Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/server/config"
"github.com/evmos/ethermint/tests"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"

Expand Down Expand Up @@ -180,6 +181,9 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2.From = addr.Hex()
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,
nil, // gasPrice
new(big.Int).Add(baseFee, big.NewInt(evmtypes.DefaultPriorityReduction.Int64()*2)), // gasFeeCap
Expand Down Expand Up @@ -216,6 +220,14 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
false, false,
0,
},
{
"gas limit above block gas limit",
tx3,
math.MaxUint64,
func() {},
false, false,
0,
},
{
"not enough balance for fees",
tx2,
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ schema = 3
version = "v1.0.4"
hash = "sha256-JvcBXBdjdmnaW/nyf/tw/uaOAGn1b78yxrtl2/Rs3kA="
[mod."github.com/cosmos/cosmos-proto"]
version = "v1.0.0-alpha8"
hash = "sha256-iXzXoS5Kfh5DBy+PhdFWraDWXda/3M4j7j4VECjv4CA="
version = "v1.0.0-beta.1"
hash = "sha256-oATkuj+fM5eBn+ywO+w/tL0AFSIEkx0J3Yz+VhVe0QA="
[mod."github.com/cosmos/cosmos-sdk"]
version = "v0.46.6"
hash = "sha256-H1VZxZUWXhpXiY3A9smLp09MEGpXmh+XvX6YUiXPcpQ="
Expand Down
86 changes: 65 additions & 21 deletions tests/integration_tests/test_gas.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -21,12 +30,10 @@ def test_gas_eth_tx(geth, ethermint):
def test_gas_deployment(geth, ethermint):
# deploy an identical contract on geth and ethermint
# ensure that the gasUsed is equivalent
_, geth_contract_receipt = deploy_contract(
geth.w3,
CONTRACTS["TestERC20A"])
_, geth_contract_receipt = deploy_contract(geth.w3, CONTRACTS["TestERC20A"])
_, ethermint_contract_receipt = deploy_contract(
ethermint.w3,
CONTRACTS["TestERC20A"])
ethermint.w3, CONTRACTS["TestERC20A"]
)
assert geth_contract_receipt.gasUsed == ethermint_contract_receipt.gasUsed


Expand All @@ -35,28 +42,65 @@ def test_gas_call(geth, ethermint):

# deploy an identical contract on geth and ethermint
# ensure that the contract has a function which consumes non-trivial gas
geth_contract, _ = deploy_contract(
geth.w3,
CONTRACTS["BurnGas"])
ethermint_contract, _ = deploy_contract(
ethermint.w3,
CONTRACTS["BurnGas"])
geth_contract, _ = deploy_contract(geth.w3, CONTRACTS["BurnGas"])
ethermint_contract, _ = deploy_contract(ethermint.w3, CONTRACTS["BurnGas"])

# call the contract and get tx receipt for geth
geth_gas_price = geth.w3.eth.gas_price
geth_txhash = (geth_contract.functions
.burnGas(function_input)
.transact({'from': ADDRS["validator"], "gasPrice": geth_gas_price}))
geth_txhash = geth_contract.functions.burnGas(function_input).transact(
{"from": ADDRS["validator"], "gasPrice": geth_gas_price}
)
geth_call_receipt = geth.w3.eth.wait_for_transaction_receipt(geth_txhash)

# repeat the above for ethermint
ethermint_gas_price = ethermint.w3.eth.gas_price
ethermint_txhash = (ethermint_contract.functions
.burnGas(function_input)
.transact({'from': ADDRS["validator"],
"gasPrice": ethermint_gas_price}))
ethermint_call_receipt = (ethermint.w3.
eth.wait_for_transaction_receipt(ethermint_txhash))
ethermint_txhash = ethermint_contract.functions.burnGas(function_input).transact(
{"from": ADDRS["validator"], "gasPrice": ethermint_gas_price}
)
ethermint_call_receipt = ethermint.w3.eth.wait_for_transaction_receipt(
ethermint_txhash
)

# ensure that the gasUsed is equivalent
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