import { P2P } from '../../src/index' ; import { createNetwork , destroyNetwork } from '../utils/network_setup' ; import { customNodeInfoSchema } from '../utils/schema' ; import { P2PConfig } from '../../src/types' ; describe ( 'Custom nodeInfo' , ( ) => { let p2pNodeList = [ ] ; beforeEach ( async ( ) => { const customConfig = ( ) : Partial < P2PConfig > => ( { nodeInfo : { options : { maxHeightPreviouslyForged : 11 , maxHeightPrevoted : 2 , } , } as any , customNodeInfoSchema , } ) ; p2pNodeList = await createNetwork ( { customConfig , networkSize : 4 } ) ; } ) ; afterEach ( async ( ) => { await destroyNetwork ( p2pNodeList ) ; } ) ; it ( 'should have tried peers with custom test field "modules" that was passed as nodeinfo' , ( ) => { for ( const p2p of p2pNodeList ) { const { triedPeers } = ( p2p as any ) . _peerBook ; const { newPeers } = ( p2p as any ) . _peerBook ; for ( const peer of triedPeers ) { expect ( peer ) . toMatchObject ( { sharedState : { options : { maxHeightPrevoted : 2 , maxHeightPreviouslyForged : 11 , } , } , } ) ; } for ( const peer of newPeers ) { if ( peer . modules ) { expect ( peer ) . toMatchObject ( { sharedState : { options : { maxHeightPrevoted : 2 , maxHeightPreviouslyForged : 11 , } , } , } ) ; } } for ( const peer of p2p . getConnectedPeers ( ) ) { expect ( peer ) . toMatchObject ( { options : { maxHeightPrevoted : 2 , maxHeightPreviouslyForged : 11 , } , } ) ; } } } ) ; } ) ;