Skip to content

Commit

Permalink
Update SafeMigration tests for zkSync (#833)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mmv08 authored Sep 19, 2024
1 parent 7ccf6e0 commit 70673bb
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 266 deletions.
363 changes: 181 additions & 182 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"devDependencies": {
"@eslint/js": "^9.9.1",
"@matterlabs/hardhat-zksync-deploy": "^1.5.0",
"@matterlabs/hardhat-zksync-ethers": "^1.2.0-beta.3",
"@matterlabs/hardhat-zksync-ethers": "^1.2.1",
"@matterlabs/hardhat-zksync-node": "^1.1.1",
"@matterlabs/hardhat-zksync-solc": "^1.2.4",
"@matterlabs/hardhat-zksync-verify": "^1.6.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@openzeppelin/contracts": "^3.4.0",
"@safe-global/mock-contract": "^4.1.0",
"@safe-global/safe-singleton-factory": "^1.0.32",
"@safe-global/safe-singleton-factory": "^1.0.33",
"@types/chai": "^4.3.19",
"@types/mocha": "^10.0.7",
"@types/node": "^20.11.30",
Expand All @@ -92,6 +92,6 @@
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0",
"yargs": "^17.7.2",
"zksync-ethers": "6.11.2"
"zksync-ethers": "6.12.1"
}
}
4 changes: 2 additions & 2 deletions test/accessors/SimulateTxAccessor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { deployContract, getSimulateTxAccessor, getSafe, getCompatFallbackHandler } from "../utils/setup";
import { deployContractFromSource, getSimulateTxAccessor, getSafe, getCompatFallbackHandler } from "../utils/setup";
import { buildContractCall } from "../../src/utils/execution";

