github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/payload_test.go (about)

     1  package operation
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/dgraph-io/badger/v2"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/onflow/flow-go/model/flow"
    11  	"github.com/onflow/flow-go/utils/unittest"
    12  )
    13  
    14  func TestSealInsertCheckRetrieve(t *testing.T) {
    15  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    16  		expected := unittest.Seal.Fixture()
    17  
    18  		err := db.Update(InsertSeal(expected.ID(), expected))
    19  		require.Nil(t, err)
    20  
    21  		var actual flow.Seal
    22  		err = db.View(RetrieveSeal(expected.ID(), &actual))
    23  		require.Nil(t, err)
    24  
    25  		assert.Equal(t, expected, &actual)
    26  	})
    27  }
    28  
    29  func TestSealIndexAndLookup(t *testing.T) {
    30  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    31  		seal1 := unittest.Seal.Fixture()
    32  		seal2 := unittest.Seal.Fixture()
    33  
    34  		seals := []*flow.Seal{seal1, seal2}
    35  
    36  		blockID := flow.MakeID([]byte{0x42})
    37  
    38  		expected := []flow.Identifier(flow.GetIDs(seals))
    39  
    40  		err := db.Update(func(tx *badger.Txn) error {
    41  			for _, seal := range seals {
    42  				if err := InsertSeal(seal.ID(), seal)(tx); err != nil {
    43  					return err
    44  				}
    45  			}
    46  			if err := IndexPayloadSeals(blockID, expected)(tx); err != nil {
    47  				return err
    48  			}
    49  			return nil
    50  		})
    51  		require.Nil(t, err)
    52  
    53  		var actual []flow.Identifier
    54  		err = db.View(LookupPayloadSeals(blockID, &actual))
    55  		require.Nil(t, err)
    56  
    57  		assert.Equal(t, expected, actual)
    58  	})
    59  }