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 , ZERO } from "@utils/constants" ; import { CompoundBravoGovernanceAdapter } from "@utils/contracts" ; import DeployHelper from "@utils/deploys" ; import { addSnapshotBeforeRestoreAfterEach , getAccounts , getWaffleExpect , getCompoundFixture , getRandomAddress } from "@utils/test/index" ; import { CompoundFixture } from "@utils/fixtures" ; const expect = getWaffleExpect ( ) ; describe ( "CompoundBravoGovernanceAdapter" , ( ) => { let owner ; let deployer ; let compoundBravoGovernanceAdapter ; let targetAddressOne ; let targetAddressTwo ; let mockSetToken ; let compoundSetup ; before ( async ( ) => { [ owner , targetAddressOne , targetAddressTwo , mockSetToken , ] = await getAccounts ( ) ; deployer = new DeployHelper ( owner . wallet ) ; compoundSetup = getCompoundFixture ( owner . address ) ; await compoundSetup . initialize ( ) ; await compoundSetup . initializeGovernorBravo ( ) ; compoundBravoGovernanceAdapter = await deployer . adapters . deployCompoundBravoGovernanceAdapter ( compoundSetup . compoundGovernorBravoDelegator . address , compoundSetup . comp . address ) ; } ) ; addSnapshotBeforeRestoreAfterEach ( ) ; describe ( "#constructor" , async ( ) => { let subjectCompToken ; let subjectGovernorBravo ; beforeEach ( async ( ) => { subjectCompToken = compoundSetup . comp . address ; subjectGovernorBravo = compoundSetup . compoundGovernorBravoDelegator . address ; } ) ; async function subject ( ) { return deployer . adapters . deployCompoundBravoGovernanceAdapter ( subjectGovernorBravo , subjectCompToken ) ; } it ( "should have the correct COMP token address" , async ( ) => { const deployedCompoundLikeGovernanceAdapter = await subject ( ) ; const actualCompToken = await deployedCompoundLikeGovernanceAdapter . governanceToken ( ) ; expect ( actualCompToken ) . to . eq ( subjectCompToken ) ; } ) ; it ( "should have the correct governor bravo contract address" , async ( ) => { const deployedCompoundBravoGovernanceAdapter = await subject ( ) ; const actualGovernorBravoAddress = await deployedCompoundBravoGovernanceAdapter . governorBravo ( ) ; expect ( actualGovernorBravoAddress ) . to . eq ( subjectGovernorBravo ) ; } ) ; } ) ; describe ( "#getProposeCalldata" , async ( ) => { let targets ; let values ; let signatures ; let calldatas ; let description ; let subjectProposalData ; beforeEach ( async ( ) => { targets = [ targetAddressOne . address , targetAddressTwo . address ] ; values = [ ZERO , ZERO ] ; signatures = [ "_supportMarket(address)" , "_setReserveFactor(uint256)" ] ; calldatas = [ "0x00000000000000000000000070e36f6bf80a52b3b46b3af8e106cc0ed743e8e4" , "0x00000000000000000000000000000000000000000000000002c68af0bb140000" , ] ; description = "Create A Proposal" ; subjectProposalData = utils . defaultAbiCoder . encode ( [ "address[]" , "uint256[]" , "string[]" , "bytes[]" , "string" ] , [ targets , values , signatures , calldatas , description ] ) ; } ) ; async function subject ( ) { return compoundBravoGovernanceAdapter . getProposeCalldata ( subjectProposalData ) ; } it ( "should return correct data for creating a proposal" , async ( ) => { const [ targetAddress , ethValue , callData ] = await subject ( ) ; const expectedCallData = compoundSetup . compoundGovernorBravoDelegate . interface . encodeFunctionData ( "propose" , [ targets , values , signatures , calldatas , description ] ) ; expect ( targetAddress ) . to . eq ( compoundSetup . compoundGovernorBravoDelegator . address ) ; expect ( ethValue ) . to . eq ( ZERO ) ; expect ( callData ) . to . eq ( expectedCallData ) ; } ) ; } ) ; describe ( "#getDelegateCalldata" , async ( ) => { let subjectDelegatee ; beforeEach ( async ( ) => { subjectDelegatee = await getRandomAddress ( ) ; } ) ; async function subject ( ) { return compoundBravoGovernanceAdapter . getDelegateCalldata ( subjectDelegatee ) ; } it ( "should return correct data for delegating" , async ( ) => { const [ targetAddress , ethValue , callData ] = await subject ( ) ; const expectedCallData = compoundSetup . comp . interface . encodeFunctionData ( "delegate" , [ subjectDelegatee ] ) ; expect ( targetAddress ) . to . eq ( compoundSetup . comp . address ) ; expect ( ethValue ) . to . eq ( ZERO ) ; expect ( callData ) . to . eq ( expectedCallData ) ; } ) ; } ) ; describe ( "#getRegisterCalldata" , async ( ) => { let subjectSetToken ; beforeEach ( async ( ) => { subjectSetToken = mockSetToken . address ; } ) ; async function subject ( ) { return compoundBravoGovernanceAdapter . getRegisterCalldata ( subjectSetToken ) ; } it ( "should return correct data for registering" , async ( ) => { const [ targetAddress , ethValue , callData ] = await subject ( ) ; const expectedCallData = compoundSetup . comp . interface . encodeFunctionData ( "delegate" , [ mockSetToken . address ] ) ; expect ( targetAddress ) . to . eq ( compoundSetup . comp . address ) ; expect ( ethValue ) . to . eq ( ZERO ) ; expect ( callData ) . to . eq ( expectedCallData ) ; } ) ; } ) ; describe ( "#getRevokeCalldata" , async ( ) => { async function subject ( ) { return compoundBravoGovernanceAdapter . getRevokeCalldata ( ) ; } it ( "should return correct data for revoking" , async ( ) => { const [ targetAddress , ethValue , callData ] = await subject ( ) ; const expectedCallData = compoundSetup . comp . interface . encodeFunctionData ( "delegate" , [ ADDRESS_ZERO ] ) ; expect ( targetAddress ) . to . eq ( compoundSetup . comp . address ) ; expect ( ethValue ) . to . eq ( ZERO ) ; expect ( callData ) . to . eq ( expectedCallData ) ; } ) ; } ) ; describe ( "#getVoteCalldata" , async ( ) => { let subjectProposalId ; let subjectSupport ; let subjectData ; beforeEach ( async ( ) => { subjectProposalId = ZERO ; subjectSupport = true ; subjectData = EMPTY_BYTES ; } ) ; async function subject ( ) { return compoundBravoGovernanceAdapter . getVoteCalldata ( subjectProposalId , subjectSupport , subjectData ) ; } it ( "should return correct data for voting on a proposal" , async ( ) => { const [ targetAddress , ethValue , callData ] = await subject ( ) ; const expectedCallData = compoundSetup . compoundGovernorBravoDelegate . interface . encodeFunctionData ( "castVote" , [ subjectProposalId , subjectSupport ? 1 : 0 ] ) ; expect ( targetAddress ) . to . eq ( compoundSetup . compoundGovernorBravoDelegator . address ) ; expect ( ethValue ) . to . eq ( ZERO ) ; expect ( callData ) . to . eq ( expectedCallData ) ; } ) ; } ) ; } ) ;