describe("SimulateTxAccessor", () => {
Expand All @@ -17,7 +17,7 @@ describe("SimulateTxAccessor", () => {
return target.balance;
}
}`;
const interactor = await deployContract(user1, source);
const interactor = await deployContractFromSource(user1, source);
const handler = await getCompatFallbackHandler();
const handlerAddress = await handler.getAddress();
const safe = await getSafe({ owners: [user1.address], threshold: 1, fallbackHandler: handlerAddress });
Expand Down
8 changes: 4 additions & 4 deletions test/core/Safe.Execution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre from "hardhat";
import { deployContract, getSafe } from "../utils/setup";
import { deployContractFromSource, getSafe } from "../utils/setup";
import {
safeApproveHash,
buildSignatureBytes,
Expand Down Expand Up @@ -30,7 +30,7 @@ describe("Safe", () => {
/* solhint-enable no-inline-assembly */
}
}`;
const storageSetter = await deployContract(user1, setterSource);
const storageSetter = await deployContractFromSource(user1, setterSource);
const TestNativeTokenReceiver = await hre.ethers.getContractFactory("TestNativeTokenReceiver");
const nativeTokenReceiver = await TestNativeTokenReceiver.deploy();

Expand All @@ -40,7 +40,7 @@ describe("Safe", () => {
require(false, "Shit happens");
}
}`;
const reverter = await deployContract(user1, reverterSource);
const reverter = await deployContractFromSource(user1, reverterSource);
return {
safe: await getSafe({ owners: [user1.address] }),
reverter,
Expand Down Expand Up @@ -305,7 +305,7 @@ describe("Safe", () => {
this.nested(8, count);
}
}`;
const gasUser = await deployContract(user1, gasUserSource);
const gasUser = await deployContractFromSource(user1, gasUserSource);
const to = await gasUser.getAddress();
const data = gasUser.interface.encodeFunctionData("useGas", [80]);
const safeTxGas = 10000;
Expand Down
4 changes: 2 additions & 2 deletions test/core/Safe.FallbackManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { AddressZero } from "@ethersproject/constants";
import { defaultTokenCallbackHandlerDeployment, deployContract, getSafeTemplate, getTokenCallbackHandler } from "../utils/setup";
import { defaultTokenCallbackHandlerDeployment, deployContractFromSource, getSafeTemplate, getTokenCallbackHandler } from "../utils/setup";
import { executeContractCallWithSigners } from "../../src/utils/execution";

describe("FallbackManager", () => {
Expand All @@ -19,7 +19,7 @@ describe("FallbackManager", () => {
}`;
const signers = await ethers.getSigners();
const [user1] = signers;
const mirror = await deployContract(user1, source);
const mirror = await deployContractFromSource(user1, source);
return {
safe: await getSafeTemplate(),
mirror,
Expand Down
6 changes: 3 additions & 3 deletions test/core/Safe.Incoming.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { ethers } from "hardhat";
import { deployContract, getSafe } from "../utils/setup";
import { deployContractFromSource, getSafe } from "../utils/setup";

describe("Safe", () => {
const setupTests = hre.deployments.createFixture(async ({ deployments }) => {
Expand All @@ -25,8 +25,8 @@ describe("Safe", () => {
const [user1] = signers;
return {
safe: await getSafe({ owners: [user1.address] }),
gasCappedTransferContract: hre.network.zksync ? null : await deployContract(user1, gasCappedTransferSource),
callContract: await deployContract(user1, callSource),
gasCappedTransferContract: hre.network.zksync ? null : await deployContractFromSource(user1, gasCappedTransferSource),
callContract: await deployContractFromSource(user1, callSource),
signers,
};
});
Expand Down
6 changes: 3 additions & 3 deletions test/core/Safe.Setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from "chai";
import hre, { ethers } from "hardhat";
import { AddressZero } from "@ethersproject/constants";

import { deployContract, getMock, getSafeSingleton, getSafeTemplate } from "../utils/setup";
import { deployContractFromSource, getMock, getSafeSingleton, getSafeTemplate } from "../utils/setup";
import { calculateSafeDomainSeparator } from "../../src/utils/execution";
import { AddressOne } from "../../src/utils/constants";
import { chainId, encodeTransfer } from "../utils/encoding";
Expand Down Expand Up @@ -231,7 +231,7 @@ describe("Safe", () => {
/* solhint-enable no-inline-assembly */
}
}`;
const testIntializer = await deployContract(user1, source);
const testIntializer = await deployContractFromSource(user1, source);
const testIntializerAddress = await testIntializer.getAddress();
const initData = testIntializer.interface.encodeFunctionData("init", ["0x42baddad"]);
await expect(
Expand Down Expand Up @@ -272,7 +272,7 @@ describe("Safe", () => {
require(false, "Computer says nah");
}
}`;
const testIntializer = await deployContract(user1, source);
const testIntializer = await deployContractFromSource(user1, source);
const testIntializerAddress = await testIntializer.getAddress();
const initData = testIntializer.interface.encodeFunctionData("init", ["0x42baddad"]);
await expect(
Expand Down
4 changes: 2 additions & 2 deletions test/factory/ProxyFactory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import hre, { ethers } from "hardhat";
import { Contract } from "ethers";
import { deployContract, getFactory, getMock, getSafe, getSafeProxyRuntimeCode } from "../utils/setup";
import { deployContractFromSource, getFactory, getMock, getSafe, getSafeProxyRuntimeCode } from "../utils/setup";
import { AddressZero } from "@ethersproject/constants";
import { calculateChainSpecificProxyAddress, calculateProxyAddress, calculateProxyAddressWithCallback } from "../../src/utils/proxies";
import { chainId } from "./../utils/encoding";
Expand Down Expand Up @@ -35,7 +35,7 @@ describe("ProxyFactory", () => {
await deployments.fixture();
const signers = await hre.ethers.getSigners();
const [user1] = signers;
const singleton = await deployContract(user1, SINGLETON_SOURCE);
const singleton = await deployContractFromSource(user1, SINGLETON_SOURCE);
return {
safe: await getSafe({ owners: [user1.address] }),
factory: await getFactory(),
Expand Down
4 changes: 2 additions & 2 deletions test/integration/Safe.0xExploit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { AddressZero } from "@ethersproject/constants";
import { defaultAbiCoder } from "@ethersproject/abi";
import { getSafe, deployContract, getCompatFallbackHandler } from "../utils/setup";
import { getSafe, deployContractFromSource, getCompatFallbackHandler } from "../utils/setup";
import { buildSignatureBytes, executeContractCallWithSigners, signHash } from "../../src/utils/execution";

describe("Safe", () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("Safe", () => {
changeState = value;
}
}`;
const testValidator = await deployContract(user1, source);
const testValidator = await deployContractFromSource(user1, source);
const testValidatorAddress = await testValidator.getAddress();
await testValidator.shouldChangeState(true);

Expand Down
5 changes: 4 additions & 1 deletion test/json/fallbackHandlerDeployment.json

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions test/json/safeDeployment.json

Large diffs are not rendered by default.

File renamed without changes.
6 changes: 3 additions & 3 deletions test/libraries/MultiSend.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { ethers } from "hardhat";
import { deployContract, getMock, getMultiSend, getSafe, getDelegateCaller } from "../utils/setup";
import { deployContractFromSource, getMock, getMultiSend, getSafe, getDelegateCaller } from "../utils/setup";
import {
buildContractCall,
buildSafeTransaction,
Expand Down Expand Up @@ -28,7 +28,7 @@ describe("MultiSend", () => {
}`;
const signers = await hre.ethers.getSigners();
const [user1] = signers;
const storageSetter = await deployContract(user1, setterSource);
const storageSetter = await deployContractFromSource(user1, setterSource);
return {
safe: await getSafe({ owners: [user1.address] }),
multiSend: await getMultiSend(),
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("MultiSend", () => {
selfdestruct(payable(msg.sender));
}
}`;
const killLib = await deployContract(user1, source);
const killLib = await deployContractFromSource(user1, source);

const nestedTransactionData = encodeMultiSend([await buildContractCall(killLib, "killme", [], 0)]);

Expand Down
4 changes: 2 additions & 2 deletions test/libraries/MultiSendCallOnly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { ethers } from "hardhat";
import { deployContract, getMock, getMultiSendCallOnly, getSafe, getDelegateCaller } from "../utils/setup";
import { deployContractFromSource, getMock, getMultiSendCallOnly, getSafe, getDelegateCaller } from "../utils/setup";
import {
buildContractCall,
buildSafeTransaction,
Expand Down Expand Up @@ -28,7 +28,7 @@ describe("MultiSendCallOnly", () => {
}`;
const signers = await hre.ethers.getSigners();
const [user1] = signers;
const storageSetter = await deployContract(user1, setterSource);
const storageSetter = await deployContractFromSource(user1, setterSource);
return {
safe: await getSafe({ owners: [user1.address] }),
multiSend: await getMultiSendCallOnly(),
Expand Down
Loading

0 comments on commit 70673bb

Please sign in to comment.