github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/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/v2" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/onflow/flow-go/model/flow" 12 "github.com/onflow/flow-go/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 } 44 45 // TestEpochCommitSafetyThreshold_InsertRetrieve tests that we can insert and 46 // retrieve epoch commit safety threshold values. 47 func TestEpochCommitSafetyThreshold_InsertRetrieve(t *testing.T) { 48 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 49 threshold := rand.Uint64() 50 51 err := db.Update(InsertEpochCommitSafetyThreshold(threshold)) 52 require.NoError(t, err) 53 54 var actual uint64 55 err = db.View(RetrieveEpochCommitSafetyThreshold(&actual)) 56 require.NoError(t, err) 57 58 assert.Equal(t, threshold, actual) 59 }) 60 }