Skip to content

Commit

Permalink
Disable zkSync Tests (#862)
Browse files Browse the repository at this point in the history
Matter Labs recently renamed `era-test-node` to `zksync-anvil`. This
causes the official `hardhat-zksync-node` package to stop working.

It is possible to patch the NPM package so that it works with `sed`:

```sh
find node_modules/@matterlabs/hardhat-zksync-node/ -type f -exec sed -i "s/era[_-]test[_-]node/anvil-zksync/g" '{}' ';'
```

However, the tests seem to be quite flaky (ran on my machine once, but
the `anvil` node seems to crash quite often).
  • Loading branch information
nlordell authored Dec 5, 2024
1 parent 937af5f commit 691aa4f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ typechain-types

# zksync era node log
era_test_node.log
anvil-zksync.log
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:ts": "rimraf dist && tsc -p tsconfig.prod.json",
"build:ts:dev": "rimraf dist && tsc -p tsconfig.json",
"test:zk": "HARDHAT_ENABLE_ZKSYNC=1 hardhat test",
"test": "hardhat test --network hardhat && npm run test:L1 && npm run test:L2 && npm run test:zk",
"test": "hardhat test --network hardhat && npm run test:L1 && npm run test:L2",
"test:parallel": "hardhat test --parallel",
"test:L1": "HARDHAT_CHAIN_ID=1 hardhat test --grep '@L1'",
"test:L2": "SAFE_CONTRACT_UNDER_TEST=SafeL2 hardhat test --network hardhat",
Expand All @@ -32,7 +32,7 @@
"lint": "npm run lint:sol && npm run lint:ts",
"lint:fix": "npm run lint:sol:fix && npm run lint:ts:fix",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:sol:fix": "solhint --fix 'contracts/**/*.sol'",
"lint:sol:fix": "solhint --fix 'contracts/**/*.sol' --noPrompt",
"lint:sol:prettier": "prettier 'contracts/**/*.sol' --list-different",
"lint:ts": "eslint 'src/**/*.ts' 'test/**/*.ts'",
"lint:ts:fix": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
Expand Down
2 changes: 1 addition & 1 deletion test/core/Safe.OwnerManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe("OwnerManager", () => {
});
});

