2021-08-11 17:04:24 +02:00
const { expect } = require ( 'chai' )
2021-08-23 11:59:28 +02:00
const { ethers } = require ( 'hardhat' )
const { utils } = ethers
2021-08-11 17:04:24 +02:00
2021-08-23 11:59:28 +02:00
const { getSignerFromAddress , advanceTime } = require ( './utils' )
2021-08-11 17:04:24 +02:00
2021-08-23 11:59:28 +02:00
describe ( 'Proposal' , function ( ) {
this . timeout ( 200000 )
const tornAddress = '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C'
const governanceAddress = '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce'
const eip2470Address = '0xCEe71753C9820f063b38FDbE4cFDAf1d3D928A80'
const relayerRegistryImpl = '0xE9c171C583115282fe1ed6e93E7b1b8aE758Ed51'
const SALT = '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
let proposal , tornWhale , governance , torn , relayerRegistry , tornadoProxyV3
/* prettier-ignore */
before ( async function ( ) {
governance = await ethers . getContractAt ( require ( './abi/governance.json' ) , governanceAddress )
const VOTING _DELAY = ( await governance . VOTING _DELAY ( ) ) . toNumber ( )
const VOTING _PERIOD = ( await governance . VOTING _PERIOD ( ) ) . toNumber ( )
const EXECUTION _DELAY = ( await governance . EXECUTION _DELAY ( ) ) . toNumber ( )
torn = await ethers . getContractAt ( require ( './abi/torn.json' ) , tornAddress )
tornWhale = await getSignerFromAddress ( '0xF977814e90dA44bFA03b6295A0616a897441aceC' )
const Proposal = await ethers . getContractFactory ( 'Proposal' )
proposal = await Proposal . deploy ( )
expect ( await proposal . isContract ( '0xE9c171C583115282fe1ed6e93E7b1b8aE758Ed51' ) ) . to . be . false
const eip2770 = await ethers . getVerifiedContractAt ( eip2470Address )
2021-08-11 17:04:24 +02:00
const RelayerRegistry = await ethers . getContractFactory ( 'RelayerRegistry' )
2021-08-23 11:59:28 +02:00
const receipt = await eip2770 . deploy ( RelayerRegistry . bytecode , SALT )
const receiptEvents = await receipt . wait ( )
expect ( relayerRegistryImpl ) . to . be . equal ( receiptEvents . events [ 0 ] . args . addr ) // this address will be different if you change the Relayer Registry contract
expect ( await proposal . isContract ( relayerRegistryImpl ) ) . to . be . true
torn = torn . connect ( tornWhale )
governance = governance . connect ( tornWhale )
await torn . approve ( governance . address , utils . parseEther ( '25000' ) )
await governance . lockWithApproval ( utils . parseEther ( '25000' ) )
await governance . propose ( proposal . address , 'Relayer registry' )
const proposalId = await governance . proposalCount ( )
await advanceTime ( VOTING _DELAY + 1 )
await governance . castVote ( proposalId , true )
await advanceTime ( VOTING _PERIOD + EXECUTION _DELAY )
const executeReceipt = await governance . execute ( proposalId )
const { events , gasUsed } = await executeReceipt . wait ( )
console . log ( 'Proposal execution took' , gasUsed . toNumber ( ) )
2021-08-11 17:04:24 +02:00
2021-08-23 11:59:28 +02:00
// eslint-disable-next-line no-unused-vars
let [ registryProxyAddr , tornadoProxyV3Addr ] = events
. filter ( e => e . topics [ 0 ] === '0x06633ee22fe8e793dec66ce36696e948bb0cc0d018ab361e8dfeb34151a4d466' )
. map ( ( e ) => ethers . utils . getAddress ( '0x' + e . data . slice ( 90 , 130 ) ) )
relayerRegistry = RelayerRegistry . attach ( registryProxyAddr )
const TornadoProxyV3 = await ethers . getContractFactory ( 'TornadoProxyV3' )
tornadoProxyV3 = TornadoProxyV3 . attach ( tornadoProxyV3Addr )
} )
it ( 'constructors' , async function ( ) {
expect ( await relayerRegistry . withdrawalProxy ( ) ) . to . equal ( tornadoProxyV3 . address )
const RelayerRegistry = await ethers . getContractFactory ( 'RelayerRegistry' )
const relayerRegistryImplementation = RelayerRegistry . attach ( relayerRegistryImpl )
expect ( await relayerRegistryImplementation . withdrawalProxy ( ) ) . to . equal (
'0x0000000000000000000000000000000000000000' ,
)
2021-08-11 17:04:24 +02:00
} )
} )