import { EthereumGlobal , NodeEthereumResponse } from "../../src/types" ; export default class EthereumMock implements EthereumGlobal { responseCallbacks : undefined ; notificationCallbacks : undefined ; connection : undefined ; addDefaultEvents : undefined ; networkVersion : string = "" ; selectedAddress : string = "" ; isMetaMask ? : boolean = false ; host ? : string ; path ? : string ; token ? : string ; constructor ( private readonly events = { } ) { } async enable ( ) { this . selectedAddress = "0x0" ; } on ( type , callback ) { this . events [ type ] = [ ... ( this . events [ type ] || [ ] ) , callback ] ; return ; } removeListener ( type , callback ) { this . events [ type ] = ( this . events [ type ] || [ ] ) . filter ( cb => cb === callback ) ; return ; } removeAllListeners ( type ) { this . events [ type ] = [ ] ; return ; } reset ( ) { return ; } async send ( eventOrMethod ) { if ( eventOrMethod === "counterfactual:nodeProvider:event" ) { return new Promise ( resolve => { function relayMessageToDapp ( event ) { return resolve ( event ) ; } this . on ( eventOrMethod , event => relayMessageToDapp ( event ) ) ; } ) ; } return { jsonrpc : "2.0" , result : { } } as NodeEthereumResponse ; } }