import { ChannelResult , CreateChannelParams } from '@statechannels/client-api-schema' ; import _ from 'lodash' ; import { Engine , Wallet } from '..' ; import { PeerSetup } from '../../jest/with-peers-setup-teardown' ; import { createChannelArgs } from '../engine/__test__/fixtures/create-channel' ; import { WalletObjective } from '../models/objective' ; export async function expectLatestStateToMatch ( channelId , engine , partial ) { const latest = await engine . getState ( { channelId } ) ; expect ( latest . channelResult ) . toMatchObject ( partial ) ; } export function getWithPeersCreateChannelsArgs ( peerSetup ) { return { ... createChannelArgs ( { participants : [ peerSetup . participantA , peerSetup . participantB ] , } ) , fundingStrategy : 'Fake' , } ; } export function waitForObjectiveProposals ( objectiveIds , wallet ) { const handledObjectiveIds = new Set < string > ( ) ; return new Promise < void > ( resolve => { const listener = ( o ) => { if ( objectiveIds . includes ( o . objectiveId ) ) { handledObjectiveIds . add ( o . objectiveId ) ; if ( handledObjectiveIds . size === _ . uniq ( objectiveIds ) . length ) { resolve ( ) ; } } } ; wallet . on ( 'ObjectiveProposed' , listener ) ; } ) ; }