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: string, engine: Engine, partial: Partial ): Promise { const latest = await engine.getState({channelId}); expect(latest.channelResult).toMatchObject(partial); } export function getWithPeersCreateChannelsArgs( peerSetup: PeerSetup ): CreateChannelParams & {fundingStrategy: 'Fake'} { return { ...createChannelArgs({ participants: [peerSetup.participantA, peerSetup.participantB], }), fundingStrategy: 'Fake', }; } export function waitForObjectiveProposals(objectiveIds: string[], wallet: Wallet): Promise { const handledObjectiveIds = new Set(); return new Promise(resolve => { const listener = (o: WalletObjective) => { if (objectiveIds.includes(o.objectiveId)) { handledObjectiveIds.add(o.objectiveId); if (handledObjectiveIds.size === _.uniq(objectiveIds).length) { resolve(); } } }; wallet.on('ObjectiveProposed', listener); }); }