github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/common/rpc/convert/transactions_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/cadence"
    10  	jsoncdc "github.com/onflow/cadence/encoding/json"
    11  
    12  	"github.com/onflow/flow-go/engine/common/rpc/convert"
    13  	"github.com/onflow/flow-go/model/flow"
    14  	"github.com/onflow/flow-go/utils/unittest"
    15  )
    16  
    17  func TestConvertTransaction(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	tx := unittest.TransactionBodyFixture()
    21  	arg, err := jsoncdc.Encode(cadence.NewAddress(unittest.AddressFixture()))
    22  	require.NoError(t, err)
    23  
    24  	// add fields not included in the fixture
    25  	tx.Arguments = append(tx.Arguments, arg)
    26  	tx.EnvelopeSignatures = append(tx.EnvelopeSignatures, unittest.TransactionSignatureFixture())
    27  
    28  	msg := convert.TransactionToMessage(tx)
    29  	converted, err := convert.MessageToTransaction(msg, flow.Testnet.Chain())
    30  	require.NoError(t, err)
    31  
    32  	assert.Equal(t, tx, converted)
    33  	assert.Equal(t, tx.ID(), converted.ID())
    34  }