-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpgradeFromSafe141L2.spec.js
More file actions
49 lines (43 loc) · 2.52 KB
/
Copy pathUpgradeFromSafe141L2.spec.js
File metadata and controls
49 lines (43 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { expect } from "chai";
import hre, { deployments } from "hardhat";
import { AddressZero } from "@ethersproject/constants";
import { getAbi, getFactory, getMock, getMultiSend } from "../utils/setup";
import { buildSafeTransaction, executeTx, safeApproveHash } from "../../src/utils/execution";
import { verificationTests } from "./subTests.spec";
import deploymentData from "../json/safeDeployment.json";
import { calculateProxyAddress } from "../../src/utils/proxies";
describe("Upgrade from Safe 1.4.1 L2", () => {
// We migrate the Safe and run the verification tests
const setupTests = deployments.createFixture(async ({ deployments }) => {
await deployments.fixture();
const mock = await getMock();
const mockAddress = await mock.getAddress();
const signers = await hre.ethers.getSigners();
const [user1] = signers;
const safeDeploymentData = hre.network.zksync ? deploymentData.safe141l2.zksync : deploymentData.safe141l2.evm;
const safeContractFactory = new hre.ethers.ContractFactory(await getAbi("Safe"), safeDeploymentData, user1);
const singleton141L2 = await (await safeContractFactory.deploy()).getAddress();
if (!singleton141L2) throw new Error("Could not deploy Safe 1.4.1 L2");
const factory = await getFactory();
const saltNonce = 42;
const proxyAddress = await calculateProxyAddress(factory, singleton141L2, "0x", saltNonce, hre.network.zksync);
await factory.createProxyWithNonce(singleton141L2, "0x", saltNonce).then((tx) => tx.wait());
const safe = await hre.ethers.getContractAt("Safe", proxyAddress);
await safe.setup([user1.address], 1, AddressZero, "0x", mockAddress, AddressZero, 0, AddressZero);
expect(await safe.VERSION()).to.be.eq("1.4.1");
const safeMigrationDeployment = await deployments.get("SafeMigration");
const safeMigration = await hre.ethers.getContractAt("SafeMigration", safeMigrationDeployment.address);
const nonce = await safe.nonce();
const data = safeMigration.interface.encodeFunctionData("migrateSingleton");
const tx = buildSafeTransaction({ to: await safeMigration.getAddress(), data, nonce, operation: 1 });
await executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]);
expect(await safe.VERSION()).to.be.eq("1.5.0");
return {
migratedSafe: safe,
mock,
multiSend: await getMultiSend(),
signers,
};
});
verificationTests(setupTests);
});