diff --git a/x/evm/types/msg.go b/x/evm/types/msg.go index 4a8f3eaa..b139755a 100644 --- a/x/evm/types/msg.go +++ b/x/evm/types/msg.go @@ -184,7 +184,9 @@ func (msg *MsgEthereumTx) ChainID() *big.Int { // Cost returns amount + gasprice * gaslimit. func (msg MsgEthereumTx) Cost() *big.Int { total := msg.Fee() - total.Add(total, msg.Data.amount()) + if msg.Data.amount() != nil { + total.Add(total, msg.Data.amount()) + } return total } diff --git a/x/evm/types/msg_test.go b/x/evm/types/msg_test.go index 12cad7c5..da4e8226 100644 --- a/x/evm/types/msg_test.go +++ b/x/evm/types/msg_test.go @@ -75,7 +75,7 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_ValidateBasic() { {msg: "pass with recipient - AccessList Tx", to: &suite.to, amount: big.NewInt(100), gasPrice: big.NewInt(0), accessList: ðtypes.AccessList{}, chainID: big.NewInt(1), expectPass: true}, {msg: "pass contract - Legacy Tx", to: nil, amount: big.NewInt(100), gasPrice: big.NewInt(100000), expectPass: true}, {msg: "invalid recipient", to: ðcmn.Address{}, amount: big.NewInt(-1), gasPrice: big.NewInt(1000), expectPass: false}, - {msg: "nil amount", to: &suite.to, amount: nil, gasPrice: big.NewInt(1000), expectPass: false}, + {msg: "nil amount", to: &suite.to, amount: nil, gasPrice: big.NewInt(1000), expectPass: true}, {msg: "negative amount", to: &suite.to, amount: big.NewInt(-1), gasPrice: big.NewInt(1000), expectPass: true}, {msg: "nil gas price", to: &suite.to, amount: big.NewInt(100), gasPrice: nil, expectPass: false}, {msg: "negative gas price", to: &suite.to, amount: big.NewInt(100), gasPrice: big.NewInt(-1), expectPass: true}, diff --git a/x/evm/types/tx_data.go b/x/evm/types/tx_data.go index 8d4712a9..bc060abc 100644 --- a/x/evm/types/tx_data.go +++ b/x/evm/types/tx_data.go @@ -180,12 +180,8 @@ func (data TxData) Validate() error { } amount := data.amount() - if amount == nil { - return sdkerrors.Wrap(ErrInvalidAmount, "cannot be nil") - } - // Amount can be 0 - if amount.Sign() == -1 { + if amount != nil && amount.Sign() == -1 { return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount) }