|
| 1 | +import { expect } from "chai"; |
| 2 | +import hre, { deployments } from "hardhat"; |
| 3 | +import { AddressZero } from "@ethersproject/constants"; |
| 4 | +import { getFactory, getMock, getMultiSend } from "../utils/setup"; |
| 5 | +import { buildSafeTransaction, executeTx, safeApproveHash } from "../../src/utils/execution"; |
| 6 | +import { verificationTests } from "./subTests.spec"; |
| 7 | +import deploymentData from "../json/safeDeployment.json"; |
| 8 | +import { calculateProxyAddress } from "../../src/utils/proxies"; |
| 9 | + |
| 10 | +describe("Upgrade from Safe 1.3.0 L2", () => { |
| 11 | + before(function () { |
| 12 | + /** |
| 13 | + * ## There's no safe 1.3.0 on zkSync, so we skip this test |
| 14 | + */ |
| 15 | + if (hre.network.zksync) this.skip(); |
| 16 | + }); |
| 17 | + |
| 18 | + // We migrate the Safe and run the verification tests |
| 19 | + const setupTests = deployments.createFixture(async ({ deployments }) => { |
| 20 | + await deployments.fixture(); |
| 21 | + const mock = await getMock(); |
| 22 | + const mockAddress = await mock.getAddress(); |
| 23 | + const [user1] = await hre.ethers.getSigners(); |
| 24 | + const singleton130L2 = (await (await user1.sendTransaction({ data: deploymentData.safe130l2.evm })).wait())?.contractAddress; |
| 25 | + if (!singleton130L2) throw new Error("Could not deploy Safe 1.3.0 L2"); |
| 26 | + |
| 27 | + const factory = await getFactory(); |
| 28 | + const saltNonce = 42; |
| 29 | + const proxyAddress = await calculateProxyAddress(factory, singleton130L2, "0x", saltNonce); |
| 30 | + await factory.createProxyWithNonce(singleton130L2, "0x", saltNonce).then((tx) => tx.wait()); |
| 31 | + |
| 32 | + const safe = await hre.ethers.getContractAt("Safe", proxyAddress); |
| 33 | + await safe.setup([user1.address], 1, AddressZero, "0x", mockAddress, AddressZero, 0, AddressZero); |
| 34 | + |
| 35 | + expect(await safe.VERSION()).to.be.eq("1.3.0"); |
| 36 | + const safeMigrationDeployment = await deployments.get("SafeMigration"); |
| 37 | + const safeMigration = await hre.ethers.getContractAt("SafeMigration", safeMigrationDeployment.address); |
| 38 | + const nonce = await safe.nonce(); |
| 39 | + const data = safeMigration.interface.encodeFunctionData("migrateSingleton"); |
| 40 | + const tx = buildSafeTransaction({ to: await safeMigration.getAddress(), data, nonce, operation: 1 }); |
| 41 | + await executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]); |
| 42 | + expect(await safe.VERSION()).to.be.eq("1.5.0"); |
| 43 | + |
| 44 | + return { |
| 45 | + migratedSafe: safe, |
| 46 | + mock, |
| 47 | + multiSend: await getMultiSend(), |
| 48 | + }; |
| 49 | + }); |
| 50 | + |
| 51 | + it("passes the Safe 1.3.0 tests", async () => { |
| 52 | + await verificationTests(setupTests); |
| 53 | + }); |
| 54 | +}); |
0 commit comments