From a2c87cc995bdffb68be625581cc6cc8d3ac9a494 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria Date: Fri, 20 Oct 2023 14:17:18 +0200 Subject: [PATCH] Add tests --- contracts/libraries/SafeToL2Migration.sol | 8 +++--- test/libraries/SafeToL2Migration.spec.ts | 31 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/contracts/libraries/SafeToL2Migration.sol b/contracts/libraries/SafeToL2Migration.sol index 469bf485f..e7a814219 100644 --- a/contracts/libraries/SafeToL2Migration.sol +++ b/contracts/libraries/SafeToL2Migration.sol @@ -6,6 +6,7 @@ import {SafeStorage} from "../libraries/SafeStorage.sol"; import {Enum} from "../common/Enum.sol"; interface ISafe { + // solhint-disable-next-line function VERSION() external view returns (string memory); } @@ -72,11 +73,8 @@ contract SafeToL2Migration is SafeStorage { // Simulate a L2 transaction so indexer picks up the Safe // 0xef2624ae - keccack("migrateToL2(address)") bytes memory data = abi.encodeWithSelector(0xef2624ae, l2Singleton); - bytes memory additionalInfo; - { - // nonce, sender, threshold - additionalInfo = abi.encode(nonce, msg.sender, threshold); - } + // nonce, sender, threshold + bytes memory additionalInfo = abi.encode(nonce - 1, msg.sender, threshold); emit SafeMultiSigTransaction( MIGRATION_SINGLETON, 0, diff --git a/test/libraries/SafeToL2Migration.spec.ts b/test/libraries/SafeToL2Migration.spec.ts index c774e0099..15ab7343a 100644 --- a/test/libraries/SafeToL2Migration.spec.ts +++ b/test/libraries/SafeToL2Migration.spec.ts @@ -130,6 +130,7 @@ describe("SafeToL2Migration library", () => { singleton130L2Address, } = await setupTests(); const safeAddress = await safe130.getAddress(); + expect(await safe130.nonce()).to.be.eq(0); // Increase nonce by sending eth await user1.sendTransaction({ to: safeAddress, value: ethers.parseEther("1") }); @@ -137,6 +138,7 @@ describe("SafeToL2Migration library", () => { const safeTx = buildSafeTransaction({ to: user1.address, value: ethers.parseEther("1"), nonce }); await executeTxWithSigners(safe130, safeTx, [user1]); + expect(await safe130.nonce()).to.be.eq(1); await expect( executeContractCallWithSigners(safe130, migration, "migrateToL2", [singleton130L2Address], [user1], true), ).to.be.revertedWith("GS013"); @@ -155,13 +157,36 @@ describe("SafeToL2Migration library", () => { const safeAddress = await safe130.getAddress(); // The emit matcher checks the address, which is the Safe as delegatecall is used const migrationSafe = migration.attach(safeAddress); - - await expect(executeContractCallWithSigners(safe130, migration, "migrateToL2", [singleton130L2Address], [user1], true)) + const migrationAddress = await migration.getAddress(); + + const functionName = "migrateToL2"; + const expectedData = migration.interface.encodeFunctionData(functionName, [singleton130L2Address]); + const safeThreshold = await safe130.getThreshold(); + const additionalInfo = hre.ethers.AbiCoder.defaultAbiCoder().encode( + ["uint256", "address", "uint256"], + [0, user1.address, safeThreshold], + ); + await expect(executeContractCallWithSigners(safe130, migration, functionName, [singleton130L2Address], [user1], true)) .to.emit(migrationSafe, "ChangedMasterCopy") - .withArgs(singleton130L2Address); + .withArgs(singleton130L2Address) + .to.emit(migrationSafe, "SafeMultiSigTransaction") + .withArgs( + migrationAddress, + 0, + expectedData, + 1, + 0, + 0, + 0, + AddressZero, + AddressZero, + "0x", // We cannot detect signatures + additionalInfo, + ); const singletonResp = await user1.call({ to: safeAddress, data: migratedInterface.encodeFunctionData("masterCopy") }); expect(migratedInterface.decodeFunctionResult("masterCopy", singletonResp)[0]).to.eq(singleton130L2Address); + expect(await safe130.nonce()).to.be.eq(1); }); it("doesn't touch important storage slots", async () => {