github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/types/call_test.go (about)

     1  package types
     2  
     3  import (
     4  	"math/big"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestDirectCall(t *testing.T) {
    12  	dc := &DirectCall{
    13  		Type:     DirectCallTxType,
    14  		SubType:  DepositCallSubType,
    15  		From:     Address{0x1, 0x2},
    16  		To:       Address{0x3, 0x4},
    17  		Data:     []byte{0xf, 0xa, 0xb},
    18  		Value:    big.NewInt(5),
    19  		GasLimit: 100,
    20  	}
    21  
    22  	t.Run("calculate hash", func(t *testing.T) {
    23  		h, err := dc.Hash()
    24  		require.NoError(t, err)
    25  		assert.Equal(t, "0xe28ff08eca95608646d765e3007b3710f7f2a8ac5e297431da1962c33487e7b6", h.Hex())
    26  	})
    27  
    28  	t.Run("construct transaction", func(t *testing.T) {
    29  		tx := dc.Transaction()
    30  		h, err := dc.Hash()
    31  		require.NoError(t, err)
    32  		assert.Equal(t, dc.Value, tx.Value())
    33  		assert.Equal(t, dc.To.ToCommon(), *tx.To())
    34  		assert.Equal(t, h, tx.Hash())
    35  		assert.Equal(t, dc.GasLimit, tx.Gas())
    36  		assert.Equal(t, dc.Data, tx.Data())
    37  		assert.Equal(t, uint64(0), tx.Nonce()) // no nonce exists for direct call
    38  	})
    39  }