Skip to content

Commit

Permalink
Add test for migration to new governor
Browse files Browse the repository at this point in the history
  • Loading branch information
HickupHH3 committed Mar 4, 2022
1 parent adbc7a0 commit 31cb43d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions shared/Forking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../typechain';

export type DeployedContracts = {
governorV1: ArenaGovernor,
governor: ArenaGovernor;
timeLock: TimelockController;
tokenLock: TokenLock;
Expand All @@ -23,12 +24,14 @@ export const getPolygonContracts = (signer: Signer): DeployedContracts => {
if (!fs.existsSync(deploymentFilePath)) throw new Error(`File '${path.resolve(deploymentFilePath)}' does not exist.`);

const contents = fs.readFileSync(deploymentFilePath, `utf8`);
let governorV1Address;
let governorAddress;
let arenaAddress;
let timelockAddress;
let tokenLockAddress;
try {
({
governorV1: governorV1Address,
governor: governorAddress,
token: arenaAddress,
tokenLock: tokenLockAddress,
Expand All @@ -43,6 +46,7 @@ export const getPolygonContracts = (signer: Signer): DeployedContracts => {
if (!tokenLockAddress) throw new Error(`Deployment file did not include tokenLock address '${deploymentFilePath}'.`);

return {
governorV1: ArenaGovernor__factory.connect(governorV1Address, signer),
governor: ArenaGovernor__factory.connect(governorAddress, signer),
arenaToken: ArenaToken__factory.connect(arenaAddress, signer),
timeLock: TimelockController__factory.connect(timelockAddress, signer),
Expand Down
34 changes: 32 additions & 2 deletions test/GovernanceSim.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ chai.use(solidity);
// can simulate poylgon mainnet governance proposals here, enable fork object in hardhat.config.ts
describe.skip('Governance - Polygon mainnet proposal simulations', async () => {
const [user] = waffle.provider.getWallets();
const deployment = getPolygonContracts(user);
const {arenaToken, timeLock} = deployment;
let deployment = getPolygonContracts(user);
const {governorV1, governor, arenaToken, timeLock} = deployment;

it('should allow governance to move tokens in timeLock contract', async () => {
const treasuryAmount = await arenaToken.balanceOf(timeLock.address);
Expand All @@ -24,4 +24,34 @@ describe.skip('Governance - Polygon mainnet proposal simulations', async () => {

expect(await arenaToken.balanceOf(timeLock.address)).to.eq(ZERO);
});

it('should migrate to new governor', async () => {
// set to current existing governor for proposal creation
deployment.governor = governorV1;
const PROPOSER_ROLE = '0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1';
let targets: string[] = [timeLock.address, timeLock.address];
let values: string[] = [`0`, `0`];
let calldatas: string[] = [
timeLock.interface.encodeFunctionData('grantRole', [PROPOSER_ROLE, governor.address]),
timeLock.interface.encodeFunctionData('revokeRole', [PROPOSER_ROLE, governorV1.address]),
];
await createAndExecuteProposal({targets, values, calldatas, user, ...deployment});

const treasuryAmount = await arenaToken.balanceOf(timeLock.address);
targets = [arenaToken.address];
values = [`0`];
calldatas = [arenaToken.interface.encodeFunctionData('transfer', [user.address, treasuryAmount])];

// attempt to move funds through old governor, will fail
try {
await createAndExecuteProposal({targets, values, calldatas, user, ...deployment});
} catch (e) {
console.log(e);
}

// attempt to move funds through new governor, should be successful
deployment.governor = governor;
await createAndExecuteProposal({targets, values, calldatas, user, ...deployment});
expect(await arenaToken.balanceOf(timeLock.address)).to.eq(ZERO);
});
});

0 comments on commit 31cb43d

Please sign in to comment.