@@ -2,6 +2,7 @@ import {Signer} from 'ethers';
2
2
import { ethers } from 'hardhat' ;
3
3
import { impersonateAccountWithFunds , stopImpersonateAccount } from '../shared/AccountManipulation' ;
4
4
import { increaseNextBlockTime , setNextBlockNumber } from '../shared/TimeManipulation' ;
5
+ import { POLYGON_AVERAGE_BLOCK_TIME } from './Constants' ;
5
6
import { DeployedContracts } from './Forking' ;
6
7
7
8
export const createAndExecuteProposal = async ( {
@@ -18,17 +19,17 @@ export const createAndExecuteProposal = async ({
18
19
values : string [ ] ;
19
20
calldatas : string [ ] ;
20
21
} & 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
25
23
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 ( ) ;
28
26
await governor . connect ( timeLockSigner ) . setVotingDelay ( `2` ) ;
29
27
await governor . connect ( timeLockSigner ) . setVotingPeriod ( `2` ) ;
30
- await stopImpersonateAccount ( timeLock . address ) ;
31
28
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 ) ;
32
33
await arenaToken . connect ( user ) . delegate ( await user . getAddress ( ) ) ;
33
34
const descriptionHash = ethers . utils . keccak256 ( [ ] ) ; // keccak(``)
34
35
let tx = await governor . connect ( user ) [ 'propose(address[],uint256[],bytes[],string)' ] ( targets , values , calldatas , `` ) ;
@@ -38,6 +39,8 @@ export const createAndExecuteProposal = async ({
38
39
39
40
// 2. advance time past voting delay and vote on proposal
40
41
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 ( ) ) ) ;
41
44
await setNextBlockNumber ( voteStartBlock . toNumber ( ) + 1 ) ; // is a blocknumber which fits in Number
42
45
tx = await governor . connect ( user ) [ 'castVote' ] ( proposalId , `1` ) ;
43
46
@@ -46,12 +49,19 @@ export const createAndExecuteProposal = async ({
46
49
47
50
// 4. advance time past voting period and queue proposal calls to Timelock via GovernorTimelockControl.queue
48
51
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 ( ) ) ) ;
49
54
await setNextBlockNumber ( voteEndBlock . toNumber ( ) + 1 ) ; // is a blocknumber which fits in Number
50
55
tx = await governor
51
56
. connect ( user )
52
57
[ 'queue(address[],uint256[],bytes[],bytes32)' ] ( targets , values , calldatas , descriptionHash ) ;
53
58
await tx . wait ( ) ;
54
59
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
+
55
65
// 5. advance time past timelock delay and then execute
56
66
const timeLockMinDelaySeconds = await timeLock . getMinDelay ( ) ;
57
67
await increaseNextBlockTime ( timeLockMinDelaySeconds . toNumber ( ) ) ;
0 commit comments