github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/mempool/stdmap/transactions_test.go (about)

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