import "module-alias/register" ; import { utils , BigNumber } from "ethers" ; import { Address , Bytes } from "@utils/types" ; import { Account } from "@utils/test/types" ; import { ADDRESS_ZERO , EMPTY_BYTES , ONE_DAY_IN_SECONDS , ZERO } from "@utils/constants" ; import { AaveGovernanceAdapter , SetToken , GovernanceModule } from "@utils/contracts" ; import DeployHelper from "@utils/deploys" ; import { ether , } from "@utils/index" ; import { addSnapshotBeforeRestoreAfterEach , getAccounts , getWaffleExpect , getSystemFixture , getAaveFixture , getRandomAddress , increaseTimeAsync , } from "@utils/test/index" ; import { AaveFixture , SystemFixture } from "@utils/fixtures" ; const expect = getWaffleExpect ( ) ; describe ( "AaveGovernanceModule" , ( ) => { let owner ; let deployer ; let setup ; let aaveSetup ; let governanceModule ; let aaveGovernanceAdapter ; const aaveGovernanceAdapterIntegrationName = "AAVE" ; before ( async ( ) => { [ owner , ] = await getAccounts ( ) ; deployer = new DeployHelper ( owner . wallet ) ; setup = getSystemFixture ( owner . address ) ; await setup . initialize ( ) ; aaveSetup = getAaveFixture ( owner . address ) ; await aaveSetup . initialize ( ) ; governanceModule = await deployer . modules . deployGovernanceModule ( setup . controller . address ) ; await setup . controller . addModule ( governanceModule . address ) ; aaveGovernanceAdapter = await deployer . adapters . deployAaveGovernanceAdapter ( aaveSetup . aaveProtoGovernance . address , aaveSetup . aaveToken . address ) ; await setup . integrationRegistry . addIntegration ( governanceModule . address , aaveGovernanceAdapterIntegrationName , aaveGovernanceAdapter . address ) ; } ) ; addSnapshotBeforeRestoreAfterEach ( ) ; context ( "when a SetToken has been deployed and issued" , async ( ) => { let setToken ; let setTokensIssued ; let componentUnits ; before ( async ( ) => { componentUnits = [ ether ( 1000 ) , ether ( 100 ) ] ; setToken = await setup . createSetToken ( [ aaveSetup . aaveToken . address , aaveSetup . lendToken . address ] , componentUnits , [ setup . issuanceModule . address , governanceModule . address ] ) ; await setup . issuanceModule . initialize ( setToken . address , ADDRESS_ZERO ) ; await governanceModule . initialize ( setToken . address ) ; setTokensIssued = ether ( 1 ) ; await aaveSetup . aaveToken . approve ( setup . issuanceModule . address , componentUnits [ 0 ] ) ; await aaveSetup . lendToken . approve ( setup . issuanceModule . address , componentUnits [ 1 ] ) ; await setup . issuanceModule . issue ( setToken . address , setTokensIssued , owner . address ) ; } ) ; describe ( "#vote" , async ( ) => { let subjectSetToken ; let subjectProposalId ; let subjectSupport ; let subjectData ; let subjectIntegrationName ; let subjectCaller ; beforeEach ( async ( ) => { await aaveSetup . aaveProtoGovernance . newProposal ( utils . keccak256 ( new Buffer ( "ProposalOne" ) ) , utils . keccak256 ( new Buffer ( "RandomIPFSHash" ) ) , ether ( 13000000 ) , await getRandomAddress ( ) , 1660 , 1660 , 5 ) ; const proposalReviewPeriod = ONE_DAY_IN_SECONDS ; await increaseTimeAsync ( proposalReviewPeriod ) ; subjectSetToken = setToken . address ; subjectIntegrationName = aaveGovernanceAdapterIntegrationName ; subjectProposalId = ZERO ; subjectSupport = true ; subjectData = EMPTY_BYTES ; subjectCaller = owner ; } ) ; async function subject ( ) { return governanceModule . connect ( subjectCaller . wallet ) . vote ( subjectSetToken , subjectIntegrationName , subjectProposalId , subjectSupport , subjectData ) ; } it ( "should vote in Aave" , async ( ) => { await subject ( ) ; const votesData = await aaveSetup . aaveProtoGovernance . getVotesData ( ZERO ) ; expect ( votesData [ 0 ] ) . to . eq ( ZERO ) ; expect ( votesData [ 1 ] ) . to . eq ( componentUnits [ 0 ] ) ; expect ( votesData [ 2 ] ) . to . eq ( ZERO ) ; } ) ; describe ( "when voting with another supported token" , ( ) => { beforeEach ( async ( ) => { subjectData = utils . defaultAbiCoder . encode ( [ "address" ] , [ aaveSetup . lendToken . address ] ) ; } ) ; it ( "should vote with LEND token" , async ( ) => { await subject ( ) ; const votesData = await aaveSetup . aaveProtoGovernance . getVotesData ( ZERO ) ; expect ( votesData [ 0 ] ) . to . eq ( ZERO ) ; expect ( votesData [ 1 ] ) . to . eq ( componentUnits [ 1 ] ) ; expect ( votesData [ 2 ] ) . to . eq ( ZERO ) ; } ) ; } ) ; describe ( "when voting against a proposal" , ( ) => { beforeEach ( async ( ) => { subjectSupport = false ; } ) ; it ( "should vote false" , async ( ) => { await subject ( ) ; const votesData = await aaveSetup . aaveProtoGovernance . getVotesData ( ZERO ) ; expect ( votesData [ 0 ] ) . to . eq ( ZERO ) ; expect ( votesData [ 1 ] ) . to . eq ( ZERO ) ; expect ( votesData [ 2 ] ) . to . eq ( componentUnits [ 0 ] ) ; } ) ; } ) ; } ) ; } ) ; } ) ;