import { AppABIEncodings , OutcomeType , SolidityValueType } from "@counterfactual/types" ; import { AddressZero , Zero } from "ethers/constants" ; import { bigNumberify , getAddress , hexlify , randomBytes } from "ethers/utils" ; import { CONVENTION_FOR_ETH_TOKEN_ADDRESS } from "../../src/constants" ; import { computeRandomExtendedPrvKey } from "../../src/engine/xkeys" ; import { AppInstance , AppInstanceProposal , StateChannel } from "../../src/models" ; export function createAppInstanceProposalForTest ( appInstanceId ) { return { identityHash : appInstanceId , proposedByIdentifier : computeRandomExtendedPrvKey ( ) , proposedToIdentifier : computeRandomExtendedPrvKey ( ) , appDefinition : AddressZero , abiEncodings : { stateEncoding : "tuple(address foo, uint256 bar)" , actionEncoding : undefined } as AppABIEncodings , initiatorDeposit : "0x00" , responderDeposit : "0x00" , timeout : "0x01" , initialState : { foo : AddressZero , bar : 0 } as SolidityValueType , appSeqNo : 0 , outcomeType : OutcomeType . TWO_PARTY_FIXED_OUTCOME , initiatorDepositTokenAddress : CONVENTION_FOR_ETH_TOKEN_ADDRESS , responderDepositTokenAddress : CONVENTION_FOR_ETH_TOKEN_ADDRESS } ; } export function createAppInstanceForTest ( stateChannel ? ) { return new AppInstance ( stateChannel ? stateChannel . getSigningKeysFor ( stateChannel . numProposedApps ) : [ getAddress ( hexlify ( randomBytes ( 20 ) ) ) , getAddress ( hexlify ( randomBytes ( 20 ) ) ) ] , 0 , { addr : getAddress ( hexlify ( randomBytes ( 20 ) ) ) , stateEncoding : "tuple(address foo, uint256 bar)" , actionEncoding : undefined } , false , stateChannel ? stateChannel . numProposedApps : Math . ceil ( 1000 * Math . random ( ) ) , { foo : AddressZero , bar : bigNumberify ( 0 ) } , 0 , Math . ceil ( 1000 * Math . random ( ) ) , OutcomeType . TWO_PARTY_FIXED_OUTCOME , { playerAddrs : [ AddressZero , AddressZero ] , amount : "0x00" , tokenAddress : AddressZero } , undefined , undefined ) ; }