-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #265: Added test for migration from 1.2.0 to 1.3.0
- Loading branch information
Showing
5 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expect } from "chai"; | ||
import hre, { ethers, deployments, waffle } from "hardhat"; | ||
import "@nomiclabs/hardhat-ethers"; | ||
import { AddressZero } from "@ethersproject/constants"; | ||
import { getSafeWithOwners, getSafeSingleton, migrationContract, getFactory, getMock } from "../utils/setup"; | ||
import { buildSafeTransaction, executeTx, executeTxWithSigners, safeApproveHash } from "../utils/execution"; | ||
import { verificationTests } from "./subTests.spec"; | ||
import deploymentData from "./safeDeployment.json"; | ||
import { calculateProxyAddress } from "../utils/proxies"; | ||
|
||
describe("Upgrade from Safe 1.2.0", () => { | ||
|
||
const [user1] = waffle.provider.getWallets(); | ||
|
||
const ChangeMasterCopyInterface = new ethers.utils.Interface(["function changeMasterCopy(address target)"]) | ||
|
||
// We migrate the Safe and run the verification tests | ||
const setupTests = deployments.createFixture(async ({ deployments }) => { | ||
await deployments.fixture(); | ||
const singleton120 = (await (await user1.sendTransaction({ data: deploymentData.safe120 })).wait()).contractAddress | ||
const singleton130 = (await getSafeSingleton()).address | ||
const factory = await getFactory() | ||
const saltNonce = 42 | ||
const proxyAddress = await calculateProxyAddress(factory, singleton120, "0x", saltNonce) | ||
await factory.createProxyWithNonce(singleton120, "0x", saltNonce).then((tx: any) => tx.wait()) | ||
|
||
const Safe = await hre.ethers.getContractFactory("GnosisSafe"); | ||
const safe = Safe.attach(proxyAddress) | ||
await safe.setup([user1.address], 1, AddressZero, "0x", AddressZero, AddressZero, 0, AddressZero) | ||
|
||
expect(await safe.VERSION()).to.be.eq("1.2.0") | ||
const nonce = await safe.callStatic.nonce() | ||
const data = ChangeMasterCopyInterface.encodeFunctionData("changeMasterCopy", [singleton130]) | ||
const tx = buildSafeTransaction({ to: safe.address, data, nonce }) | ||
await executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]) | ||
expect(await safe.VERSION()).to.be.eq("1.3.0") | ||
|
||
return { | ||
migratedSafe: safe, | ||
mock: await getMock() | ||
} | ||
}) | ||
verificationTests(setupTests) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Contract } from "@ethersproject/contracts" | ||
import { parseEther } from "@ethersproject/units" | ||
import { expect } from "chai"; | ||
import hre, { ethers, waffle } from "hardhat"; | ||
import { buildSafeTransaction, executeTx, executeTxWithSigners } from "../utils/execution" | ||
|
||
interface TestSetup { | ||
migratedSafe: Contract, | ||
mock: Contract | ||
} | ||
|
||
export const verificationTests = (setupTests: () => Promise<TestSetup>) => { | ||
|
||
const [user1, user2] = waffle.provider.getWallets(); | ||
|
||
describe("execTransaction", async () => { | ||
it('should be able to transfer ETH', async () => { | ||
const { migratedSafe } = await setupTests() | ||
await user1.sendTransaction({ to: migratedSafe.address, value: parseEther("1") }) | ||
const nonce = await migratedSafe.nonce() | ||
const tx = buildSafeTransaction({ to: user2.address, value: parseEther("1"), nonce }) | ||
|
||
const userBalance = await ethers.provider.getBalance(user2.address) | ||
await expect(await ethers.provider.getBalance(migratedSafe.address)).to.be.deep.eq(parseEther("1")) | ||
|
||
await executeTxWithSigners(migratedSafe, tx, [user1]) | ||
|
||
await expect(await ethers.provider.getBalance(user2.address)).to.be.deep.eq(userBalance.add(parseEther("1"))) | ||
await expect(await ethers.provider.getBalance(migratedSafe.address)).to.be.deep.eq(parseEther("0")) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters