import { newKitFromWeb3 } from '@celo/contractkit' ; import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold' ; import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' ; import { getContractFromEvent , testWithGanache } from '@celo/dev-utils/lib/ganache-test' ; import Web3 from 'web3' ; import SetBeneficiary from './set-beneficiary' ; process . env . NO_SYNCCHECK = 'true' ; testWithGanache ( 'releasegold:set-beneficiary cmd' , ( web3 ) => { let contractAddress ; let kit ; let releaseGoldWrapper ; let releaseGoldMultiSig ; let releaseOwner ; let beneficiary ; let newBeneficiary ; let otherAccount ; beforeEach ( async ( ) => { const accounts = await web3 . eth . getAccounts ( ) ; releaseOwner = accounts [ 0 ] ; newBeneficiary = accounts [ 2 ] ; otherAccount = accounts [ 3 ] ; contractAddress = await getContractFromEvent ( 'ReleaseGoldInstanceCreated(address,address)' , web3 , { index : 1 } ) ; kit = newKitFromWeb3 ( web3 ) ; releaseGoldWrapper = new ReleaseGoldWrapper ( kit , newReleaseGold ( web3 , contractAddress ) ) ; beneficiary = await releaseGoldWrapper . getBeneficiary ( ) ; const owner = await releaseGoldWrapper . getOwner ( ) ; releaseGoldMultiSig = await kit . contracts . getMultiSig ( owner ) ; } ) ; test ( 'can change beneficiary' , async ( ) => { await SetBeneficiary . run ( [ '--contract' , contractAddress , '--from' , releaseOwner , '--beneficiary' , newBeneficiary , '--yesreally' , ] ) ; expect ( await releaseGoldWrapper . getBeneficiary ( ) ) . toEqual ( beneficiary ) ; await SetBeneficiary . run ( [ '--contract' , contractAddress , '--from' , beneficiary , '--beneficiary' , newBeneficiary , '--yesreally' , ] ) ; expect ( await releaseGoldWrapper . getBeneficiary ( ) ) . toEqual ( newBeneficiary ) ; expect ( await releaseGoldMultiSig . getOwners ( ) ) . toEqual ( [ releaseOwner , newBeneficiary ] ) ; } ) ; test ( 'if called by a different account, it should fail' , async ( ) => { await expect ( SetBeneficiary . run ( [ '--contract' , contractAddress , '--from' , otherAccount , '--beneficiary' , newBeneficiary , '--yesreally' , ] ) ) . rejects . toThrow ( ) ; } ) ; test ( 'if the owners submit different txs, nothing on the ReleaseGold contract should change' , async ( ) => { await SetBeneficiary . run ( [ '--contract' , contractAddress , '--from' , releaseOwner , '--beneficiary' , newBeneficiary , '--yesreally' , ] ) ; await SetBeneficiary . run ( [ '--contract' , contractAddress , '--from' , beneficiary , '--beneficiary' , otherAccount , '--yesreally' , ] ) ; expect ( await releaseGoldWrapper . getBeneficiary ( ) ) . toEqual ( beneficiary ) ; expect ( await releaseGoldMultiSig . getOwners ( ) ) . toEqual ( [ releaseOwner , beneficiary ] ) ; } ) ; } ) ;