From 803695f465f3771b6a3722d52c2482d46b912853 Mon Sep 17 00:00:00 2001 From: Zach Kolodny Date: Mon, 3 Jun 2024 20:09:09 -0400 Subject: [PATCH] hardhat tests pass --- .../contracts/common/L1ContractErrors.sol | 2 +- .../state-transition/libraries/Diamond.sol | 3 +- l1-contracts/hardhat.config.ts | 4 +++ .../test/test_config/constant/hardhat.json | 32 +++++++++---------- .../test/unit_tests/custom_base_token.spec.ts | 6 ++-- .../test/unit_tests/governance_test.spec.ts | 8 ++--- .../unit_tests/l1_shared_bridge_test.spec.ts | 18 +++++------ .../test/unit_tests/l2-upgrade.test.spec.ts | 30 ++++++++--------- .../test/unit_tests/legacy_era_test.spec.ts | 18 +++++------ .../test/unit_tests/mailbox_test.spec.ts | 10 +++--- .../test/unit_tests/proxy_test.spec.ts | 6 ++-- l1-contracts/test/unit_tests/utils.ts | 16 +++++++++- .../validator_timelock_test.spec.ts | 12 +++---- 13 files changed, 92 insertions(+), 73 deletions(-) diff --git a/l1-contracts/contracts/common/L1ContractErrors.sol b/l1-contracts/contracts/common/L1ContractErrors.sol index f4a4baad9..900570d83 100644 --- a/l1-contracts/contracts/common/L1ContractErrors.sol +++ b/l1-contracts/contracts/common/L1ContractErrors.sol @@ -120,7 +120,7 @@ error MissingSystemLogs(uint256 expected, uint256 actual); // 0xe85392f9 error CanOnlyProcessOneBatch(); // 0x55ad3fd3 -error BatchHashMismatch(bytes32 exected, bytes32 actual); +error BatchHashMismatch(bytes32 expected, bytes32 actual); // 0xf093c2e5 error UpgradeBatchNumberIsNotZero(); // 0x0105f9c0 diff --git a/l1-contracts/contracts/state-transition/libraries/Diamond.sol b/l1-contracts/contracts/state-transition/libraries/Diamond.sol index 98cde91f3..0d94de457 100644 --- a/l1-contracts/contracts/state-transition/libraries/Diamond.sol +++ b/l1-contracts/contracts/state-transition/libraries/Diamond.sol @@ -307,7 +307,8 @@ library Diamond { (bool success, bytes memory data) = _init.delegatecall(_calldata); if (!success) { // If the returndata is too small, we still want to produce some meaningful error - if (data.length <= 4) { + + if (data.length < 4) { revert MalformedCalldata(); } diff --git a/l1-contracts/hardhat.config.ts b/l1-contracts/hardhat.config.ts index 884dc43d3..a3988d7b7 100644 --- a/l1-contracts/hardhat.config.ts +++ b/l1-contracts/hardhat.config.ts @@ -47,6 +47,10 @@ export default { enabled: process.env.TEST_CONTRACTS_FORK === "1", }, }, + local: { + url: "http://127.0.0.1:8545/", + accounts: ["0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"] + } }, etherscan: { apiKey: process.env.MISC_ETHERSCAN_API_KEY, diff --git a/l1-contracts/test/test_config/constant/hardhat.json b/l1-contracts/test/test_config/constant/hardhat.json index a2364bde4..51a16802a 100644 --- a/l1-contracts/test/test_config/constant/hardhat.json +++ b/l1-contracts/test/test_config/constant/hardhat.json @@ -3,96 +3,96 @@ "name": "DAI", "symbol": "DAI", "decimals": 18, - "address": "0x4fE0EE70D78132fBb5C68C1d5e0020f3c05542f2" + "address": "0x3202935CA01eADd2F0B4e7aA23EFA52315121172" }, { "name": "wBTC", "symbol": "wBTC", "decimals": 8, - "address": "0x3202935CA01eADd2F0B4e7aA23EFA52315121172" + "address": "0xe73a1c05498e492f182f9B3E3cd65b2F9f52eE94" }, { "name": "BAT", "symbol": "BAT", "decimals": 18, - "address": "0xe73a1c05498e492f182f9B3E3cd65b2F9f52eE94" + "address": "0x7aAE2ee8317b384aDE246664933A147411b60045" }, { "name": "GNT", "symbol": "GNT", "decimals": 18, - "address": "0x7aAE2ee8317b384aDE246664933A147411b60045" + "address": "0x02a344d1e31e92e39c2681937645F1d668C37d4e" }, { "name": "MLTT", "symbol": "MLTT", "decimals": 18, - "address": "0x02a344d1e31e92e39c2681937645F1d668C37d4e" + "address": "0x28033f8EdB2F43747E55401C4a3E3b4b2cF5146C" }, { "name": "DAIK", "symbol": "DAIK", "decimals": 18, - "address": "0x28033f8EdB2F43747E55401C4a3E3b4b2cF5146C" + "address": "0x147dCc3a8E99794C2Ec79EaF1a142324D6778255" }, { "name": "wBTCK", "symbol": "wBTCK", "decimals": 8, - "address": "0x147dCc3a8E99794C2Ec79EaF1a142324D6778255" + "address": "0x74cA8715E29196Bfbcd7444B09203d22dDaF7d1a" }, { "name": "BATK", "symbol": "BATS", "decimals": 18, - "address": "0x74cA8715E29196Bfbcd7444B09203d22dDaF7d1a" + "address": "0x2eAf3eac597d23db3A8427329482aE47935141d9" }, { "name": "GNTK", "symbol": "GNTS", "decimals": 18, - "address": "0x2eAf3eac597d23db3A8427329482aE47935141d9" + "address": "0x2B1b32d23f2be391280bFbD2B51daB8Ad2a69B9e" }, { "name": "MLTTK", "symbol": "MLTTS", "decimals": 18, - "address": "0x2B1b32d23f2be391280bFbD2B51daB8Ad2a69B9e" + "address": "0xc2Ca10940Ad80Cd98512B767457bd44713232B5a" }, { "name": "DAIL", "symbol": "DAIL", "decimals": 18, - "address": "0xc2Ca10940Ad80Cd98512B767457bd44713232B5a" + "address": "0xd6b4CDa9F0Ef6d9F6b35Ab5424df0dD95E6a6D1b" }, { "name": "wBTCL", "symbol": "wBTCP", "decimals": 8, - "address": "0xd6b4CDa9F0Ef6d9F6b35Ab5424df0dD95E6a6D1b" + "address": "0x15CD4a1C10AE2D3727Dad680a1966947931588C9" }, { "name": "BATL", "symbol": "BATW", "decimals": 18, - "address": "0x15CD4a1C10AE2D3727Dad680a1966947931588C9" + "address": "0x45f430CFD5Bf38eCE39f1B9A2930B3fD494619e8" }, { "name": "GNTL", "symbol": "GNTW", "decimals": 18, - "address": "0x45f430CFD5Bf38eCE39f1B9A2930B3fD494619e8" + "address": "0x801Ab08819573537C0B256d139473eF13482B3Dd" }, { "name": "MLTTL", "symbol": "MLTTW", "decimals": 18, - "address": "0x801Ab08819573537C0B256d139473eF13482B3Dd" + "address": "0xf55F3af54B9a507Bd0260e5844C1648921214745" }, { "name": "Wrapped Ether", "symbol": "WETH", "decimals": 18, - "address": "0xf55F3af54B9a507Bd0260e5844C1648921214745" + "address": "0xed01DF970925Cc0BB427f9E8014449C8a529D303" } ] \ No newline at end of file diff --git a/l1-contracts/test/unit_tests/custom_base_token.spec.ts b/l1-contracts/test/unit_tests/custom_base_token.spec.ts index b0e9733a3..464298482 100644 --- a/l1-contracts/test/unit_tests/custom_base_token.spec.ts +++ b/l1-contracts/test/unit_tests/custom_base_token.spec.ts @@ -97,7 +97,7 @@ describe("Custom base token chain and bridge tests", () => { ) ); - expect(revertReason).equal("ShB not legacy bridge"); + expect(revertReason).contains("Unauthorized"); }); it("Should deposit base token successfully direct via bridgehub", async () => { @@ -147,13 +147,13 @@ describe("Custom base token chain and bridge tests", () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, "0x", []) ); - expect(revertReason).equal("ShB wrong msg len"); + expect(revertReason).contains("MalformedMessage"); }); it("Should revert on finalizing a withdrawal with wrong function selector", async () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, ethers.utils.randomBytes(96), []) ); - expect(revertReason).equal("ShB Incorrect message function selector"); + expect(revertReason).contains("InvalidSelector"); }); }); diff --git a/l1-contracts/test/unit_tests/governance_test.spec.ts b/l1-contracts/test/unit_tests/governance_test.spec.ts index 4ab11f266..444e70846 100644 --- a/l1-contracts/test/unit_tests/governance_test.spec.ts +++ b/l1-contracts/test/unit_tests/governance_test.spec.ts @@ -36,7 +36,7 @@ describe("Admin facet tests", function () { const revertReason = await getCallRevertReason( adminFacetTest.connect(randomSigner).setValidator(validatorAddress, true) ); - expect(revertReason).equal("Hyperchain: not state transition manager"); + expect(revertReason).contains("Unauthorized"); }); it("StateTransitionManager successfully set porter availability", async () => { @@ -48,7 +48,7 @@ describe("Admin facet tests", function () { it("random account fails to set porter availability", async () => { const revertReason = await getCallRevertReason(adminFacetTest.connect(randomSigner).setPorterAvailability(false)); - expect(revertReason).equal("Hyperchain: not state transition manager"); + expect(revertReason).contains("Unauthorized"); }); it("StateTransitionManager successfully set priority transaction max gas limit", async () => { @@ -64,7 +64,7 @@ describe("Admin facet tests", function () { const revertReason = await getCallRevertReason( adminFacetTest.connect(randomSigner).setPriorityTxMaxGasLimit(gasLimit) ); - expect(revertReason).equal("Hyperchain: not state transition manager"); + expect(revertReason).contains("Unauthorized"); }); describe("change admin", function () { @@ -92,7 +92,7 @@ describe("Admin facet tests", function () { it("failed to accept admin from not proposed account", async () => { const revertReason = await getCallRevertReason(adminFacetTest.connect(randomSigner).acceptAdmin()); - expect(revertReason).equal("n4"); + expect(revertReason).contains("Unauthorized"); }); it("accept admin from proposed account", async () => { diff --git a/l1-contracts/test/unit_tests/l1_shared_bridge_test.spec.ts b/l1-contracts/test/unit_tests/l1_shared_bridge_test.spec.ts index b53b12175..31475e241 100644 --- a/l1-contracts/test/unit_tests/l1_shared_bridge_test.spec.ts +++ b/l1-contracts/test/unit_tests/l1_shared_bridge_test.spec.ts @@ -98,7 +98,7 @@ describe("Shared Bridge tests", () => { { value: mintValue } ) ); - expect(revertReason).equal("6T"); + expect(revertReason).contains("EmptyDeposit"); }); it("Should deposit successfully", async () => { @@ -129,7 +129,7 @@ describe("Shared Bridge tests", () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, "0x", [ethers.constants.HashZero]) ); - expect(revertReason).equal("ShB wrong msg len"); + expect(revertReason).contains("MalformedMessage"); }); it("Should revert on finalizing a withdrawal with wrong message length", async () => { @@ -145,14 +145,14 @@ describe("Shared Bridge tests", () => { [ethers.constants.HashZero] ) ); - expect(revertReason).equal("ShB wrong msg len 2"); + expect(revertReason).contains("MalformedMessage"); }); it("Should revert on finalizing a withdrawal with wrong function selector", async () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, ethers.utils.randomBytes(96), []) ); - expect(revertReason).equal("ShB Incorrect message function selector"); + expect(revertReason).contains("InvalidSelector"); }); it("Should deposit erc20 token successfully", async () => { @@ -183,7 +183,7 @@ describe("Shared Bridge tests", () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, "0x", [ethers.constants.HashZero]) ); - expect(revertReason).equal("ShB wrong msg len"); + expect(revertReason).contains("MalformedMessage"); }); it("Should revert on finalizing a withdrawal with wrong function signature", async () => { @@ -192,7 +192,7 @@ describe("Shared Bridge tests", () => { .connect(randomSigner) .finalizeWithdrawal(chainId, 0, 0, 0, ethers.utils.randomBytes(76), [ethers.constants.HashZero]) ); - expect(revertReason).equal("ShB Incorrect message function selector"); + expect(revertReason).contains("InvalidSelector"); }); it("Should revert on finalizing a withdrawal with wrong batch number", async () => { @@ -206,7 +206,7 @@ describe("Shared Bridge tests", () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 10, 0, 0, l2ToL1message, []) ); - expect(revertReason).equal("xx"); + expect(revertReason).contains("BatchNotExecuted"); }); it("Should revert on finalizing a withdrawal with wrong length of proof", async () => { @@ -220,7 +220,7 @@ describe("Shared Bridge tests", () => { const revertReason = await getCallRevertReason( l1SharedBridge.connect(randomSigner).finalizeWithdrawal(chainId, 0, 0, 0, l2ToL1message, []) ); - expect(revertReason).equal("xc"); + expect(revertReason).contains("MerklePathEmpty"); }); it("Should revert on finalizing a withdrawal with wrong proof", async () => { @@ -236,6 +236,6 @@ describe("Shared Bridge tests", () => { .connect(randomSigner) .finalizeWithdrawal(chainId, 0, 0, 0, l2ToL1message, Array(9).fill(ethers.constants.HashZero)) ); - expect(revertReason).equal("ShB withd w proof"); + expect(revertReason).contains("InvalidProof"); }); }); diff --git a/l1-contracts/test/unit_tests/l2-upgrade.test.spec.ts b/l1-contracts/test/unit_tests/l2-upgrade.test.spec.ts index cda99ac34..3a5dd60ee 100644 --- a/l1-contracts/test/unit_tests/l2-upgrade.test.spec.ts +++ b/l1-contracts/test/unit_tests/l2-upgrade.test.spec.ts @@ -176,7 +176,7 @@ describe("L2 upgrade test", function () { l2ProtocolUpgradeTx: noopUpgradeTransaction, }) ); - expect(revertReason).to.equal("Upgrade is not ready yet"); + expect(revertReason).contains("TimeNotReached"); }); it("Should require correct tx type for upgrade tx", async () => { @@ -190,7 +190,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("L2 system upgrade tx type is wrong"); + expect(revertReason).contains("InvalidTxType"); }); it("Should include the new protocol version as part of nonce", async () => { @@ -206,7 +206,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("The new protocol version should be included in the L2 system upgrade tx"); + expect(revertReason).contains("NewProtocolVersionNotInUpgradeTxn"); }); it("Should ensure monotonic protocol version", async () => { @@ -222,7 +222,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("New protocol version is not greater than the current one"); + expect(revertReason).contains("InvalidProtocolVersion"); }); it("Should ensure protocol version not increasing too much", async () => { @@ -238,7 +238,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("Too big protocol version difference"); + expect(revertReason).contains("InvalidProtocolVersion"); }); it("Should validate upgrade transaction overhead", async () => { @@ -254,7 +254,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("my"); + expect(revertReason).contains("NotEnoughGas"); }); it("Should validate upgrade transaction gas max", async () => { @@ -270,7 +270,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("ui"); + expect(revertReason).contains("TooMuchGas"); }); it("Should validate upgrade transaction cannot output more pubdata than processable", async () => { @@ -287,7 +287,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("uk"); + expect(revertReason).contains("InvalidPubdataLength"); }); it("Should validate factory deps", async () => { @@ -306,7 +306,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("Wrong factory dep hash"); + expect(revertReason).contains("InvalidHash"); }); it("Should validate factory deps length match", async () => { @@ -324,7 +324,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("Wrong number of factory deps"); + expect(revertReason).contains("UnexpectedNumberOfFactoryDeps"); }); it("Should validate factory deps length isn't too large", async () => { @@ -344,7 +344,7 @@ describe("L2 upgrade test", function () { }) ); - expect(revertReason).to.equal("Factory deps can be at most 32"); + expect(revertReason).contains("TooManyFactoryDeps"); }); let l2UpgradeTxHash: string; @@ -465,7 +465,7 @@ describe("L2 upgrade test", function () { executeUpgrade(chainId, proxyGetters, stateTransitionManager, proxyAdmin, upgrade) ); await rollBackToVersion((4 + 1 + initialProtocolVersion).toString(), stateTransitionManager, upgrade); - expect(revertReason).to.equal("Previous upgrade has not been finalized"); + expect(revertReason).to.contains("PreviousUpgradeNotFinalized"); }); it("Should require that the next commit batches contains an upgrade tx", async () => { @@ -479,7 +479,7 @@ describe("L2 upgrade test", function () { const revertReason = await getCallRevertReason( proxyExecutor.commitBatches(storedBatch2Info, [batch3InfoNoUpgradeTx]) ); - expect(revertReason).to.equal("b8"); + expect(revertReason).to.contains("MissingSystemLogs"); }); it("Should ensure any additional upgrade logs go to the priority ops hash", async () => { @@ -521,7 +521,7 @@ describe("L2 upgrade test", function () { const revertReason = await getCallRevertReason( proxyExecutor.commitBatches(storedBatch2Info, [batch3InfoNoUpgradeTx]) ); - expect(revertReason).to.equal("kp"); + expect(revertReason).to.contains("LogAlreadyProcessed"); }); it("Should fail to commit when upgrade tx hash does not match", async () => { @@ -554,7 +554,7 @@ describe("L2 upgrade test", function () { const revertReason = await getCallRevertReason( proxyExecutor.commitBatches(storedBatch2Info, [batch3InfoTwoUpgradeTx]) ); - expect(revertReason).to.equal("ut"); + expect(revertReason).to.contains("TxHashMismatch"); }); it("Should commit successfully when the upgrade tx is present", async () => { diff --git a/l1-contracts/test/unit_tests/legacy_era_test.spec.ts b/l1-contracts/test/unit_tests/legacy_era_test.spec.ts index 92a86dc7d..deb50bbe4 100644 --- a/l1-contracts/test/unit_tests/legacy_era_test.spec.ts +++ b/l1-contracts/test/unit_tests/legacy_era_test.spec.ts @@ -142,7 +142,7 @@ describe("Legacy Era tests", function () { "deposit(address,address,uint256,uint256,uint256,address)" ](await randomSigner.getAddress(), erc20TestToken.address, 0, 0, 0, ethers.constants.AddressZero) ); - expect(revertReason).equal("0T"); + expect(revertReason).contains("EmptyDeposit"); }); it("Should deposit successfully", async () => { @@ -162,7 +162,7 @@ describe("Legacy Era tests", function () { const revertReason = await getCallRevertReason( l1ERC20Bridge.connect(randomSigner).finalizeWithdrawal(0, 0, 0, "0x", [ethers.constants.HashZero]) ); - expect(revertReason).equal("ShB wrong msg len"); + expect(revertReason).contains("MalformedMessage"); }); it("Should revert on finalizing a withdrawal with wrong function signature", async () => { @@ -171,7 +171,7 @@ describe("Legacy Era tests", function () { .connect(randomSigner) .finalizeWithdrawal(0, 0, 0, ethers.utils.randomBytes(76), [ethers.constants.HashZero]) ); - expect(revertReason).equal("ShB Incorrect message function selector"); + expect(revertReason).contains("InvalidSelector"); }); it("Should revert on finalizing a withdrawal with wrong batch number", async () => { @@ -185,7 +185,7 @@ describe("Legacy Era tests", function () { const revertReason = await getCallRevertReason( l1ERC20Bridge.connect(randomSigner).finalizeWithdrawal(10, 0, 0, l2ToL1message, []) ); - expect(revertReason).equal("xx"); + expect(revertReason).contains("BatchNotExecuted"); }); it("Should revert on finalizing a withdrawal with wrong length of proof", async () => { @@ -199,7 +199,7 @@ describe("Legacy Era tests", function () { const revertReason = await getCallRevertReason( l1ERC20Bridge.connect(randomSigner).finalizeWithdrawal(0, 0, 0, l2ToL1message, []) ); - expect(revertReason).equal("xc"); + expect(revertReason).contains("MerklePathEmpty"); }); it("Should revert on finalizing a withdrawal with wrong proof", async () => { @@ -215,7 +215,7 @@ describe("Legacy Era tests", function () { .connect(randomSigner) .finalizeWithdrawal(0, 0, 0, l2ToL1message, Array(9).fill(ethers.constants.HashZero)) ); - expect(revertReason).equal("ShB withd w proof"); + expect(revertReason).contains("InvalidProof"); }); /////////// Mailbox. Note we have these two together because we need to fix ERA Diamond proxy Address @@ -237,7 +237,7 @@ describe("Legacy Era tests", function () { ) ); - expect(revertReason).equal("pp"); + expect(revertReason).contains("MalformedBytecode"); }); describe("finalizeEthWithdrawal", function () { @@ -284,7 +284,7 @@ describe("Legacy Era tests", function () { const revertReason = await getCallRevertReason( mailbox.finalizeEthWithdrawal(BLOCK_NUMBER, MESSAGE_INDEX, TX_NUMBER_IN_BLOCK, MESSAGE, invalidProof) ); - expect(revertReason).equal("ShB withd w proof"); + expect(revertReason).contains("InvalidProof"); }); it("Successful deposit", async () => { @@ -316,7 +316,7 @@ describe("Legacy Era tests", function () { const revertReason = await getCallRevertReason( mailbox.finalizeEthWithdrawal(BLOCK_NUMBER, MESSAGE_INDEX, TX_NUMBER_IN_BLOCK, MESSAGE, MERKLE_PROOF) ); - expect(revertReason).equal("Withdrawal is already finalized"); + expect(revertReason).contains("WithdrawalAlreadyFinalized"); }); }); }); diff --git a/l1-contracts/test/unit_tests/mailbox_test.spec.ts b/l1-contracts/test/unit_tests/mailbox_test.spec.ts index 7210ccc44..5bb874381 100644 --- a/l1-contracts/test/unit_tests/mailbox_test.spec.ts +++ b/l1-contracts/test/unit_tests/mailbox_test.spec.ts @@ -105,7 +105,7 @@ describe("Mailbox tests", function () { ) ); - expect(revertReason).equal("pq"); + expect(revertReason).contains("MalformedBytecode"); }); it("Should not accept bytecode of even length in words", async () => { @@ -122,7 +122,7 @@ describe("Mailbox tests", function () { ) ); - expect(revertReason).equal("ps"); + expect(revertReason).contains("MalformedBytecode"); }); describe("finalizeEthWithdrawal", function () { @@ -167,21 +167,21 @@ describe("Mailbox tests", function () { const revertReason = await getCallRevertReason( mailbox.finalizeEthWithdrawal(BLOCK_NUMBER, MESSAGE_INDEX, TX_NUMBER_IN_BLOCK, MESSAGE, invalidProof) ); - expect(revertReason).equal("Mailbox: finalizeEthWithdrawal only available for Era on mailbox"); + expect(revertReason).contains("OnlyEraSupported"); }); it("Successful withdrawal", async () => { const revertReason = await getCallRevertReason( mailbox.finalizeEthWithdrawal(BLOCK_NUMBER, MESSAGE_INDEX, TX_NUMBER_IN_BLOCK, MESSAGE, MERKLE_PROOF) ); - expect(revertReason).equal("Mailbox: finalizeEthWithdrawal only available for Era on mailbox"); + expect(revertReason).contains("OnlyEraSupported"); }); it("Reverts when withdrawal is already finalized", async () => { const revertReason = await getCallRevertReason( mailbox.finalizeEthWithdrawal(BLOCK_NUMBER, MESSAGE_INDEX, TX_NUMBER_IN_BLOCK, MESSAGE, MERKLE_PROOF) ); - expect(revertReason).equal("Mailbox: finalizeEthWithdrawal only available for Era on mailbox"); + expect(revertReason).contains("OnlyEraSupported"); }); }); diff --git a/l1-contracts/test/unit_tests/proxy_test.spec.ts b/l1-contracts/test/unit_tests/proxy_test.spec.ts index 3c3ae6429..e63abe0bb 100644 --- a/l1-contracts/test/unit_tests/proxy_test.spec.ts +++ b/l1-contracts/test/unit_tests/proxy_test.spec.ts @@ -134,14 +134,14 @@ describe("Diamond proxy tests", function () { const proxyAsERC20 = TestnetERC20TokenFactory.connect(proxy.address, proxy.signer); const revertReason = await getCallRevertReason(proxyAsERC20.transfer(proxyAsERC20.address, 0)); - expect(revertReason).equal("F"); + expect(revertReason).contains("InvalidSelector"); }); it("check that proxy reject data with no selector", async () => { const dataWithoutSelector = "0x1122"; const revertReason = await getCallRevertReason(proxy.fallback({ data: dataWithoutSelector })); - expect(revertReason).equal("Ut"); + expect(revertReason).contains("MalformedCalldata"); }); it("should freeze the diamond storage", async () => { @@ -178,7 +178,7 @@ describe("Diamond proxy tests", function () { data: executorFacetSelector3 + "0000000000000000000000000000000000000000000000000000000000000000", }) ); - expect(revertReason).equal("q1"); + expect(revertReason).contains("FacetIsFrozen"); }); it("should be able to call an unfreezable facet when diamondStorage is frozen", async () => { diff --git a/l1-contracts/test/unit_tests/utils.ts b/l1-contracts/test/unit_tests/utils.ts index fd34a0e7f..aca1343d5 100644 --- a/l1-contracts/test/unit_tests/utils.ts +++ b/l1-contracts/test/unit_tests/utils.ts @@ -97,7 +97,21 @@ export async function getCallRevertReason(promise) { } } } catch (_) { - throw e; + try { + if ( + revertReason === "cannot estimate gas; transaction may fail or may require manual gas limit" || + revertReason === DEFAULT_REVERT_REASON + ) { + if (e.error) { + revertReason = + e.error.toString().match(/reverted with custom error '([^']*)'/)[1] || "PLACEHOLDER_STRING"; + } else { + revertReason = e.toString().match(/reverted with custom error '([^']*)'/)[1] || "PLACEHOLDER_STRING"; + } + } + } catch (_) { + throw e; + } } } } diff --git a/l1-contracts/test/unit_tests/validator_timelock_test.spec.ts b/l1-contracts/test/unit_tests/validator_timelock_test.spec.ts index 119cae7cc..af3c951ff 100644 --- a/l1-contracts/test/unit_tests/validator_timelock_test.spec.ts +++ b/l1-contracts/test/unit_tests/validator_timelock_test.spec.ts @@ -90,7 +90,7 @@ describe("ValidatorTimelock tests", function () { validatorTimelock.connect(randomSigner).commitBatches(getMockStoredBatchInfo(0), [getMockCommitBatchInfo(1)]) ); - expect(revertReason).equal("ValidatorTimelock: only validator"); + expect(revertReason).contains("Unauthorized"); }); it("Should revert if non-validator proves batches", async () => { @@ -100,13 +100,13 @@ describe("ValidatorTimelock tests", function () { .proveBatches(getMockStoredBatchInfo(0), [getMockStoredBatchInfo(1)], MOCK_PROOF_INPUT) ); - expect(revertReason).equal("ValidatorTimelock: only validator"); + expect(revertReason).contains("Unauthorized"); }); it("Should revert if non-validator revert batches", async () => { const revertReason = await getCallRevertReason(validatorTimelock.connect(randomSigner).revertBatches(1)); - expect(revertReason).equal("ValidatorTimelock: only validator"); + expect(revertReason).contains("Unauthorized"); }); it("Should revert if non-validator executes batches", async () => { @@ -114,7 +114,7 @@ describe("ValidatorTimelock tests", function () { validatorTimelock.connect(randomSigner).executeBatches([getMockStoredBatchInfo(1)]) ); - expect(revertReason).equal("ValidatorTimelock: only validator"); + expect(revertReason).contains("Unauthorized"); }); it("Should revert if not chain governor sets validator", async () => { @@ -122,7 +122,7 @@ describe("ValidatorTimelock tests", function () { validatorTimelock.connect(randomSigner).addValidator(chainId, await randomSigner.getAddress()) ); - expect(revertReason).equal("ValidatorTimelock: only chain admin"); + expect(revertReason).contains("Unauthorized"); }); it("Should revert if non-owner sets execution delay", async () => { @@ -165,7 +165,7 @@ describe("ValidatorTimelock tests", function () { validatorTimelock.connect(validator).executeBatchesSharedBridge(chainId, [getMockStoredBatchInfo(1)]) ); - expect(revertReason).equal("5c"); + expect(revertReason).contains("TimeNotReached"); }); it("Should successfully revert batches", async () => {