Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Oct 25, 2023
1 parent 6eb48a4 commit 01707b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
20 changes: 12 additions & 8 deletions contracts/libraries/SafeToL2Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ contract SafeToL2Migration is SafeStorage {
bytes additionalInfo
);

function migrate(address l2Singleton) private {
function migrate(address l2Singleton, bytes memory functionData) private {
singleton = l2Singleton;

// Simulate a L2 transaction so indexer picks up the Safe
// 0xef2624ae - keccak("migrateToL2(address)")
bytes memory data = abi.encodeWithSelector(0xef2624ae, l2Singleton);
// nonce, sender, threshold
// Encode nonce, sender, threshold
bytes memory additionalInfo = abi.encode(nonce - 1, msg.sender, threshold);

// Simulate a L2 transaction so indexer picks up the Safe
emit SafeMultiSigTransaction(
MIGRATION_SINGLETON,
0,
data,
functionData,
Enum.Operation.DelegateCall,
0,
0,
Expand Down Expand Up @@ -104,7 +103,9 @@ contract SafeToL2Migration is SafeStorage {
"Provided singleton version is not supported"
);

migrate(l2Singleton);
// 0xef2624ae - keccak("migrateToL2(address)")
bytes memory functionData = abi.encodeWithSelector(0xef2624ae, l2Singleton);
migrate(l2Singleton, functionData);
}

function migrateFromV111(address l2Singleton, address fallbackHandler) public {
Expand All @@ -123,7 +124,10 @@ contract SafeToL2Migration is SafeStorage {
ISafe safe = ISafe(address(this));
safe.setFallbackHandler(fallbackHandler);
emit SafeSetup(MIGRATION_SINGLETON, safe.getOwners(), safe.getThreshold(), address(0), fallbackHandler);
migrate(l2Singleton);

// 0xd9a20812 - keccak("migrateFromV111(address,address)")
bytes memory functionData = abi.encodeWithSelector(0xd9a20812, l2Singleton, fallbackHandler);
migrate(l2Singleton, functionData);
}

/**
Expand Down
24 changes: 23 additions & 1 deletion test/libraries/SafeToL2Migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,33 @@ describe("SafeToL2Migration library", () => {
]);
const nonce = await safe111.nonce();
expect(nonce).to.be.eq(0);
const safeThreshold = await safe111.getThreshold();
const additionalInfo = hre.ethers.AbiCoder.defaultAbiCoder().encode(
["uint256", "address", "uint256"],
[0, user1.address, safeThreshold],
);

const tx = buildSafeTransaction({ to: migrationAddress, data, operation: 1, nonce });

expect(await executeTx(safe111, tx, [await safeApproveHash(user1, safe111, tx, true)]))
.to.emit(migrationSafe, "ChangedMasterCopy")
.withArgs(SAFE_SINGLETON_141_L2_ADDRESS);
.withArgs(SAFE_SINGLETON_141_L2_ADDRESS)
.to.emit(migrationSafe, "SafeMultiSigTransaction")
.withArgs(
migrationAddress,
0,
data,
1,
0,
0,
0,
AddressZero,
AddressZero,
"0x", // We cannot detect signatures
additionalInfo,
)
.to.emit(migrationSafe, "SafeSetup")
.withArgs(migrationAddress, await safe111.getOwners(), safeThreshold, AddressZero, COMPATIBILITY_FALLBACK_HANDLER_150);

expect(await safe111.nonce()).to.be.eq(1);
expect(await safe111.VERSION()).to.be.eq("1.4.1");
Expand Down

0 comments on commit 01707b3

Please sign in to comment.