describe("changeThreshold", async () => {
describe("changeThreshold", () => {
it("can only be called from Safe itself", async () => {
const { safe } = await setupTests();
await expect(safe.changeThreshold(1)).to.be.revertedWith("GS031");
Expand Down
2 changes: 1 addition & 1 deletion test/core/Safe.Signatures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ describe("Safe", () => {
});
});

describe("checkNSignatures", async () => {
describe("checkNSignatures", () => {
it("should fail if signature points into static part", async () => {
const {
safe,
Expand Down
83 changes: 42 additions & 41 deletions test/handlers/ExtensibleFallbackHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { chainId } from "../utils/encoding";
import { encodeHandler, decodeHandler, encodeCustomVerifier, encodeHandlerFunction } from "../utils/extensible";
import { killLibContract } from "../utils/contracts";

describe("ExtensibleFallbackHandler", async () => {
const [user1, user2] = await hre.ethers.getSigners();

describe("ExtensibleFallbackHandler", () => {
const setupTests = deployments.createFixture(async ({ deployments }) => {
await deployments.fixture();
const [user1, user2] = await hre.ethers.getSigners();
const signLib = await (await hre.ethers.getContractFactory("SignMessageLib")).deploy();
const handler = await getExtensibleFallbackHandler();
const handlerAddress = await handler.getAddress();
Expand Down Expand Up @@ -49,13 +48,13 @@ describe("ExtensibleFallbackHandler", async () => {
const counterSource = `
contract Counter {
uint256 public count = 0;
function handle(address, address, uint256, bytes calldata) external returns (bytes memory result) {
bytes4 selector;
assembly {
selector := calldataload(164)
}
require(selector == 0xdeadbeef, "Invalid data");
count = count + 1;
}
Expand Down Expand Up @@ -112,6 +111,8 @@ describe("ExtensibleFallbackHandler", async () => {
);

return {
user1,
user2,
safe,
validator,
otherSafe,
Expand All @@ -128,8 +129,8 @@ describe("ExtensibleFallbackHandler", async () => {
};
});

describe("Token Callbacks", async () => {
describe("ERC1155", async () => {
describe("Token Callbacks", () => {
describe("ERC1155", () => {
it("to handle onERC1155Received", async () => {
const { handler } = await setupTests();
expect(await handler.onERC1155Received.staticCall(AddressZero, AddressZero, 0, 0, "0x")).to.be.eq("0xf23a6e61");
Expand All @@ -146,7 +147,7 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("ERC721", async () => {
describe("ERC721", () => {
it("to handle onERC721Received", async () => {
const { handler } = await setupTests();
expect(await handler.onERC721Received.staticCall(AddressZero, AddressZero, 0, "0x")).to.be.eq("0x150b7a02");
Expand All @@ -159,10 +160,10 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("Fallback Handler", async () => {
describe("fallback()", async () => {
describe("Fallback Handler", () => {
describe("fallback()", () => {
it("should revert if call to safe is less than 4 bytes (method selector)", async () => {
const { validator } = await setupTests();
const { user1, validator } = await setupTests();

const tx = {
to: await validator.getAddress(),
Expand All @@ -175,8 +176,8 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("Custom methods", async () => {
describe("setSafeMethod(bytes4,bytes32)", async () => {
describe("Custom methods", () => {
describe("setSafeMethod(bytes4,bytes32)", () => {
it("should revert if called by non-safe", async () => {
const { handler, mirror } = await setupTests();
await expect(handler.setSafeMethod("0xdeadbeef", encodeHandler(true, await mirror.getAddress()))).to.be.revertedWith(
Expand All @@ -185,7 +186,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should emit event when setting a new method", async () => {
const { safe, handler, validator, mirror } = await setupTests();
const { user1, user2, safe, handler, validator, mirror } = await setupTests();
const safeAddress = await safe.getAddress();
const newHandler = encodeHandler(true, await mirror.getAddress());
await expect(executeContractCallWithSigners(safe, validator, "setSafeMethod", ["0xdededede", newHandler], [user1, user2]))
Expand All @@ -197,7 +198,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should emit event when updating a method", async () => {
const { otherSafe, handler, preconfiguredValidator, mirror } = await setupTests();
const { user1, user2, otherSafe, handler, preconfiguredValidator, mirror } = await setupTests();
const otherSafeAddress = await otherSafe.getAddress();
const oldHandler = encodeHandler(true, await mirror.getAddress());
const newHandler = encodeHandler(true, "0xdeAdDeADDEaDdeaDdEAddEADDEAdDeadDEADDEaD");
Expand All @@ -218,7 +219,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should emit event when removing a method", async () => {
const { otherSafe, handler, preconfiguredValidator } = await setupTests();
const { user1, user2, otherSafe, handler, preconfiguredValidator } = await setupTests();
const otherSafeAddress = await otherSafe.getAddress();
await expect(
executeContractCallWithSigners(
Expand All @@ -237,7 +238,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("is correctly set", async () => {
const { safe, validator, mirror } = await setupTests();
const { user1, user2, safe, validator, mirror } = await setupTests();
const safeAddress = await safe.getAddress();
const tx = {
to: safeAddress,
Expand Down Expand Up @@ -275,7 +276,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should allow calling non-static methods", async () => {
const { safe, validator, counter } = await setupTests();
const { user1, user2, safe, validator, counter } = await setupTests();

const tx = {
to: await safe.getAddress(),
Expand All @@ -302,7 +303,7 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("MarshalLib", async () => {
describe("MarshalLib", () => {
it("should correctly encode a handler and static flag", async () => {
const { testMarshalLib } = await setupTests();
const handler = "0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead";
Expand Down Expand Up @@ -358,15 +359,15 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("Signature Verifier Muxer", async () => {
describe("supportsInterface(bytes4)", async () => {
describe("Signature Verifier Muxer", () => {
describe("supportsInterface(bytes4)", () => {
it("should return true for supporting ERC1271", async () => {
const { handler } = await setupTests();
expect(await handler.supportsInterface.staticCall("0x1626ba7e")).to.be.eq(true);
});
});

describe("setDomainVerifier(bytes32,address)", async () => {
describe("setDomainVerifier(bytes32,address)", () => {
it("should revert if called by non-safe", async () => {
const { handler, mirror } = await setupTests();
const domainSeparator = ethers.keccak256("0xdeadbeef");
Expand All @@ -376,7 +377,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should emit event when setting a new domain verifier", async () => {
const { safe, handler, validator, testVerifier } = await setupTests();
const { user1, user2, safe, handler, validator, testVerifier } = await setupTests();
const safeAddress = await safe.getAddress();
const testVerifierAddress = await testVerifier.getAddress();
const domainSeparator = ethers.keccak256("0xdeadbeef");
Expand All @@ -396,7 +397,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should emit event when updating a domain verifier", async () => {
const { otherSafe, handler, preconfiguredValidator, mirror } = await setupTests();
const { user1, user2, otherSafe, handler, preconfiguredValidator, mirror } = await setupTests();
const otherSafeAddress = await otherSafe.getAddress();
const mirrorAddress = await mirror.getAddress();
const domainSeparator = ethers.keccak256("0xdeadbeef");
Expand All @@ -418,7 +419,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should emit event when removing a domain verifier", async () => {
const { otherSafe, handler, preconfiguredValidator } = await setupTests();
const { user1, user2, otherSafe, handler, preconfiguredValidator } = await setupTests();
const otherSafeAddress = await otherSafe.getAddress();
const domainSeparator = ethers.keccak256("0xdeadbeef");
await expect(
Expand All @@ -437,7 +438,7 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("isValidSignature(bytes32,bytes)", async () => {
describe("isValidSignature(bytes32,bytes)", () => {
it("should revert if called directly", async () => {
const { handler } = await setupTests();
const dataHash = ethers.keccak256("0xbaddad");
Expand All @@ -463,14 +464,14 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should return magic value if message was signed", async () => {
const { safe, validator, signLib } = await setupTests();
const { user1, user2, safe, validator, signLib } = await setupTests();
const dataHash = ethers.keccak256("0xbaddad");
await executeContractCallWithSigners(safe, signLib, "signMessage", [dataHash], [user1, user2], true);
expect(await validator.isValidSignature.staticCall(dataHash, "0x")).to.be.eq("0x1626ba7e");
});

it("should return magic value if enough owners signed with typed signatures", async () => {
const { validator } = await setupTests();
const { user1, user2, validator } = await setupTests();
const validatorAddress = await validator.getAddress();
const dataHash = ethers.keccak256("0xbaddad");
const typedDataSig = {
Expand All @@ -496,7 +497,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should send EIP-712 context to custom verifier", async () => {
const { safe, validator, revertVerifier } = await setupTests();
const { user1, user2, safe, validator, revertVerifier } = await setupTests();
const domainSeparator = ethers.keccak256("0xdeadbeef");
const typeHash = ethers.keccak256("0xbaddad");
// abi encode the message
Expand Down Expand Up @@ -600,36 +601,36 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("IERC165", async () => {
describe("supportsInterface(bytes4)", async () => {
describe("IERC165", () => {
describe("supportsInterface(bytes4)", () => {
it("should return true for ERC165", async () => {
const { validator } = await setupTests();
expect(await validator.supportsInterface.staticCall("0x01ffc9a7")).to.be.true;
});
});

describe("setSupportedInterface(bytes4,bool)", async () => {
describe("setSupportedInterface(bytes4,bool)", () => {
it("should revert if called by non-safe", async () => {
const { handler } = await setupTests();
await expect(handler.setSupportedInterface("0xdeadbeef", true)).to.be.revertedWith("only safe can call this method");
});

it("should revert if trying to set an invalid interface", async () => {
const { validator, safe } = await setupTests();
const { user1, user2, validator, safe } = await setupTests();
await expect(
executeContractCallWithSigners(safe, validator, "setSupportedInterface", ["0xffffffff", true], [user1, user2]),
).to.be.revertedWith("invalid interface id");
});

it("should emit event when adding a newly supported interface", async () => {
const { validator, safe, handler } = await setupTests();
const { user1, user2, validator, safe, handler } = await setupTests();
await expect(executeContractCallWithSigners(safe, validator, "setSupportedInterface", ["0xdeadbeef", true], [user1, user2]))
.to.emit(handler, "AddedInterface")
.withArgs(await safe.getAddress(), "0xdeadbeef");
});

it("should emit event when removing a supported interface", async () => {
const { handler, otherSafe, preconfiguredValidator } = await setupTests();
const { user1, user2, handler, otherSafe, preconfiguredValidator } = await setupTests();

await expect(
executeContractCallWithSigners(
Expand All @@ -645,7 +646,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should not emit event when removing an unsupported interface", async () => {
const { handler, otherSafe, preconfiguredValidator } = await setupTests();
const { user1, user2, handler, otherSafe, preconfiguredValidator } = await setupTests();

await expect(
executeContractCallWithSigners(
Expand All @@ -659,7 +660,7 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("addSupportedInterfaceBatch(bytes4, bytes32[]", async () => {
describe("addSupportedInterfaceBatch(bytes4, bytes32[]", () => {
it("should revert if called by non-safe", async () => {
const { handler } = await setupTests();
await expect(handler.addSupportedInterfaceBatch("0xdeadbeef", [HashZero])).to.be.revertedWith(
Expand All @@ -668,7 +669,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should revert if batch contains an invalid interface", async () => {
const { validator, safe } = await setupTests();
const { user1, user2, validator, safe } = await setupTests();
await expect(
executeContractCallWithSigners(
safe,
Expand All @@ -681,7 +682,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should add all handlers in batch", async () => {
const { validator, safe, handler, mirror } = await setupTests();
const { user1, user2, validator, safe, handler, mirror } = await setupTests();
const safeAddress = await safe.getAddress();

// calculate the selector for each function
Expand Down Expand Up @@ -713,7 +714,7 @@ describe("ExtensibleFallbackHandler", async () => {
});
});

describe("removeSupportedInterfaceBatch(bytes4, bytes4[]", async () => {
describe("removeSupportedInterfaceBatch(bytes4, bytes4[]", () => {
it("should revert if called by non-safe", async () => {
const { handler } = await setupTests();
await expect(handler.removeSupportedInterfaceBatch("0xdeadbeef", ["0xdeadbeef"])).to.be.revertedWith(
Expand All @@ -722,7 +723,7 @@ describe("ExtensibleFallbackHandler", async () => {
});

it("should remove all methods in a batch", async () => {
const { validator, safe, handler, mirror } = await setupTests();
const { user1, user2, validator, safe, handler, mirror } = await setupTests();
const safeAddress = await safe.getAddress();

// calculate the selector for each function
Expand Down
2 changes: 1 addition & 1 deletion test/l2/Safe.Execution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("SafeL2", () => {
};
});

describe("execTransactions", async () => {
describe("execTransactions", () => {
it("should emit SafeMultiSigTransaction event", async () => {
const {
safe,
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/Migration.120.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("Migration 1.2.0", () => {
signers,
};
});
describe("constructor", async () => {
describe("constructor", () => {
it("can not use 0 Address", async () => {
const {
signers: [user1],
Expand Down

0 comments on commit 691aa4f

Please sign in to comment.