import { P2P } from '../../src/index' ; import { InboundPeer } from '../../src/peer' ; import { createNetwork , destroyNetwork } from '../utils/network_setup' ; describe ( 'Peer inbound eviction for connection time' , ( ) => { let p2pNodeList = [ ] ; beforeEach ( async ( ) => { const customSeedPeers = ( index , networkStartPort , networkSize ) => [ { ipAddress : '127.0.0.1' , port : networkStartPort + ( ( index - 1 + networkSize ) % networkSize ) , } , ] ; const customConfig = ( index , networkStartPort , networkSize ) => ( { latencyProtectionRatio : 0 , productivityProtectionRatio : 0 , longevityProtectionRatio : 0.5 , maxInboundConnections : 3 , seedPeers : customSeedPeers ( index , networkStartPort , networkSize ) , } ) ; p2pNodeList = await createNetwork ( { customConfig } ) ; } ) ; afterEach ( async ( ) => { await destroyNetwork ( p2pNodeList ) ; } ) ; it ( 'should not evict earliest connected peers' , ( ) => { const firstNode = p2pNodeList [ 0 ] ; const inboundPeers = firstNode [ '_peerPool' ] . getPeers ( InboundPeer ) . map ( peer => peer . port ) ; expect ( inboundPeers ) . toSatisfy ( ( n ) => n . includes ( 5001 ) || n . includes ( 5002 ) ) ; } ) ; } ) ;