tests(integration): block gas limit tests (#1500)

* added antehandler test

* add integration tests

* add back gas call test

* added integration tests v2

* linters

* Update tests/integration_tests/test_gas.py

* Update tests/integration_tests/test_gas.py

* update gomod2nix

* Update tests/integration_tests/test_gas.py

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Freddy Caceres <facs95@gmail.com>
This commit is contained in:
Adi Saravanan 2022-12-02 04:23:11 -08:00 committed by GitHub
parent 5b43aab0d5
commit a230c0ec2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 23 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/evmos/ethermint/app/ante" "github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/server/config" "github.com/evmos/ethermint/server/config"
"github.com/evmos/ethermint/tests" "github.com/evmos/ethermint/tests"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb" "github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types" evmtypes "github.com/evmos/ethermint/x/evm/types"
@ -180,6 +181,9 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2.From = addr.Hex() tx2.From = addr.Hex()
tx2Priority := int64(1) tx2Priority := int64(1)
tx3GasLimit := ethermint.BlockGasLimit(suite.ctx) + uint64(1)
tx3 := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), tx3GasLimit, gasPrice, nil, nil, nil, &ethtypes.AccessList{{Address: addr, StorageKeys: nil}})
dynamicFeeTx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), tx2GasLimit, dynamicFeeTx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), tx2GasLimit,
nil, // gasPrice nil, // gasPrice
new(big.Int).Add(baseFee, big.NewInt(evmtypes.DefaultPriorityReduction.Int64()*2)), // gasFeeCap new(big.Int).Add(baseFee, big.NewInt(evmtypes.DefaultPriorityReduction.Int64()*2)), // gasFeeCap
@ -216,6 +220,14 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
false, false, false, false,
0, 0,
}, },
{
"gas limit above block gas limit",
tx3,
math.MaxUint64,
func() {},
false, false,
0,
},
{ {
"not enough balance for fees", "not enough balance for fees",
tx2, tx2,

View File

@ -94,8 +94,8 @@ schema = 3
version = "v1.0.4" version = "v1.0.4"
hash = "sha256-JvcBXBdjdmnaW/nyf/tw/uaOAGn1b78yxrtl2/Rs3kA=" hash = "sha256-JvcBXBdjdmnaW/nyf/tw/uaOAGn1b78yxrtl2/Rs3kA="
[mod."github.com/cosmos/cosmos-proto"] [mod."github.com/cosmos/cosmos-proto"]
version = "v1.0.0-alpha8" version = "v1.0.0-beta.1"
hash = "sha256-iXzXoS5Kfh5DBy+PhdFWraDWXda/3M4j7j4VECjv4CA=" hash = "sha256-oATkuj+fM5eBn+ywO+w/tL0AFSIEkx0J3Yz+VhVe0QA="
[mod."github.com/cosmos/cosmos-sdk"] [mod."github.com/cosmos/cosmos-sdk"]
version = "v0.46.6" version = "v0.46.6"
hash = "sha256-H1VZxZUWXhpXiY3A9smLp09MEGpXmh+XvX6YUiXPcpQ=" hash = "sha256-H1VZxZUWXhpXiY3A9smLp09MEGpXmh+XvX6YUiXPcpQ="

86
tests/integration_tests/test_gas.py Executable file → Normal file
View File

@ -1,4 +1,13 @@
from .utils import ADDRS, CONTRACTS, KEYS, deploy_contract, send_transaction import pytest
from .utils import (
ADDRS,
CONTRACTS,
KEYS,
deploy_contract,
send_transaction,
w3_wait_for_new_blocks,
)
def test_gas_eth_tx(geth, ethermint): def test_gas_eth_tx(geth, ethermint):
@ -21,12 +30,10 @@ def test_gas_eth_tx(geth, ethermint):
def test_gas_deployment(geth, ethermint): def test_gas_deployment(geth, ethermint):
# deploy an identical contract on geth and ethermint # deploy an identical contract on geth and ethermint
# ensure that the gasUsed is equivalent # ensure that the gasUsed is equivalent
_, geth_contract_receipt = deploy_contract( _, geth_contract_receipt = deploy_contract(geth.w3, CONTRACTS["TestERC20A"])
geth.w3,
CONTRACTS["TestERC20A"])
_, ethermint_contract_receipt = deploy_contract( _, ethermint_contract_receipt = deploy_contract(
ethermint.w3, ethermint.w3, CONTRACTS["TestERC20A"]
CONTRACTS["TestERC20A"]) )
assert geth_contract_receipt.gasUsed == ethermint_contract_receipt.gasUsed assert geth_contract_receipt.gasUsed == ethermint_contract_receipt.gasUsed
@ -35,28 +42,65 @@ def test_gas_call(geth, ethermint):
# deploy an identical contract on geth and ethermint # deploy an identical contract on geth and ethermint
# ensure that the contract has a function which consumes non-trivial gas # ensure that the contract has a function which consumes non-trivial gas
geth_contract, _ = deploy_contract( geth_contract, _ = deploy_contract(geth.w3, CONTRACTS["BurnGas"])
geth.w3, ethermint_contract, _ = deploy_contract(ethermint.w3, CONTRACTS["BurnGas"])
CONTRACTS["BurnGas"])
ethermint_contract, _ = deploy_contract(
ethermint.w3,
CONTRACTS["BurnGas"])
# call the contract and get tx receipt for geth # call the contract and get tx receipt for geth
geth_gas_price = geth.w3.eth.gas_price geth_gas_price = geth.w3.eth.gas_price
geth_txhash = (geth_contract.functions geth_txhash = geth_contract.functions.burnGas(function_input).transact(
.burnGas(function_input) {"from": ADDRS["validator"], "gasPrice": geth_gas_price}
.transact({'from': ADDRS["validator"], "gasPrice": geth_gas_price})) )
geth_call_receipt = geth.w3.eth.wait_for_transaction_receipt(geth_txhash) geth_call_receipt = geth.w3.eth.wait_for_transaction_receipt(geth_txhash)
# repeat the above for ethermint # repeat the above for ethermint
ethermint_gas_price = ethermint.w3.eth.gas_price ethermint_gas_price = ethermint.w3.eth.gas_price
ethermint_txhash = (ethermint_contract.functions ethermint_txhash = ethermint_contract.functions.burnGas(function_input).transact(
.burnGas(function_input) {"from": ADDRS["validator"], "gasPrice": ethermint_gas_price}
.transact({'from': ADDRS["validator"], )
"gasPrice": ethermint_gas_price})) ethermint_call_receipt = ethermint.w3.eth.wait_for_transaction_receipt(
ethermint_call_receipt = (ethermint.w3. ethermint_txhash
eth.wait_for_transaction_receipt(ethermint_txhash)) )
# ensure that the gasUsed is equivalent # ensure that the gasUsed is equivalent
assert geth_call_receipt.gasUsed == ethermint_call_receipt.gasUsed assert geth_call_receipt.gasUsed == ethermint_call_receipt.gasUsed
def test_block_gas_limit(ethermint):
tx_value = 10
# get the block gas limit from the latest block
w3_wait_for_new_blocks(ethermint.w3, 5)
block = ethermint.w3.eth.get_block("latest")
exceeded_gas_limit = block.gasLimit + 100
# send a transaction exceeding the block gas limit
ethermint_gas_price = ethermint.w3.eth.gas_price
tx = {
"to": ADDRS["community"],
"value": tx_value,
"gas": exceeded_gas_limit,
"gasPrice": ethermint_gas_price,
}
# expect an error due to the block gas limit
with pytest.raises(Exception):
send_transaction(ethermint.w3, tx, KEYS["validator"])
# deploy a contract on ethermint
ethermint_contract, _ = deploy_contract(ethermint.w3, CONTRACTS["BurnGas"])
# expect an error on contract call due to block gas limit
with pytest.raises(Exception):
ethermint_txhash = ethermint_contract.functions.burnGas(
exceeded_gas_limit
).transact(
{
"from": ADDRS["validator"],
"gas": exceeded_gas_limit,
"gasPrice": ethermint_gas_price,
}
)
(ethermint.w3.eth.wait_for_transaction_receipt(ethermint_txhash))
return