github.com/koko1123/flow-go-1@v0.29.6/engine/execution/computation/committer/committer_test.go (about)

     1  package committer_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/mock"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/koko1123/flow-go-1/engine/execution/computation/committer"
    10  	fvmUtils "github.com/koko1123/flow-go-1/fvm/utils"
    11  	led "github.com/koko1123/flow-go-1/ledger"
    12  	ledgermock "github.com/koko1123/flow-go-1/ledger/mock"
    13  	"github.com/koko1123/flow-go-1/model/flow"
    14  	"github.com/koko1123/flow-go-1/module/trace"
    15  	utils "github.com/koko1123/flow-go-1/utils/unittest"
    16  )
    17  
    18  func TestLedgerViewCommitter(t *testing.T) {
    19  
    20  	t.Run("calls to set and prove", func(t *testing.T) {
    21  
    22  		ledger := new(ledgermock.Ledger)
    23  		com := committer.NewLedgerViewCommitter(ledger, trace.NewNoopTracer())
    24  
    25  		var expectedStateCommitment led.State
    26  		copy(expectedStateCommitment[:], []byte{1, 2, 3})
    27  		ledger.On("Set", mock.Anything).
    28  			Return(expectedStateCommitment, nil, nil).
    29  			Once()
    30  
    31  		expectedProof := led.Proof([]byte{2, 3, 4})
    32  		ledger.On("Prove", mock.Anything).
    33  			Return(expectedProof, nil).
    34  			Once()
    35  
    36  		view := fvmUtils.NewSimpleView()
    37  
    38  		err := view.Set(
    39  			"owner",
    40  			"key",
    41  			[]byte{1},
    42  		)
    43  		require.NoError(t, err)
    44  
    45  		newState, proof, _, err := com.CommitView(view, utils.StateCommitmentFixture())
    46  		require.NoError(t, err)
    47  		require.Equal(t, flow.StateCommitment(expectedStateCommitment), newState)
    48  		require.Equal(t, []uint8(expectedProof), proof)
    49  	})
    50  
    51  }