Skip to content

Commit 70673bb

Browse files
authored
Update SafeMigration tests for zkSync (#833)
This PR: - Partially solves #767 (test updates for `SafeToL2Upgrade` are still pending) - It is based on version 1.5.0 because 1.4.1 cannot be compiled at the moment because we used `.send` in there, and hardhat zksync compiler plugin needs to be updated to support suppressing errors. I will cherry-pick it later. - I updated the `deployContract` function name and return type to be more self-explanatory - The main changes were around adding zksync compatible bytecode and also using the ContractFactory from the "zksync-ethers" package because in ZkSync you need to interact with a system contract to deploy contracts and not just send a transaction with the bytecode and `to` address omitted. One bug found: matter-labs/hardhat-zksync#1420
1 parent 7ccf6e0 commit 70673bb

19 files changed

+306
-266
lines changed

package-lock.json

Lines changed: 181 additions & 182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@
6060
"devDependencies": {
6161
"@eslint/js": "^9.9.1",
6262
"@matterlabs/hardhat-zksync-deploy": "^1.5.0",
63-
"@matterlabs/hardhat-zksync-ethers": "^1.2.0-beta.3",
63+
"@matterlabs/hardhat-zksync-ethers": "^1.2.1",
6464
"@matterlabs/hardhat-zksync-node": "^1.1.1",
6565
"@matterlabs/hardhat-zksync-solc": "^1.2.4",
6666
"@matterlabs/hardhat-zksync-verify": "^1.6.0",
6767
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
6868
"@openzeppelin/contracts": "^3.4.0",
6969
"@safe-global/mock-contract": "^4.1.0",
70-
"@safe-global/safe-singleton-factory": "^1.0.32",
70+
"@safe-global/safe-singleton-factory": "^1.0.33",
7171
"@types/chai": "^4.3.19",
7272
"@types/mocha": "^10.0.7",
7373
"@types/node": "^20.11.30",
@@ -92,6 +92,6 @@
9292
"typescript": "^5.5.4",
9393
"typescript-eslint": "^8.4.0",
9494
"yargs": "^17.7.2",
95-
"zksync-ethers": "6.11.2"
95+
"zksync-ethers": "6.12.1"
9696
}
9797
}

test/accessors/SimulateTxAccessor.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "chai";
22
import hre, { deployments, ethers } from "hardhat";
3-
import { deployContract, getSimulateTxAccessor, getSafe, getCompatFallbackHandler } from "../utils/setup";
3+
import { deployContractFromSource, getSimulateTxAccessor, getSafe, getCompatFallbackHandler } from "../utils/setup";
44
import { buildContractCall } from "../../src/utils/execution";
55

