import { CreateChannelParams , Allocation , CloseChannelParams , } from '@statechannels/client-api-schema' ; import { BigNumber , ethers , constants } from 'ethers' ; import { ONE_DAY } from '../../__test__/test-helpers' ; import { setupPeerEngines , teardownPeerSetup , PeerSetup , } from '../../../jest/with-peers-setup-teardown' ; import { expectLatestStateToMatch } from '../utils' ; import { getMessages } from '../../message-service/utils' ; let channelId ; let peerSetup ; beforeAll ( async ( ) => { peerSetup = await setupPeerEngines ( ) ; } ) ; afterAll ( async ( ) => { await teardownPeerSetup ( peerSetup ) ; } ) ; it ( 'Create a fake-funded channel between two engines ' , async ( ) => { const aBal = BigNumber . from ( 1 ) . toHexString ( ) ; const { participantA , participantB , peerEngines , messageService } = peerSetup ; const allocation = { allocationItems : [ { destination : participantA . destination , amount : aBal } ] , asset : constants . AddressZero , } ; const channelParams = { participants : [ participantA , participantB ] , allocations : [ allocation ] , appDefinition : ethers . constants . AddressZero , appData : '0x00' , fundingStrategy : 'Fake' , challengeDuration : ONE_DAY , } ; const aCreateChannelOutput = await peerEngines . a . createChannel ( channelParams ) ; await messageService . send ( getMessages ( aCreateChannelOutput ) ) ; channelId = aCreateChannelOutput . channelResult . channelId ; expectLatestStateToMatch ( channelId , peerEngines . a , { status : 'opening' , turnNum : 0 , } ) ; await expectLatestStateToMatch ( channelId , peerEngines . b , { status : 'proposed' , turnNum : 0 , } ) ; const bJoinChannelOutput = await peerEngines . b . joinChannel ( { channelId } ) ; await messageService . send ( getMessages ( bJoinChannelOutput ) ) ; await expectLatestStateToMatch ( channelId , peerEngines . a , { status : 'running' , turnNum : 3 , } ) ; await expectLatestStateToMatch ( channelId , peerEngines . b , { status : 'running' , turnNum : 3 , } ) ; const closeChannelParams = { channelId , } ; const aCloseChannelResult = await peerEngines . a . closeChannel ( closeChannelParams ) ; await messageService . send ( getMessages ( aCloseChannelResult ) ) ; await expectLatestStateToMatch ( channelId , peerEngines . b , { status : 'closed' , turnNum : 4 , } ) ; await expectLatestStateToMatch ( channelId , peerEngines . b , { status : 'closed' , turnNum : 4 , } ) ; } ) ;