github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/my_receipts_test.go (about) 1 package badger_test 2 3 import ( 4 "testing" 5 6 "github.com/dgraph-io/badger/v2" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/module/metrics" 10 bstorage "github.com/onflow/flow-go/storage/badger" 11 "github.com/onflow/flow-go/utils/unittest" 12 ) 13 14 func TestMyExecutionReceiptsStorage(t *testing.T) { 15 withStore := func(t *testing.T, f func(store *bstorage.MyExecutionReceipts)) { 16 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 17 metrics := metrics.NewNoopCollector() 18 results := bstorage.NewExecutionResults(metrics, db) 19 receipts := bstorage.NewExecutionReceipts(metrics, db, results, bstorage.DefaultCacheSize) 20 store := bstorage.NewMyExecutionReceipts(metrics, db, receipts) 21 22 f(store) 23 }) 24 } 25 26 t.Run("store one get one", func(t *testing.T) { 27 withStore(t, func(store *bstorage.MyExecutionReceipts) { 28 block := unittest.BlockFixture() 29 receipt1 := unittest.ReceiptForBlockFixture(&block) 30 31 err := store.StoreMyReceipt(receipt1) 32 require.NoError(t, err) 33 34 actual, err := store.MyReceipt(block.ID()) 35 require.NoError(t, err) 36 37 require.Equal(t, receipt1, actual) 38 }) 39 }) 40 41 t.Run("store same for the same block", func(t *testing.T) { 42 withStore(t, func(store *bstorage.MyExecutionReceipts) { 43 block := unittest.BlockFixture() 44 45 receipt1 := unittest.ReceiptForBlockFixture(&block) 46 47 err := store.StoreMyReceipt(receipt1) 48 require.NoError(t, err) 49 50 err = store.StoreMyReceipt(receipt1) 51 require.NoError(t, err) 52 }) 53 }) 54 55 t.Run("store different receipt for same block should fail", func(t *testing.T) { 56 withStore(t, func(store *bstorage.MyExecutionReceipts) { 57 block := unittest.BlockFixture() 58 59 executor1 := unittest.IdentifierFixture() 60 executor2 := unittest.IdentifierFixture() 61 62 receipt1 := unittest.ReceiptForBlockExecutorFixture(&block, executor1) 63 receipt2 := unittest.ReceiptForBlockExecutorFixture(&block, executor2) 64 65 err := store.StoreMyReceipt(receipt1) 66 require.NoError(t, err) 67 68 err = store.StoreMyReceipt(receipt2) 69 require.Error(t, err) 70 }) 71 }) 72 }