update chain-id format (#542)

* chain_id.go

* rpc changes

* update scripts

* additional test

* changelog

* fix tests

* update script

* rpc updates

* validate testnet command chain-id

* validate rest server chain-id

* fix lint

* rpc updates

* changelog

* comment simulations
This commit is contained in:
Federico Kunze
2020-09-24 14:50:47 -03:00
committed by GitHub
parent b9a10b3f3e
commit a924b20091
22 changed files with 427 additions and 301 deletions
+10 -12
View File
@@ -1,11 +1,9 @@
package evm
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
emint "github.com/cosmos/ethermint/types"
ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -32,13 +30,13 @@ func NewHandler(k Keeper) sdk.Handler {
// handleMsgEthereumTx handles an Ethereum specific tx
func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*sdk.Result, error) {
// parse the chainID from a string to a base-10 integer
intChainID, ok := new(big.Int).SetString(ctx.ChainID(), 10)
if !ok {
return nil, sdkerrors.Wrap(emint.ErrInvalidChainID, ctx.ChainID())
chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID())
if err != nil {
return nil, err
}
// Verify signature and retrieve sender address
sender, err := msg.VerifySig(intChainID)
sender, err := msg.VerifySig(chainIDEpoch)
if err != nil {
return nil, err
}
@@ -54,7 +52,7 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
Amount: msg.Data.Amount,
Payload: msg.Data.Payload,
Csdb: k.CommitStateDB.WithContext(ctx),
ChainID: intChainID,
ChainID: chainIDEpoch,
TxHash: &ethHash,
Sender: sender,
Simulate: ctx.IsCheckTx(),
@@ -123,9 +121,9 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
// handleMsgEthermint handles an sdk.StdTx for an Ethereum state transition
func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk.Result, error) {
// parse the chainID from a string to a base-10 integer
intChainID, ok := new(big.Int).SetString(ctx.ChainID(), 10)
if !ok {
return nil, sdkerrors.Wrap(emint.ErrInvalidChainID, ctx.ChainID())
chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID())
if err != nil {
return nil, err
}
txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
@@ -138,7 +136,7 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
Amount: msg.Amount.BigInt(),
Payload: msg.Payload,
Csdb: k.CommitStateDB.WithContext(ctx),
ChainID: intChainID,
ChainID: chainIDEpoch,
TxHash: &ethHash,
Sender: common.BytesToAddress(msg.From.Bytes()),
Simulate: ctx.IsCheckTx(),
+8 -12
View File
@@ -21,6 +21,7 @@ import (
"github.com/cosmos/ethermint/app"
"github.com/cosmos/ethermint/crypto"
ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm"
"github.com/cosmos/ethermint/x/evm/keeper"
"github.com/cosmos/ethermint/x/evm/types"
@@ -43,7 +44,7 @@ func (suite *EvmTestSuite) SetupTest() {
checkTx := false
suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "3", Time: time.Now().UTC()})
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
suite.handler = evm.NewHandler(suite.app.EvmKeeper)
suite.querier = keeper.NewQuerier(suite.app.EvmKeeper)
suite.codec = codec.New()
@@ -58,10 +59,7 @@ func (suite *EvmTestSuite) TestHandleMsgEthereumTx() {
suite.Require().NoError(err)
sender := ethcmn.HexToAddress(privkey.PubKey().Address().String())
var (
tx types.MsgEthereumTx
chainID *big.Int
)
var tx types.MsgEthereumTx
testCases := []struct {
msg string
@@ -75,9 +73,8 @@ func (suite *EvmTestSuite) TestHandleMsgEthereumTx() {
tx = types.NewMsgEthereumTx(0, &sender, big.NewInt(100), 0, big.NewInt(10000), nil)
// parse context chain ID to big.Int
var ok bool
chainID, ok = new(big.Int).SetString(suite.ctx.ChainID(), 10)
suite.Require().True(ok)
chainID, err := ethermint.ParseChainID(suite.ctx.ChainID())
suite.Require().NoError(err)
// sign transaction
err = tx.Sign(chainID, privkey.ToECDSA())
@@ -91,9 +88,8 @@ func (suite *EvmTestSuite) TestHandleMsgEthereumTx() {
tx = types.NewMsgEthereumTxContract(0, big.NewInt(100), 0, big.NewInt(10000), nil)
// parse context chain ID to big.Int
var ok bool
chainID, ok = new(big.Int).SetString(suite.ctx.ChainID(), 10)
suite.Require().True(ok)
chainID, err := ethermint.ParseChainID(suite.ctx.ChainID())
suite.Require().NoError(err)
// sign transaction
err = tx.Sign(chainID, privkey.ToECDSA())
@@ -125,7 +121,7 @@ func (suite *EvmTestSuite) TestHandleMsgEthereumTx() {
}
for _, tc := range testCases {
suite.Run("", func() {
suite.Run(tc.msg, func() {
suite.SetupTest() // reset
//nolint
tc.malleate()