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