import { TEST_ACCOUNTS } from '@statechannels/devtools' ; import { TestContractArtifacts , randomChannelId } from '@statechannels/nitro-protocol' ; import { BN , makeAddress } from '@statechannels/wallet-core' ; import { Contract , providers , Wallet } from 'ethers' ; import _ from 'lodash' ; import { ChainService } from '../chain-service' ; const pk = TEST_ACCOUNTS [ 0 ] . privateKey ; const erc20Address = makeAddress ( process . env . ERC20_ADDRESS ! ) ; if ( ! process . env . RPC_ENDPOINT ) throw new Error ( 'RPC_ENDPOINT must be defined' ) ; const rpcEndpoint = process . env . RPC_ENDPOINT ; const provider = new providers . JsonRpcProvider ( rpcEndpoint ) ; const ethWalletWithTokens = new Wallet ( pk , provider ) ; const privateKey = TEST_ACCOUNTS [ 3 ] . privateKey ; const ethWallet = new Wallet ( privateKey , provider ) ; let chainService ; beforeEach ( ( ) => { chainService = new ChainService ( { provider : rpcEndpoint , pk : privateKey , allowanceMode : 'MaxUint' , } ) ; } ) ; afterEach ( ( ) => chainService . destructor ( ) ) ; const iterations = 100 ; describe ( 'fundChannel' , ( ) => { it . skip ( `${ iterations } simultaneous deposits` , async ( ) => { const depositAmount = 5 ; const totalTransferAmount = iterations * depositAmount ; const contract = new Contract ( erc20Address , TestContractArtifacts . TokenArtifact . abi ) ; await ( await contract . connect ( ethWalletWithTokens ) . transfer ( ethWallet . address , BN . from ( totalTransferAmount ) ) ) . wait ( ) ; const promises = _ . range ( 0 , iterations ) . map ( ( ) => chainService . fundChannel ( { channelId : randomChannelId ( ) , asset : erc20Address , expectedHeld : BN . from ( 0 ) , amount : BN . from ( depositAmount ) , } ) . then ( response => response . wait ( ) ) ) ; return Promise . all ( promises ) ; } , 500000 ) ; } ) ;