import { P2P , events } from '../../src/index' ; import { wait } from '../utils/helpers' ; import { createNetwork , destroyNetwork } from '../utils/network_setup' ; import { P2PConfig } from '../../src/types' ; const { EVENT_BAN_PEER } = events ; const customNodeInfoSchema = { $id : '/malformed' , type : 'object' , properties : { invalid : { dataType : 'string' , fieldNumber : 1 , } , } , } ; describe ( 'penalty sending malformed peerInfo' , ( ) => { let p2pNodeList = [ ] ; const collectedEvents = new Map ( ) ; beforeEach ( async ( ) => { p2pNodeList = await createNetwork ( { networkSize : 2 , customConfig : ( index ) : Partial < P2PConfig > => index === 0 ? { maxPeerInfoSize : 30248 , customNodeInfoSchema } : { customNodeInfoSchema } , } ) ; p2pNodeList [ 1 ] . on ( EVENT_BAN_PEER , peerId => { collectedEvents . set ( EVENT_BAN_PEER , peerId ) ; } ) ; p2pNodeList [ 0 ] . applyNodeInfo ( { networkIdentifier : 'da3ed6a45429278bac2666961289ca17ad86595d33b31037615d4b8e8f158bba' , networkVersion : '1.1' , options : { invalid : '1.' . repeat ( 13000 ) } , advertiseAddress : true , } ) ; await wait ( 100 ) ; } ) ; afterEach ( async ( ) => { await destroyNetwork ( p2pNodeList ) ; } ) ; it ( 'should fire EVENT_BAN_PEER event' , ( ) => { expect ( collectedEvents . get ( EVENT_BAN_PEER ) ) . toBe ( '127.0.0.1:5000' ) ; } ) ; } ) ;