github.com/aakash4dev/cometbft@v0.38.2/mempool/ids_test.go (about) 1 package mempool 2 3 import ( 4 "net" 5 "testing" 6 7 "github.com/aakash4dev/cometbft/p2p/mock" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestMempoolIDsBasic(t *testing.T) { 12 ids := newMempoolIDs() 13 14 peer := mock.NewPeer(net.IP{127, 0, 0, 1}) 15 16 ids.ReserveForPeer(peer) 17 assert.EqualValues(t, 1, ids.GetForPeer(peer)) 18 ids.Reclaim(peer) 19 20 ids.ReserveForPeer(peer) 21 assert.EqualValues(t, 2, ids.GetForPeer(peer)) 22 ids.Reclaim(peer) 23 } 24 25 func TestMempoolIDsPanicsIfNodeRequestsOvermaxActiveIDs(t *testing.T) { 26 if testing.Short() { 27 return 28 } 29 30 // 0 is already reserved for UnknownPeerID 31 ids := newMempoolIDs() 32 33 for i := 0; i < MaxActiveIDs-1; i++ { 34 peer := mock.NewPeer(net.IP{127, 0, 0, 1}) 35 ids.ReserveForPeer(peer) 36 } 37 38 assert.Panics(t, func() { 39 peer := mock.NewPeer(net.IP{127, 0, 0, 1}) 40 ids.ReserveForPeer(peer) 41 }) 42 }