Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
add gas price=0 unit test, comments (#528)
Browse files Browse the repository at this point in the history
* add handler comment

* add gas price=0 test

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
noot and fedekunze authored Sep 23, 2020
1 parent 1f4f7fb commit a54c2dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
Simulate: ctx.IsCheckTx(),
}

// Prepare db for logs
// TODO: block hash
// 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
// TODO: block hash
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++
}
Expand Down Expand Up @@ -146,8 +149,8 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
st.Recipient = &to
}

// Prepare db for logs
if !st.Simulate {
// Prepare db for logs
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++
}
Expand Down
2 changes: 2 additions & 0 deletions x/evm/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestMsgEthermintValidation(t *testing.T) {
{amount: sdk.NewInt(0), gasPrice: sdk.NewInt(100000), expectPass: true},
{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(0), expectPass: false},
}

for i, tc := range testCases {
Expand Down Expand Up @@ -116,6 +117,7 @@ func TestMsgEthereumTxValidation(t *testing.T) {
{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 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 {
Expand Down

0 comments on commit a54c2dc

Please sign in to comment.