github.com/koko1123/flow-go-1@v0.29.6/module/mempool/stdmap/transactions_test.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package stdmap_test 4 5 import ( 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 10 "github.com/koko1123/flow-go-1/module/mempool/stdmap" 11 "github.com/koko1123/flow-go-1/utils/unittest" 12 ) 13 14 func TestTransactionPool(t *testing.T) { 15 tx1 := unittest.TransactionBodyFixture() 16 item1 := &tx1 17 18 tx2 := unittest.TransactionBodyFixture() 19 item2 := &tx2 20 21 pool := stdmap.NewTransactions(1000) 22 23 t.Run("should be able to add first", func(t *testing.T) { 24 added := pool.Add(item1) 25 assert.True(t, added) 26 }) 27 28 t.Run("should be able to add second", func(t *testing.T) { 29 added := pool.Add(item2) 30 assert.True(t, added) 31 }) 32 33 t.Run("should be able to get size", func(t *testing.T) { 34 size := pool.Size() 35 assert.EqualValues(t, 2, size) 36 }) 37 38 t.Run("should be able to get first", func(t *testing.T) { 39 got, exists := pool.ByID(item1.ID()) 40 assert.True(t, exists) 41 assert.Equal(t, item1, got) 42 }) 43 44 t.Run("should be able to remove second", func(t *testing.T) { 45 ok := pool.Remove(item2.ID()) 46 assert.True(t, ok) 47 }) 48 49 t.Run("should be able to retrieve all", func(t *testing.T) { 50 items := pool.All() 51 assert.Len(t, items, 1) 52 assert.Equal(t, item1, items[0]) 53 }) 54 55 t.Run("should be able to clear", func(t *testing.T) { 56 assert.True(t, pool.Size() > 0) 57 pool.Clear() 58 assert.Equal(t, uint(0), pool.Size()) 59 }) 60 }