github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/common/rpc/convert/execution_results_test.go (about)

     1  package convert_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/onflow/flow-go/engine/common/rpc/convert"
    10  	"github.com/onflow/flow-go/model/flow"
    11  	"github.com/onflow/flow-go/utils/unittest"
    12  )
    13  
    14  func TestConvertExecutionResult(t *testing.T) {
    15  	t.Parallel()
    16  
    17  	er := unittest.ExecutionResultFixture(unittest.WithServiceEvents(3))
    18  
    19  	msg, err := convert.ExecutionResultToMessage(er)
    20  	require.NoError(t, err)
    21  
    22  	converted, err := convert.MessageToExecutionResult(msg)
    23  	require.NoError(t, err)
    24  
    25  	assert.Equal(t, er, converted)
    26  }
    27  
    28  func TestConvertExecutionResults(t *testing.T) {
    29  	t.Parallel()
    30  
    31  	results := []*flow.ExecutionResult{
    32  		unittest.ExecutionResultFixture(unittest.WithServiceEvents(3)),
    33  		unittest.ExecutionResultFixture(unittest.WithServiceEvents(3)),
    34  		unittest.ExecutionResultFixture(unittest.WithServiceEvents(3)),
    35  	}
    36  
    37  	msg, err := convert.ExecutionResultsToMessages(results)
    38  	require.NoError(t, err)
    39  
    40  	converted, err := convert.MessagesToExecutionResults(msg)
    41  	require.NoError(t, err)
    42  
    43  	assert.Equal(t, results, converted)
    44  }
    45  
    46  func TestConvertExecutionResultMetaList(t *testing.T) {
    47  	t.Parallel()
    48  
    49  	block := unittest.FullBlockFixture()
    50  	block.SetPayload(unittest.PayloadFixture(unittest.WithAllTheFixins))
    51  	metaList := block.Payload.Receipts
    52  
    53  	msg := convert.ExecutionResultMetaListToMessages(metaList)
    54  	converted := convert.MessagesToExecutionResultMetaList(msg)
    55  
    56  	assert.Equal(t, metaList, converted)
    57  }