2021-06-04 13:14:45 +00:00
|
|
|
package encoding_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/app"
|
|
|
|
"github.com/tharsis/ethermint/encoding"
|
|
|
|
"github.com/tharsis/ethermint/tests"
|
|
|
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
2021-06-04 13:14:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTxEncoding(t *testing.T) {
|
|
|
|
addr, key := tests.NewAddrKey()
|
|
|
|
signer := tests.NewSigner(key)
|
|
|
|
|
2021-10-05 15:38:20 +00:00
|
|
|
msg := evmtypes.NewTxContract(big.NewInt(1), 1, big.NewInt(10), 100000, nil, big.NewInt(1), big.NewInt(1), []byte{}, nil)
|
2021-06-04 13:14:45 +00:00
|
|
|
msg.From = addr.Hex()
|
|
|
|
|
|
|
|
ethSigner := ethtypes.LatestSignerForChainID(big.NewInt(1))
|
|
|
|
err := msg.Sign(ethSigner, signer)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cfg := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
|
2021-11-02 10:24:24 +00:00
|
|
|
_, err = cfg.TxConfig.TxEncoder()(msg)
|
|
|
|
require.Error(t, err, "encoding failed")
|
2021-06-04 13:14:45 +00:00
|
|
|
|
|
|
|
// FIXME: transaction hashing is hardcoded on Terndermint:
|
|
|
|
// See https://github.com/tendermint/tendermint/issues/6539 for reference
|
|
|
|
// txHash := msg.AsTransaction().Hash()
|
|
|
|
// tmTx := tmtypes.Tx(bz)
|
|
|
|
|
|
|
|
// require.Equal(t, txHash.Bytes(), tmTx.Hash())
|
|
|
|
}
|