github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/mempool/stdmap/receipts_test.go (about) 1 package stdmap_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/module/mempool/stdmap" 10 "github.com/onflow/flow-go/utils/unittest" 11 ) 12 13 func TestReceiptPool(t *testing.T) { 14 item1 := unittest.ExecutionReceiptFixture() 15 item2 := unittest.ExecutionReceiptFixture() 16 17 pool, err := stdmap.NewReceipts(1000) 18 require.NoError(t, err) 19 20 t.Run("should be able to add first", func(t *testing.T) { 21 added := pool.Add(item1) 22 assert.True(t, added) 23 }) 24 25 t.Run("should be able to add second", func(t *testing.T) { 26 added := pool.Add(item2) 27 assert.True(t, added) 28 }) 29 30 t.Run("should be able to get size", func(t *testing.T) { 31 size := pool.Size() 32 assert.EqualValues(t, 2, size) 33 }) 34 35 t.Run("should be able to get first", func(t *testing.T) { 36 got, exists := pool.ByID(item1.ID()) 37 assert.True(t, exists) 38 assert.Equal(t, item1, got) 39 }) 40 41 t.Run("should be able to remove second", func(t *testing.T) { 42 ok := pool.Remove(item2.ID()) 43 assert.True(t, ok) 44 }) 45 46 t.Run("should be able to retrieve all", func(t *testing.T) { 47 items := pool.All() 48 assert.Len(t, items, 1) 49 assert.Equal(t, item1, items[0]) 50 }) 51 }