Skip to content

Commit

Permalink
small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Feb 16, 2024
1 parent e94be5a commit 0bfd180
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 147 deletions.
5 changes: 3 additions & 2 deletions l1-contracts/contracts/bridge/L1SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Initializable, Owna
address _prevMsgSender,
address _l1Token,
uint256 _amount
) external virtual payable onlyBridgehubOrEra(_chainId) {
) external payable virtual onlyBridgehubOrEra(_chainId) {
if (_l1Token == ETH_TOKEN_ADDRESS) {
require(msg.value == _amount, "L1SharedBridge: msg.value not equal to amount");
} else {
Expand Down Expand Up @@ -400,7 +400,8 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Initializable, Owna
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external override onlyLegacyBridge returns (address, address, uint256) { // l1Receiver, l1Token, amount
) external override onlyLegacyBridge returns (address, address, uint256) {
// l1Receiver, l1Token, amount
return
_finalizeWithdrawal(
ERA_CHAIN_ID,
Expand Down
10 changes: 7 additions & 3 deletions l1-contracts/contracts/dev-contracts/test/L1SharedBridgeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import "../../bridge/interfaces/IL1SharedBridge.sol";

/// @author Matter Labs
contract L1SharedBridgeTest is L1SharedBridge {

address private immutable eraDiamondProxy;

constructor(address _diamondProxyAddress, address payable _l1WethAddress, IBridgehub _bridgehub, IL1ERC20Bridge _legacyBridge) L1SharedBridge(_l1WethAddress, _bridgehub, _legacyBridge){
constructor(
address _diamondProxyAddress,
address payable _l1WethAddress,
IBridgehub _bridgehub,
IL1ERC20Bridge _legacyBridge
) L1SharedBridge(_l1WethAddress, _bridgehub, _legacyBridge) {
eraDiamondProxy = _diamondProxyAddress;
}

Expand All @@ -31,7 +35,7 @@ contract L1SharedBridgeTest is L1SharedBridge {
address _prevMsgSender,
address _l1Token,
uint256 _amount
) external payable onlyBridgehubOrTestEra(_chainId) override {
) external payable override onlyBridgehubOrTestEra(_chainId) {
if (_l1Token == ETH_TOKEN_ADDRESS) {
require(msg.value == _amount, "L1SharedBridge: msg.value not equal to amount");
} else {
Expand Down
2 changes: 0 additions & 2 deletions l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
"deploy-testkit": "ts-node scripts/deploy-testkit.ts",
"verify": "hardhat run --network env scripts/verify.ts",
"read-variable": "ts-node scripts/read-variable.ts",
"initialize-erc20-bridge": "ts-node scripts/initialize-erc20-bridge.ts",
"initialize-weth-bridge": "ts-node scripts/initialize-weth-bridge.ts",
"initialize-governance-chain": "ts-node scripts/initialize-governance-chain.ts",
"initialize-bridges": "ts-node scripts/initialize-bridges.ts",
"initialize-validator": "ts-node scripts/initialize-validator.ts",
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/initialize-governance-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ async function main() {
const governance = deployer.governanceContract(deployWallet);
const zkSync = deployer.stateTransitionContract(deployWallet);

await (await zkSync.setPendingGovernor(governance.address)).wait();
await (await zkSync.setPendingAdmin(governance.address)).wait();

const call = {
target: zkSync.address,
value: 0,
data: zkSync.interface.encodeFunctionData("acceptGovernor"),
data: zkSync.interface.encodeFunctionData("acceptAdmin"),
};

const operation = {
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/scripts/migrate-governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function main() {
target: l1Erc20Bridge.address,
});

const zkSyncSetPendingGovernor = zkSync.interface.encodeFunctionData("setPendingGovernor", [
const zkSyncSetPendingGovernor = zkSync.interface.encodeFunctionData("setPendingAdmin", [
governanceAddressFromEnv,
]);
displayTx("zkSync Diamond Proxy migration calldata:", {
Expand Down
32 changes: 16 additions & 16 deletions l1-contracts/test/test_config/constant/hardhat.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,96 @@
"name": "DAI",
"symbol": "DAI",
"decimals": 18,
"address": "0x9F5d1DA449A6c22CCCCE139acD98adD82797fEec"
"address": "0xe8c976ce9F855825e52015bd1E88Fc84Da1946d2"
},
{
"name": "wBTC",
"symbol": "wBTC",
"decimals": 8,
"address": "0x275E5aa56a705c8726eE35B3DC6530DE0a0e5f6c"
"address": "0xd012f213dDD34858A1357e30B4c491dbFCba8Ee3"
},
{
"name": "BAT",
"symbol": "BAT",
"decimals": 18,
"address": "0x18d8b7878Ee8D1cf3c32b177e0B0EC2379084B11"
"address": "0x8fbdf8cEAf04E3cc9ac53C90b344c0c2489a0645"
},
{
"name": "GNT",
"symbol": "GNT",
"decimals": 18,
"address": "0xe4B41b2c8e3831cbEdC8b3D82047fA30B6B22946"
"address": "0x91D6cBBb7006A3fC6686d65375A067624b8D405A"
},
{
"name": "MLTT",
"symbol": "MLTT",
"decimals": 18,
"address": "0xe8c976ce9F855825e52015bd1E88Fc84Da1946d2"
"address": "0xEbD3994f1a9d85458bD2a40Fc6927C4048291067"
},
{
"name": "DAIK",
"symbol": "DAIK",
"decimals": 18,
"address": "0xd012f213dDD34858A1357e30B4c491dbFCba8Ee3"
"address": "0x194475D0de71858B134e2084fa627B5A7d04334c"
},
{
"name": "wBTCK",
"symbol": "wBTCK",
"decimals": 8,
"address": "0x8fbdf8cEAf04E3cc9ac53C90b344c0c2489a0645"
"address": "0xfB6306147E50e7042E74eA6Cc3db38a8489F8D78"
},
{
"name": "BATK",
"symbol": "BATS",
"decimals": 18,
"address": "0x91D6cBBb7006A3fC6686d65375A067624b8D405A"
"address": "0xA50C21DE8a2d575F915E5f8D6D5ec8eF2935D58e"
},
{
"name": "GNTK",
"symbol": "GNTS",
"decimals": 18,
"address": "0xEbD3994f1a9d85458bD2a40Fc6927C4048291067"
"address": "0xCBaDEF24FA67dB5a56fD84c72b22797A125C3132"
},
{
"name": "MLTTK",
"symbol": "MLTTS",
"decimals": 18,
"address": "0x194475D0de71858B134e2084fa627B5A7d04334c"
"address": "0x80C92D6E8d4015660506Cf4F4503eBF3bc073190"
},
{
"name": "DAIL",
"symbol": "DAIL",
"decimals": 18,
"address": "0xfB6306147E50e7042E74eA6Cc3db38a8489F8D78"
"address": "0x44bD975d5735ab2E1b61787228f538e13bF263DC"
},
{
"name": "wBTCL",
"symbol": "wBTCP",
"decimals": 8,
"address": "0xA50C21DE8a2d575F915E5f8D6D5ec8eF2935D58e"
"address": "0xDbEBD56A3068c71f6F71973171c6880a238Ff742"
},
{
"name": "BATL",
"symbol": "BATW",
"decimals": 18,
"address": "0xCBaDEF24FA67dB5a56fD84c72b22797A125C3132"
"address": "0x3Ca0576c73B1A6e1788eD9De747eD63ecEce5eB0"
},
{
"name": "GNTL",
"symbol": "GNTW",
"decimals": 18,
"address": "0x80C92D6E8d4015660506Cf4F4503eBF3bc073190"
"address": "0x16d1b025Ab084f9fA9ba6569f6EB98329dc10dc4"
},
{
"name": "MLTTL",
"symbol": "MLTTW",
"decimals": 18,
"address": "0x44bD975d5735ab2E1b61787228f538e13bF263DC"
"address": "0x03e98ce05501e6d1699A9Bf7Abb694dde742Ee80"
},
{
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": 18,
"address": "0xDbEBD56A3068c71f6F71973171c6880a238Ff742"
"address": "0x139D7fa4EDEDD4015E582E52669F4177A89450Ff"
}
]
38 changes: 3 additions & 35 deletions l1-contracts/test/unit_tests/custom_base_token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as hardhat from "hardhat";
import { ethers, Wallet } from "ethers";
import { Interface } from "ethers/lib/utils";

import type { TestnetERC20Token, WETH9 } from "../../typechain";
import { TestnetERC20TokenFactory, WETH9Factory } from "../../typechain";
import type { TestnetERC20Token } from "../../typechain";
import { TestnetERC20TokenFactory } from "../../typechain";
import type { IBridgehub } from "../../typechain/IBridgehub";
import { IBridgehubFactory } from "../../typechain/IBridgehubFactory";
import type { IL1SharedBridge } from "../../typechain/IL1SharedBridge";
Expand All @@ -28,8 +28,6 @@ describe("Custom base token chain and bridge tests", () => {
let baseTokenAddress: string;
let altTokenAddress: string;
let altToken: TestnetERC20Token;
let wethTokenAddress: string;
let wethToken: WETH9;
let chainId = process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID ? parseInt(process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID) : 270;

before(async () => {
Expand Down Expand Up @@ -62,9 +60,6 @@ describe("Custom base token chain and bridge tests", () => {
altTokenAddress = tokens.find((token: { symbol: string }) => token.symbol == "DAI")!.address;
altToken = TestnetERC20TokenFactory.connect(altTokenAddress, owner);

wethTokenAddress = await deployer.defaultSharedBridge(deployWallet).l1WethAddress();
wethToken = WETH9Factory.connect(wethTokenAddress, owner);

// prepare the bridge
l1SharedBridge = IL1SharedBridgeFactory.connect(deployer.addresses.Bridges.SharedBridgeProxy, deployWallet);
});
Expand All @@ -87,7 +82,7 @@ describe("Custom base token chain and bridge tests", () => {
expect(txHash).not.equal(ethers.constants.HashZero);
});

it("Should not allow direct deposits", async () => {
it("Should not allow direct legacy deposits", async () => {
const revertReason = await getCallRevertReason(
l1SharedBridge
.connect(randomSigner)
Expand All @@ -98,7 +93,6 @@ describe("Custom base token chain and bridge tests", () => {
0,
0,
0,
0,
ethers.constants.AddressZero
)
);
Expand Down Expand Up @@ -149,32 +143,6 @@ describe("Custom base token chain and bridge tests", () => {
});
});

it("Should deposit weth token successfully twoBridges method", async () => {
const wethTokenAmount = ethers.utils.parseUnits("800", 18);
const baseTokenAmount = ethers.utils.parseUnits("800", 18);

await (await wethToken.connect(randomSigner).deposit({ value: wethTokenAmount })).wait();
await (await wethToken.connect(randomSigner).approve(l1SharedBridge.address, wethTokenAmount)).wait();

await (await baseToken.connect(randomSigner).mint(await randomSigner.getAddress(), baseTokenAmount)).wait();
await (await baseToken.connect(randomSigner).approve(l1SharedBridge.address, baseTokenAmount)).wait();

await bridgehub.connect(randomSigner).requestL2TransactionTwoBridges({
chainId,
mintValue: baseTokenAmount,
l2Value: 1,
l2GasLimit: 10000000,
l2GasPerPubdataByteLimit: REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
refundRecipient: await randomSigner.getAddress(),
secondBridgeAddress: l1SharedBridge.address,
secondBridgeValue: 0,
secondBridgeCalldata: ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "address"],
[wethTokenAddress, wethTokenAmount, await randomSigner.getAddress()]
),
});
});

it("Should revert on finalizing a withdrawal with wrong message length", async () => {
const revertReason = await getCallRevertReason(
l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, "0x", [])
Expand Down
40 changes: 20 additions & 20 deletions l1-contracts/test/unit_tests/governance_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("Admin facet tests", function () {

const governanceContract = await contractFactory.deploy();
const governance = GovernanceFactory.connect(governanceContract.address, governanceContract.signer);
await adminFacetTest.setPendingGovernor(governance.address);
await adminFacetTest.setPendingAdmin(governance.address);

randomSigner = (await hardhat.ethers.getSigners())[1];
});
Expand Down Expand Up @@ -67,39 +67,39 @@ describe("Admin facet tests", function () {
expect(revertReason).equal("StateTransition Chain: not state transition manager");
});

describe("change governor", function () {
let newGovernor: ethers.Signer;
describe("change admin", function () {
let newAdmin: ethers.Signer;

before(async () => {
newGovernor = (await hardhat.ethers.getSigners())[2];
newAdmin = (await hardhat.ethers.getSigners())[2];
});

it("set pending governor", async () => {
const proposedGovernor = await randomSigner.getAddress();
await adminFacetTest.setPendingGovernor(proposedGovernor);
it("set pending admin", async () => {
const proposedAdmin = await randomSigner.getAddress();
await adminFacetTest.setPendingAdmin(proposedAdmin);

const pendingGovernor = await adminFacetTest.getPendingAdmin();
expect(pendingGovernor).equal(proposedGovernor);
const pendingAdmin = await adminFacetTest.getPendingAdmin();
expect(pendingAdmin).equal(proposedAdmin);
});

it("reset pending governor", async () => {
const proposedGovernor = await newGovernor.getAddress();
await adminFacetTest.setPendingGovernor(proposedGovernor);
it("reset pending admin", async () => {
const proposedAdmin = await newAdmin.getAddress();
await adminFacetTest.setPendingAdmin(proposedAdmin);

const pendingGovernor = await adminFacetTest.getPendingAdmin();
expect(pendingGovernor).equal(proposedGovernor);
const pendingAdmin = await adminFacetTest.getPendingAdmin();
expect(pendingAdmin).equal(proposedAdmin);
});

it("failed to accept governor from not proposed account", async () => {
const revertReason = await getCallRevertReason(adminFacetTest.connect(randomSigner).acceptGovernor());
it("failed to accept admin from not proposed account", async () => {
const revertReason = await getCallRevertReason(adminFacetTest.connect(randomSigner).acceptAdmin());
expect(revertReason).equal("n4");
});

it("accept governor from proposed account", async () => {
await adminFacetTest.connect(newGovernor).acceptGovernor();
it("accept admin from proposed account", async () => {
await adminFacetTest.connect(newAdmin).acceptAdmin();

const governor = await adminFacetTest.getAdmin();
expect(governor).equal(await newGovernor.getAddress());
const admin = await adminFacetTest.getAdmin();
expect(admin).equal(await newAdmin.getAddress());
});
});
});
Loading

0 comments on commit 0bfd180

Please sign in to comment.