import { ContractKit , newKitFromWeb3 } from '@celo/contractkit' ; import { getContractFromEvent , testWithGanache } from '@celo/dev-utils/lib/ganache-test' ; import Web3 from 'web3' ; import Register from '../account/register' ; import TransferDollars from '../transfer/dollars' ; import CreateAccount from './create-account' ; import RGTransferDollars from './transfer-dollars' ; process . env . NO_SYNCCHECK = 'true' ; jest . setTimeout ( 15000 ) ; testWithGanache ( 'releasegold:transfer-dollars cmd' , ( web3 ) => { let accounts = [ ] ; let contractAddress ; let kit ; beforeEach ( async ( ) => { contractAddress = await getContractFromEvent ( 'ReleaseGoldInstanceCreated(address,address)' , web3 , { index : 1 } ) ; kit = newKitFromWeb3 ( web3 ) ; accounts = await web3 . eth . getAccounts ( ) ; await Register . run ( [ '--from' , accounts [ 0 ] ] ) ; await CreateAccount . run ( [ '--contract' , contractAddress ] ) ; } ) ; test ( 'can transfer dollars out of the ReleaseGold contract' , async ( ) => { const balanceBefore = await kit . getTotalBalance ( accounts [ 0 ] ) ; const cUSDToTransfer = '500000000000000000000' ; await TransferDollars . run ( [ '--from' , accounts [ 0 ] , '--to' , contractAddress , '--value' , cUSDToTransfer , ] ) ; const contractBalance = await kit . getTotalBalance ( contractAddress ) ; expect ( contractBalance . cUSD ! . toFixed ( ) ) . toEqual ( cUSDToTransfer ) ; await RGTransferDollars . run ( [ '--contract' , contractAddress , '--to' , accounts [ 0 ] , '--value' , cUSDToTransfer , ] ) ; const balanceAfter = await kit . getTotalBalance ( accounts [ 0 ] ) ; expect ( balanceBefore . cUSD ) . toEqual ( balanceAfter . cUSD ) ; } ) ; test ( 'should fail if contract has no celo dollars' , async ( ) => { await expect ( RGTransferDollars . run ( [ '--contract' , contractAddress , '--to' , accounts [ 0 ] , '--value' , '1' ] ) ) . rejects . toThrow ( ) ; } ) ; } ) ;