github.com/koko1123/flow-go-1@v0.29.6/storage/badger/payloads_test.go (about) 1 package badger_test 2 3 import ( 4 "errors" 5 6 "testing" 7 8 "github.com/dgraph-io/badger/v3" 9 "github.com/stretchr/testify/require" 10 11 "github.com/koko1123/flow-go-1/module/metrics" 12 "github.com/koko1123/flow-go-1/storage" 13 "github.com/koko1123/flow-go-1/utils/unittest" 14 15 badgerstorage "github.com/koko1123/flow-go-1/storage/badger" 16 ) 17 18 func TestPayloadStoreRetrieve(t *testing.T) { 19 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 20 metrics := metrics.NewNoopCollector() 21 22 index := badgerstorage.NewIndex(metrics, db) 23 seals := badgerstorage.NewSeals(metrics, db) 24 guarantees := badgerstorage.NewGuarantees(metrics, db, badgerstorage.DefaultCacheSize) 25 results := badgerstorage.NewExecutionResults(metrics, db) 26 receipts := badgerstorage.NewExecutionReceipts(metrics, db, results, badgerstorage.DefaultCacheSize) 27 store := badgerstorage.NewPayloads(db, index, guarantees, seals, receipts, results) 28 29 blockID := unittest.IdentifierFixture() 30 expected := unittest.PayloadFixture(unittest.WithAllTheFixins) 31 32 // store payload 33 err := store.Store(blockID, &expected) 34 require.NoError(t, err) 35 36 // fetch payload 37 payload, err := store.ByBlockID(blockID) 38 require.NoError(t, err) 39 require.Equal(t, &expected, payload) 40 }) 41 } 42 43 func TestPayloadRetreiveWithoutStore(t *testing.T) { 44 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 45 metrics := metrics.NewNoopCollector() 46 47 index := badgerstorage.NewIndex(metrics, db) 48 seals := badgerstorage.NewSeals(metrics, db) 49 guarantees := badgerstorage.NewGuarantees(metrics, db, badgerstorage.DefaultCacheSize) 50 results := badgerstorage.NewExecutionResults(metrics, db) 51 receipts := badgerstorage.NewExecutionReceipts(metrics, db, results, badgerstorage.DefaultCacheSize) 52 store := badgerstorage.NewPayloads(db, index, guarantees, seals, receipts, results) 53 54 blockID := unittest.IdentifierFixture() 55 56 _, err := store.ByBlockID(blockID) 57 require.True(t, errors.Is(err, storage.ErrNotFound)) 58 }) 59 }