fix: tx amount can be nil or zero (#117)
* amount can be nil or zero * fix cost function * fix tests
This commit is contained in:
parent
f762087d36
commit
9d18414c93
@ -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
|
||||
}
|
||||
|
||||
|
@ -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},
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user