Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit f868cf1

Browse files
committed
GovernanceSim test: advance time in addition to blocks for better simulation
1 parent c67e514 commit f868cf1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

test/shared/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export const MAX_UINT = constants.MaxUint256;
99
export const ONE_HOUR = 60 * 60;
1010
export const ONE_DAY = 24 * ONE_HOUR;
1111
export const ONE_YEAR = 365 * ONE_DAY;
12+
export const POLYGON_AVERAGE_BLOCK_TIME = 2.2;

test/shared/Governance.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Signer} from 'ethers';
22
import {ethers} from 'hardhat';
33
import {impersonateAccountWithFunds, stopImpersonateAccount} from '../shared/AccountManipulation';
44
import {increaseNextBlockTime, setNextBlockNumber} from '../shared/TimeManipulation';
5+
import {POLYGON_AVERAGE_BLOCK_TIME} from './Constants';
56
import {DeployedContracts} from './Forking';
67

78
export const createAndExecuteProposal = async ({
@@ -18,17 +19,17 @@ export const createAndExecuteProposal = async ({
1819
values: string[];
1920
calldatas: string[];
2021
} & DeployedContracts) => {
21-
// we need address with min. proposalThreshold tokens to propose
22-
// 1. borrow some treasury tokens to user
23-
const quorumAmount = await governor.quorumVotes();
24-
// careful, this sends ETH to timelock which might break real-world simulation for proposals involving Timelock ETH
22+
// 0. set voting delay & duration to 2 blocks, otherwise need to simulate 302,400 blocks
2523
const timeLockSigner = await impersonateAccountWithFunds(timeLock.address);
26-
await arenaToken.connect(timeLockSigner).transfer(await user.getAddress(), quorumAmount);
27-
// set voting delay & duration to 2 blocks, otherwise need to simulate 302,400 blocks
24+
let originalVotingDelay = await governor.votingDelay();
25+
let originalVotingPeriod = await governor.votingPeriod();
2826
await governor.connect(timeLockSigner).setVotingDelay(`2`);
2927
await governor.connect(timeLockSigner).setVotingPeriod(`2`);
30-
await stopImpersonateAccount(timeLock.address);
3128

29+
// 1. borrow some treasury tokens to user as we need signer with min. proposalThreshold tokens to propose
30+
const quorumAmount = await governor.quorumVotes();
31+
// careful, this sends ETH to timelock which might break real-world simulation for proposals involving Timelock ETH
32+
await arenaToken.connect(timeLockSigner).transfer(await user.getAddress(), quorumAmount);
3233
await arenaToken.connect(user).delegate(await user.getAddress());
3334
const descriptionHash = ethers.utils.keccak256([]); // keccak(``)
3435
let tx = await governor.connect(user)['propose(address[],uint256[],bytes[],string)'](targets, values, calldatas, ``);
@@ -38,6 +39,8 @@ export const createAndExecuteProposal = async ({
3839

3940
// 2. advance time past voting delay and vote on proposal
4041
const voteStartBlock = await governor.proposalSnapshot(proposalId);
42+
// simulate elapsed time close to original voting delay
43+
await increaseNextBlockTime(Math.floor(POLYGON_AVERAGE_BLOCK_TIME * originalVotingDelay.toNumber()));
4144
await setNextBlockNumber(voteStartBlock.toNumber() + 1); // is a blocknumber which fits in Number
4245
tx = await governor.connect(user)['castVote'](proposalId, `1`);
4346

@@ -46,12 +49,19 @@ export const createAndExecuteProposal = async ({
4649

4750
// 4. advance time past voting period and queue proposal calls to Timelock via GovernorTimelockControl.queue
4851
const voteEndBlock = await governor.proposalDeadline(proposalId);
52+
// simulate elapsed time close to original voting delay
53+
await increaseNextBlockTime(Math.floor(POLYGON_AVERAGE_BLOCK_TIME * originalVotingPeriod.toNumber()));
4954
await setNextBlockNumber(voteEndBlock.toNumber() + 1); // is a blocknumber which fits in Number
5055
tx = await governor
5156
.connect(user)
5257
['queue(address[],uint256[],bytes[],bytes32)'](targets, values, calldatas, descriptionHash);
5358
await tx.wait();
5459

60+
// can revert Governor changes now
61+
await governor.connect(timeLockSigner).setVotingDelay(originalVotingDelay);
62+
await governor.connect(timeLockSigner).setVotingPeriod(originalVotingPeriod);
63+
await stopImpersonateAccount(timeLock.address);
64+
5565
// 5. advance time past timelock delay and then execute
5666
const timeLockMinDelaySeconds = await timeLock.getMinDelay();
5767
await increaseNextBlockTime(timeLockMinDelaySeconds.toNumber());

0 commit comments

Comments
 (0)