github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/children_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  func TestBlockChildrenIndexUpdateLookup(t *testing.T) {
    15  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    16  		blockID := unittest.IdentifierFixture()
    17  		childrenIDs := unittest.IdentifierListFixture(8)
    18  		var retrievedIDs flow.IdentifierList
    19  
    20  		err := db.Update(InsertBlockChildren(blockID, childrenIDs))
    21  		require.NoError(t, err)
    22  		err = db.View(RetrieveBlockChildren(blockID, &retrievedIDs))
    23  		require.NoError(t, err)
    24  		assert.Equal(t, childrenIDs, retrievedIDs)
    25  
    26  		altIDs := unittest.IdentifierListFixture(4)
    27  		err = db.Update(UpdateBlockChildren(blockID, altIDs))
    28  		require.NoError(t, err)
    29  		err = db.View(RetrieveBlockChildren(blockID, &retrievedIDs))
    30  		require.NoError(t, err)
    31  		assert.Equal(t, altIDs, retrievedIDs)
    32  	})
    33  }