import { providers , constants } from 'ethers' ; import { Address , PrivateKey , SignedState , State , unreachable } from '@statechannels/wallet-core' ; import { Bytes32 } from '../type-aliases' ; import { ChainEventSubscriberInterface , ChainRequest , ChainServiceInterface , FundChannelArg , } from './' ; const mockTransactionReceipt = { to : '' , from : '' , contractAddress : '' , transactionIndex : 0 , gasUsed : constants . Zero , logsBloom : '' , blockHash : '' , transactionHash : '' , logs : [ ] , blockNumber : 0 , confirmations : 0 , cumulativeGasUsed : constants . Zero , byzantium : false , } ; const mockTransactoinResponse = { hash : '' , confirmations : 0 , from : '' , wait : ( _confirmations ? ) : Promise < providers . TransactionReceipt > => Promise . resolve ( mockTransactionReceipt ) , nonce : 0 , gasLimit : constants . Zero , gasPrice : constants . Zero , data : '' , value : constants . Zero , chainId : 0 , } ; export class MockChainService implements ChainServiceInterface { public async handleChainRequests ( chainRequests ) { const responses = Array ( chainRequests . length ) ; for ( const chainRequest of chainRequests ) { switch ( chainRequest . type ) { case 'Challenge' : responses . push ( await this . challenge ( chainRequest . challengeStates , chainRequest . privateKey ) ) ; break ; case 'ConcludeAndWithdraw' : responses . push ( await this . concludeAndWithdraw ( chainRequest . finalizationProof ) ) ; break ; case 'FundChannel' : responses . push ( await this . fundChannel ( chainRequest ) ) ; break ; case 'Withdraw' : responses . push ( await this . withdraw ( chainRequest . state ) ) ; break ; default : unreachable ( chainRequest ) ; } } return responses ; } async checkChainId ( _networkChainId ) { } fundChannel ( _arg ) { return Promise . resolve ( mockTransactoinResponse ) ; } registerChannel ( _channelId , _assetHolders , _subscriber ) { return ; } unregisterChannel ( _channelId ) { return ; } concludeAndWithdraw ( _finalizationProof ) { return Promise . resolve ( mockTransactoinResponse ) ; } withdraw ( _state ) { return Promise . resolve ( mockTransactoinResponse ) ; } challenge ( _challengeStates , _privateKey ) { return Promise . resolve ( mockTransactoinResponse ) ; } async fetchBytecode ( _appDefinition ) { return '0x0' ; } destructor ( ) { return ; } } export class ErorringMockChainService extends MockChainService { withdraw ( _state ) { throw new Error ( 'Failed to submit transaction' ) ; } }