github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/protocol_state_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 // TestInsertProtocolState tests if basic badger operations on EpochProtocolState work as expected. 15 func TestInsertProtocolState(t *testing.T) { 16 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 17 expected := unittest.EpochStateFixture().ProtocolStateEntry 18 19 protocolStateID := expected.ID() 20 err := db.Update(InsertProtocolState(protocolStateID, expected)) 21 require.Nil(t, err) 22 23 var actual flow.ProtocolStateEntry 24 err = db.View(RetrieveProtocolState(protocolStateID, &actual)) 25 require.Nil(t, err) 26 27 assert.Equal(t, expected, &actual) 28 29 blockID := unittest.IdentifierFixture() 30 err = db.Update(IndexProtocolState(blockID, protocolStateID)) 31 require.Nil(t, err) 32 33 var actualProtocolStateID flow.Identifier 34 err = db.View(LookupProtocolState(blockID, &actualProtocolStateID)) 35 require.Nil(t, err) 36 37 assert.Equal(t, protocolStateID, actualProtocolStateID) 38 }) 39 }