github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/receipts_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 TestReceipts_InsertRetrieve(t *testing.T) {
    17  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    18  		receipt := unittest.ExecutionReceiptFixture()
    19  		expected := receipt.Meta()
    20  
    21  		err := db.Update(InsertExecutionReceiptMeta(receipt.ID(), expected))
    22  		require.Nil(t, err)
    23  
    24  		var actual flow.ExecutionReceiptMeta
    25  		err = db.View(RetrieveExecutionReceiptMeta(receipt.ID(), &actual))
    26  		require.Nil(t, err)
    27  
    28  		assert.Equal(t, expected, &actual)
    29  	})
    30  }
    31  
    32  func TestReceipts_Index(t *testing.T) {
    33  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    34  		receipt := unittest.ExecutionReceiptFixture()
    35  		expected := receipt.ID()
    36  		blockID := receipt.ExecutionResult.BlockID
    37  
    38  		err := db.Update(IndexOwnExecutionReceipt(blockID, expected))
    39  		require.Nil(t, err)
    40  
    41  		var actual flow.Identifier
    42  		err = db.View(LookupOwnExecutionReceipt(blockID, &actual))
    43  		require.Nil(t, err)
    44  
    45  		assert.Equal(t, expected, actual)
    46  	})
    47  }
    48  
    49  func TestReceipts_MultiIndex(t *testing.T) {
    50  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    51  		expected := []flow.Identifier{unittest.IdentifierFixture(), unittest.IdentifierFixture()}
    52  		blockID := unittest.IdentifierFixture()
    53  
    54  		for _, id := range expected {
    55  			err := db.Update(IndexExecutionReceipts(blockID, id))
    56  			require.Nil(t, err)
    57  		}
    58  		var actual []flow.Identifier
    59  		err := db.View(LookupExecutionReceipts(blockID, &actual))
    60  		require.Nil(t, err)
    61  
    62  		assert.ElementsMatch(t, expected, actual)
    63  	})
    64  }