github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/spork_test.go (about) 1 package operation 2 3 import ( 4 "math/rand" 5 "testing" 6 7 "github.com/dgraph-io/badger/v3" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/koko1123/flow-go-1/model/flow" 12 "github.com/koko1123/flow-go-1/utils/unittest" 13 ) 14 15 func TestSporkID_InsertRetrieve(t *testing.T) { 16 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 17 sporkID := unittest.IdentifierFixture() 18 19 err := db.Update(InsertSporkID(sporkID)) 20 require.NoError(t, err) 21 22 var actual flow.Identifier 23 err = db.View(RetrieveSporkID(&actual)) 24 require.NoError(t, err) 25 26 assert.Equal(t, sporkID, actual) 27 }) 28 } 29 30 func TestProtocolVersion_InsertRetrieve(t *testing.T) { 31 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 32 version := uint(rand.Uint32()) 33 34 err := db.Update(InsertProtocolVersion(version)) 35 require.NoError(t, err) 36 37 var actual uint 38 err = db.View(RetrieveProtocolVersion(&actual)) 39 require.NoError(t, err) 40 41 assert.Equal(t, version, actual) 42 }) 43 }