add gas price=0 unit test, comments (#528)

* add handler comment

* add gas price=0 test

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
noot 2020-09-23 11:21:21 -04:00 committed by GitHub
parent 1f4f7fb017
commit a54c2dc726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -60,9 +60,12 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
Simulate: ctx.IsCheckTx(), Simulate: ctx.IsCheckTx(),
} }
// since the txCount is used by the stateDB, and a simulated tx is run only on the node it's submitted to,
// then this will cause the txCount/stateDB of the node that ran the simulated tx to be different than the
// other nodes, causing a consensus error
if !st.Simulate {
// Prepare db for logs // Prepare db for logs
// TODO: block hash // TODO: block hash
if !st.Simulate {
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount) k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++ k.TxCount++
} }
@ -146,8 +149,8 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
st.Recipient = &to st.Recipient = &to
} }
// Prepare db for logs
if !st.Simulate { if !st.Simulate {
// Prepare db for logs
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount) k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++ k.TxCount++
} }

View File

@ -47,6 +47,7 @@ func TestMsgEthermintValidation(t *testing.T) {
{amount: sdk.NewInt(0), gasPrice: sdk.NewInt(100000), expectPass: true}, {amount: sdk.NewInt(0), gasPrice: sdk.NewInt(100000), expectPass: true},
{amount: sdk.NewInt(-1), gasPrice: sdk.NewInt(100000), expectPass: false}, {amount: sdk.NewInt(-1), gasPrice: sdk.NewInt(100000), expectPass: false},
{amount: sdk.NewInt(100), gasPrice: sdk.NewInt(-1), expectPass: false}, {amount: sdk.NewInt(100), gasPrice: sdk.NewInt(-1), expectPass: false},
{amount: sdk.NewInt(100), gasPrice: sdk.NewInt(0), expectPass: false},
} }
for i, tc := range testCases { for i, tc := range testCases {
@ -116,6 +117,7 @@ func TestMsgEthereumTxValidation(t *testing.T) {
{msg: "pass", amount: big.NewInt(100), gasPrice: big.NewInt(100000), expectPass: true}, {msg: "pass", amount: big.NewInt(100), gasPrice: big.NewInt(100000), expectPass: true},
{msg: "invalid amount", amount: big.NewInt(-1), gasPrice: big.NewInt(100000), expectPass: false}, {msg: "invalid amount", amount: big.NewInt(-1), gasPrice: big.NewInt(100000), expectPass: false},
{msg: "invalid gas price", amount: big.NewInt(100), gasPrice: big.NewInt(-1), expectPass: false}, {msg: "invalid gas price", amount: big.NewInt(100), gasPrice: big.NewInt(-1), expectPass: false},
{msg: "invalid gas price", amount: big.NewInt(100), gasPrice: big.NewInt(0), expectPass: false},
} }
for i, tc := range testCases { for i, tc := range testCases {