github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/seals_test.go (about)

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