Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
add test ensuring storage is preserved on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Feb 1, 2021
1 parent 8a93633 commit 8e70033
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/e2e/upgradeAuthenticator.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
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 () => {
const GPv2AllowListAuthenticationV2 = await ethers.getContractFactory(
"GPv2AllowListAuthenticationV2",
deployer,
);
// Note that, before the upgrade this is actually the old instance
const authenticatorV2 = GPv2AllowListAuthenticationV2.attach(
authenticator.address,
);
Expand All @@ -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,
Expand Down

0 comments on commit 8e70033

Please sign in to comment.