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