2021-06-11 13:38:51 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-06-30 15:28:38 +00:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/tests"
|
2021-06-11 13:38:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTxData_chainID(t *testing.T) {
|
2021-07-05 16:39:08 +00:00
|
|
|
chainID := sdk.NewInt(1)
|
|
|
|
|
2021-06-11 13:38:51 +00:00
|
|
|
testCases := []struct {
|
|
|
|
msg string
|
|
|
|
data TxData
|
|
|
|
expChainID *big.Int
|
|
|
|
}{
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"access list tx", &AccessListTx{Accesses: AccessList{}, ChainID: &chainID}, big.NewInt(1),
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"access list tx, nil chain ID", &AccessListTx{Accesses: AccessList{}}, nil,
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"legacy tx, derived", &LegacyTx{}, nil,
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2021-07-05 16:39:08 +00:00
|
|
|
chainID := tc.data.GetChainID()
|
2021-06-11 13:38:51 +00:00
|
|
|
require.Equal(t, chainID, tc.expChainID, tc.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTxData_DeriveChainID(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
msg string
|
|
|
|
data TxData
|
|
|
|
expChainID *big.Int
|
|
|
|
from common.Address
|
|
|
|
}{
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"v = 0", &AccessListTx{V: big.NewInt(0).Bytes()}, nil, tests.GenerateAddress(),
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"v = 1", &AccessListTx{V: big.NewInt(1).Bytes()}, big.NewInt(9223372036854775791), tests.GenerateAddress(),
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"v = 27", &AccessListTx{V: big.NewInt(27).Bytes()}, new(big.Int), tests.GenerateAddress(),
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"v = 28", &AccessListTx{V: big.NewInt(28).Bytes()}, new(big.Int), tests.GenerateAddress(),
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-05 16:39:08 +00:00
|
|
|
"v = nil ", &AccessListTx{V: nil}, nil, tests.GenerateAddress(),
|
2021-06-11 13:38:51 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2021-07-05 16:39:08 +00:00
|
|
|
v, _, _ := tc.data.GetRawSignatureValues()
|
2021-06-11 13:38:51 +00:00
|
|
|
|
|
|
|
chainID := DeriveChainID(v)
|
|
|
|
require.Equal(t, tc.expChainID, chainID, tc.msg)
|
|
|
|
}
|
|
|
|
}
|