66
describe("SimulateTxAccessor", () => {
@@ -17,7 +17,7 @@ describe("SimulateTxAccessor", () => {
1717
return target.balance;
1818
}
1919
}`;
20-
const interactor = await deployContract(user1, source);
20+
const interactor = await deployContractFromSource(user1, source);
2121
const handler = await getCompatFallbackHandler();
2222
const handlerAddress = await handler.getAddress();
2323
const safe = await getSafe({ owners: [user1.address], threshold: 1, fallbackHandler: handlerAddress });

test/core/Safe.Execution.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "chai";
22
import hre from "hardhat";
3-
import { deployContract, getSafe } from "../utils/setup";
3+
import { deployContractFromSource, getSafe } from "../utils/setup";
44
import {
55
safeApproveHash,
66
buildSignatureBytes,
@@ -30,7 +30,7 @@ describe("Safe", () => {
3030
/* solhint-enable no-inline-assembly */
3131
}
3232
}`;
33-
const storageSetter = await deployContract(user1, setterSource);
33+
const storageSetter = await deployContractFromSource(user1, setterSource);
3434
const TestNativeTokenReceiver = await hre.ethers.getContractFactory("TestNativeTokenReceiver");
3535
const nativeTokenReceiver = await TestNativeTokenReceiver.deploy();
3636

@@ -40,7 +40,7 @@ describe("Safe", () => {
4040
require(false, "Shit happens");
4141
}
4242
}`;
43-
const reverter = await deployContract(user1, reverterSource);
43+
const reverter = await deployContractFromSource(user1, reverterSource);
4444
return {
4545
safe: await getSafe({ owners: [user1.address] }),
4646
reverter,
@@ -305,7 +305,7 @@ describe("Safe", () => {
305305
this.nested(8, count);
306306
}
307307
}`;
308-
const gasUser = await deployContract(user1, gasUserSource);
308+
const gasUser = await deployContractFromSource(user1, gasUserSource);
309309
const to = await gasUser.getAddress();
310310
const data = gasUser.interface.encodeFunctionData("useGas", [80]);
311311
const safeTxGas = 10000;

test/core/Safe.FallbackManager.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from "chai";
22
import hre, { deployments, ethers } from "hardhat";
33
import { AddressZero } from "@ethersproject/constants";
4-
import { defaultTokenCallbackHandlerDeployment, deployContract, getSafeTemplate, getTokenCallbackHandler } from "../utils/setup";
4+
import { defaultTokenCallbackHandlerDeployment, deployContractFromSource, getSafeTemplate, getTokenCallbackHandler } from "../utils/setup";
55
import { executeContractCallWithSigners } from "../../src/utils/execution";
66

77
describe("FallbackManager", () => {
@@ -19,7 +19,7 @@ describe("FallbackManager", () => {
1919
}`;
2020
const signers = await ethers.getSigners();
2121
const [user1] = signers;
22-
const mirror = await deployContract(user1, source);
22+
const mirror = await deployContractFromSource(user1, source);
2323
return {
2424
safe: await getSafeTemplate(),
2525
mirror,

test/core/Safe.Incoming.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "chai";
22
import hre, { ethers } from "hardhat";
3-
import { deployContract, getSafe } from "../utils/setup";
3+
import { deployContractFromSource, getSafe } from "../utils/setup";
44

55
describe("Safe", () => {
66
const setupTests = hre.deployments.createFixture(async ({ deployments }) => {
@@ -25,8 +25,8 @@ describe("Safe", () => {
2525
const [user1] = signers;
2626
return {
2727
safe: await getSafe({ owners: [user1.address] }),
28-
gasCappedTransferContract: hre.network.zksync ? null : await deployContract(user1, gasCappedTransferSource),
29-
callContract: await deployContract(user1, callSource),
28+
gasCappedTransferContract: hre.network.zksync ? null : await deployContractFromSource(user1, gasCappedTransferSource),
29+
callContract: await deployContractFromSource(user1, callSource),
3030
signers,
3131
};
3232
});

test/core/Safe.Setup.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import hre, { ethers } from "hardhat";
33
import { AddressZero } from "@ethersproject/constants";
44

5-
import { deployContract, getMock, getSafeSingleton, getSafeTemplate } from "../utils/setup";
5+
import { deployContractFromSource, getMock, getSafeSingleton, getSafeTemplate } from "../utils/setup";
66
import { calculateSafeDomainSeparator } from "../../src/utils/execution";
77
import { AddressOne } from "../../src/utils/constants";
88
import { chainId, encodeTransfer } from "../utils/encoding";
@@ -231,7 +231,7 @@ describe("Safe", () => {
231231
/* solhint-enable no-inline-assembly */
232232
}
233233
}`;
234-
const testIntializer = await deployContract(user1, source);
234+
const testIntializer = await deployContractFromSource(user1, source);
235235
const testIntializerAddress = await testIntializer.getAddress();
236236
const initData = testIntializer.interface.encodeFunctionData("init", ["0x42baddad"]);
237237
await expect(
@@ -272,7 +272,7 @@ describe("Safe", () => {
272272
require(false, "Computer says nah");
273273
}
274274
}`;
275-
const testIntializer = await deployContract(user1, source);
275+
const testIntializer = await deployContractFromSource(user1, source);
276276
const testIntializerAddress = await testIntializer.getAddress();
277277
const initData = testIntializer.interface.encodeFunctionData("init", ["0x42baddad"]);
278278
await expect(

test/factory/ProxyFactory.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from "chai";
22
import hre, { ethers } from "hardhat";
33
import { Contract } from "ethers";
4-
import { deployContract, getFactory, getMock, getSafe, getSafeProxyRuntimeCode } from "../utils/setup";
4+
import { deployContractFromSource, getFactory, getMock, getSafe, getSafeProxyRuntimeCode } from "../utils/setup";
55
import { AddressZero } from "@ethersproject/constants";
66
import { calculateChainSpecificProxyAddress, calculateProxyAddress, calculateProxyAddressWithCallback } from "../../src/utils/proxies";
77
import { chainId } from "./../utils/encoding";
@@ -35,7 +35,7 @@ describe("ProxyFactory", () => {
3535
await deployments.fixture();
3636
const signers = await hre.ethers.getSigners();
3737
const [user1] = signers;
38-
const singleton = await deployContract(user1, SINGLETON_SOURCE);
38+
const singleton = await deployContractFromSource(user1, SINGLETON_SOURCE);
3939
return {
4040
safe: await getSafe({ owners: [user1.address] }),
4141
factory: await getFactory(),

test/integration/Safe.0xExploit.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import hre, { deployments, ethers } from "hardhat";
33
import { AddressZero } from "@ethersproject/constants";
44
import { defaultAbiCoder } from "@ethersproject/abi";
5-
import { getSafe, deployContract, getCompatFallbackHandler } from "../utils/setup";
5+
import { getSafe, deployContractFromSource, getCompatFallbackHandler } from "../utils/setup";
66
import { buildSignatureBytes, executeContractCallWithSigners, signHash } from "../../src/utils/execution";
77

88
describe("Safe", () => {
@@ -111,7 +111,7 @@ describe("Safe", () => {
111111
changeState = value;
112112
}
113113
}`;
114-
const testValidator = await deployContract(user1, source);
114+
const testValidator = await deployContractFromSource(user1, source);
115115
const testValidatorAddress = await testValidator.getAddress();
116116
await testValidator.shouldChangeState(true);
117117

test/json/fallbackHandlerDeployment.json

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)