github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/protocol_kv_store_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 // TestInsertProtocolKVStore tests if basic badger operations on ProtocolKVStore work as expected. 15 func TestInsertProtocolKVStore(t *testing.T) { 16 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 17 expected := &flow.PSKeyValueStoreData{ 18 Version: 2, 19 Data: unittest.RandomBytes(32), 20 } 21 22 kvStoreStateID := unittest.IdentifierFixture() 23 err := db.Update(InsertProtocolKVStore(kvStoreStateID, expected)) 24 require.Nil(t, err) 25 26 var actual flow.PSKeyValueStoreData 27 err = db.View(RetrieveProtocolKVStore(kvStoreStateID, &actual)) 28 require.Nil(t, err) 29 30 assert.Equal(t, expected, &actual) 31 32 blockID := unittest.IdentifierFixture() 33 err = db.Update(IndexProtocolKVStore(blockID, kvStoreStateID)) 34 require.Nil(t, err) 35 36 var actualProtocolKVStoreID flow.Identifier 37 err = db.View(LookupProtocolKVStore(blockID, &actualProtocolKVStoreID)) 38 require.Nil(t, err) 39 40 assert.Equal(t, kvStoreStateID, actualProtocolKVStoreID) 41 }) 42 }