github.com/koko1123/flow-go-1@v0.29.6/storage/badger/procedure/cluster_test.go (about) 1 package procedure 2 3 import ( 4 "testing" 5 6 "github.com/dgraph-io/badger/v3" 7 "github.com/stretchr/testify/require" 8 9 "github.com/koko1123/flow-go-1/model/cluster" 10 "github.com/koko1123/flow-go-1/model/flow" 11 "github.com/koko1123/flow-go-1/storage/badger/operation" 12 "github.com/koko1123/flow-go-1/utils/unittest" 13 ) 14 15 func TestInsertRetrieveClusterBlock(t *testing.T) { 16 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 17 block := unittest.ClusterBlockFixture() 18 19 err := db.Update(InsertClusterBlock(&block)) 20 require.NoError(t, err) 21 22 var retrieved cluster.Block 23 err = db.View(RetrieveClusterBlock(block.Header.ID(), &retrieved)) 24 require.NoError(t, err) 25 26 require.Equal(t, block, retrieved) 27 }) 28 } 29 30 func TestFinalizeClusterBlock(t *testing.T) { 31 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 32 parent := unittest.ClusterBlockFixture() 33 34 block := unittest.ClusterBlockWithParent(&parent) 35 36 err := db.Update(InsertClusterBlock(&block)) 37 require.NoError(t, err) 38 39 err = db.Update(operation.IndexClusterBlockHeight(block.Header.ChainID, parent.Header.Height, parent.ID())) 40 require.NoError(t, err) 41 42 err = db.Update(operation.InsertClusterFinalizedHeight(block.Header.ChainID, parent.Header.Height)) 43 require.NoError(t, err) 44 45 err = db.Update(FinalizeClusterBlock(block.Header.ID())) 46 require.NoError(t, err) 47 48 var boundary uint64 49 err = db.View(operation.RetrieveClusterFinalizedHeight(block.Header.ChainID, &boundary)) 50 require.NoError(t, err) 51 require.Equal(t, block.Header.Height, boundary) 52 53 var headID flow.Identifier 54 err = db.View(operation.LookupClusterBlockHeight(block.Header.ChainID, boundary, &headID)) 55 require.NoError(t, err) 56 require.Equal(t, block.ID(), headID) 57 }) 58 }