From 8e70033de5d1e093bfd1d440028c0327510bc175 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 1 Feb 2021 18:24:15 +0100 Subject: [PATCH] add test ensuring storage is preserved on upgrade --- test/e2e/upgradeAuthenticator.test.ts | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/e2e/upgradeAuthenticator.test.ts b/test/e2e/upgradeAuthenticator.test.ts index 16b5bdc3..3ba9221e 100644 --- a/test/e2e/upgradeAuthenticator.test.ts +++ b/test/e2e/upgradeAuthenticator.test.ts @@ -1,18 +1,22 @@ import { expect } from "chai"; import { Contract, Wallet } from "ethers"; -import { deployments, ethers } from "hardhat"; +import { deployments, ethers, waffle } from "hardhat"; +import { setupSolversTask } from "../../src/tasks/solvers"; import { SALT } from "../../src/ts"; import { deployTestContracts } from "./fixture"; -describe("Upgrading", () => { +describe("Upgrade Authenticator", () => { let authenticator: Contract; let deployer: Wallet; let owner: Wallet; + let solver: Wallet; beforeEach(async () => { ({ authenticator, deployer, owner } = await deployTestContracts()); + // Solver isn't a named account + solver = waffle.provider.getWallets()[2]; }); it("should upgrade authenticator", async () => { @@ -20,6 +24,7 @@ describe("Upgrading", () => { "GPv2AllowListAuthenticationV2", deployer, ); + // Note that, before the upgrade this is actually the old instance const authenticatorV2 = GPv2AllowListAuthenticationV2.attach( authenticator.address, ); @@ -34,6 +39,27 @@ describe("Upgrading", () => { expect(await authenticatorV2.newMethod()).to.equal(1337); }); + it("should preserve storage", async () => { + authenticator.connect(owner).addSolver(solver.address); + + // Upgrade after storage is set. + await upgrade( + "GPv2AllowListAuthentication", + "GPv2AllowListAuthenticationV2", + ); + + const GPv2AllowListAuthenticationV2 = await ethers.getContractFactory( + "GPv2AllowListAuthenticationV2", + deployer, + ); + const authenticatorV2 = GPv2AllowListAuthenticationV2.attach( + authenticator.address, + ); + // Both, the listed solvers and original manager are still set + expect(await authenticatorV2.isSolver(solver.address)).to.equal(true); + expect(await authenticatorV2.manager()).to.equal(owner.address); + }); + async function upgrade(contractName: string, newContractName: string) { await deployments.deploy(contractName, { contract: newContractName,