import { NetworkContextForTestSuite } from "@counterfactual/local-ganache-server" ; import { One } from "ethers/constants" ; import { parseEther } from "ethers/utils" ; import { Node } from "../../src" ; import { CONVENTION_FOR_ETH_TOKEN_ADDRESS } from "../../src/constants" ; import { NODE_EVENTS , ProposeMessage } from "../../src/types" ; import { toBeLt } from "../engine/integration/bignumber-jest-matcher" ; import { setup , SetupContext } from "./setup" ; import { collateralizeChannel , createChannel , makeInstallCall , makeProposeCall } from "./utils" ; expect . extend ( { toBeLt } ) ; jest . setTimeout ( 7500 ) ; const { TicTacToeApp } = global [ "networkContext" ] as NetworkContextForTestSuite ; describe ( "Node method follows spec - install" , ( ) => { let multisigAddress ; let nodeA ; let nodeB ; describe ( "Node A gets app install proposal, sends to node B, B approves it, installs it, " + "sends acks back to A, A installs it, both nodes have the same app instance" , ( ) => { beforeEach ( async ( ) => { const context = await setup ( global ) ; nodeA = context [ "A" ] . node ; nodeB = context [ "B" ] . node ; multisigAddress = await createChannel ( nodeA , nodeB ) ; await collateralizeChannel ( multisigAddress , nodeA , nodeB , parseEther ( "2" ) ) ; } ) ; it ( "install app with ETH" , done => { let completedInstalls = 0 ; nodeB . on ( NODE_EVENTS . PROPOSE_INSTALL , ( msg ) => { makeInstallCall ( nodeB , msg . data . appInstanceId ) ; } ) ; nodeA . on ( NODE_EVENTS . INSTALL , ( ) => { completedInstalls += 1 ; if ( completedInstalls === 2 ) { done ( ) ; } } ) ; const rpc = makeProposeCall ( nodeB , TicTacToeApp , undefined , One , CONVENTION_FOR_ETH_TOKEN_ADDRESS , One , CONVENTION_FOR_ETH_TOKEN_ADDRESS ) ; nodeA . rpcRouter . dispatch ( rpc ) ; nodeA . rpcRouter . dispatch ( rpc ) ; } ) ; } ) ; } ) ;