github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/interactions_test.go (about)

     1  // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED
     2  
     3  package operation
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/dgraph-io/badger/v3"
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/koko1123/flow-go-1/engine/execution/state/delta"
    13  	"github.com/koko1123/flow-go-1/model/flow"
    14  	"github.com/koko1123/flow-go-1/utils/unittest"
    15  )
    16  
    17  func TestStateInteractionsInsertCheckRetrieve(t *testing.T) {
    18  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    19  
    20  		d1 := delta.NewView(func(owner, key string) (value flow.RegisterValue, err error) {
    21  			return nil, nil
    22  		})
    23  
    24  		d2 := delta.NewView(func(owner, key string) (value flow.RegisterValue, err error) {
    25  			return nil, nil
    26  		})
    27  
    28  		// some set and reads
    29  		err := d1.Set(string([]byte("\x89krg\u007fBN\x1d\xf5\xfb\xb8r\xbc4\xbd\x98ռ\xf1\xd0twU\xbf\x16N\xb4?,\xa0&;")), "", []byte("zażółć gęślą jaźń"))
    30  		require.NoError(t, err)
    31  		err = d1.Set(string([]byte{2}), "", []byte("b"))
    32  		require.NoError(t, err)
    33  		err = d1.Set(string([]byte{2}), "", []byte("c"))
    34  		require.NoError(t, err)
    35  
    36  		_, err = d1.Get(string([]byte{2}), "")
    37  		require.NoError(t, err)
    38  		_, err = d1.Get(string([]byte{3}), "")
    39  		require.NoError(t, err)
    40  
    41  		interactions := []*delta.Snapshot{&d1.Interactions().Snapshot, &d2.Interactions().Snapshot}
    42  
    43  		blockID := unittest.IdentifierFixture()
    44  
    45  		err = db.Update(InsertExecutionStateInteractions(blockID, interactions))
    46  		require.Nil(t, err)
    47  
    48  		var readInteractions []*delta.Snapshot
    49  
    50  		err = db.View(RetrieveExecutionStateInteractions(blockID, &readInteractions))
    51  		require.NoError(t, err)
    52  
    53  		assert.Equal(t, interactions, readInteractions)
    54  
    55  		assert.Equal(t, d1.Delta(), d1.Interactions().Delta)
    56  	})
    57  }