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