From 989f406239cf134e71298f9047d2c80207be9ab7 Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Sun, 27 Nov 2022 21:51:53 -0800 Subject: [PATCH 1/9] added antehandler test --- app/ante/eth_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index ff2224e85e..1e27afa568 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -10,6 +10,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" @@ -234,6 +235,11 @@ 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, ðtypes.AccessList{{Address: addr, StorageKeys: nil}}) + tx3.From = addr.Hex() + tx3Priority := int64(1) + 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 @@ -270,6 +276,14 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { false, false, 0, }, + { + "gas limit above block gas limit", + tx3, + ethermint.BlockGasLimit(suite.ctx) + uint64(1), + func() {}, + false, false, + tx3Priority, + }, { "not enough balance for fees", tx2, From a6994c06176661b7acbcbfee2023416463eb2c5c Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Sun, 27 Nov 2022 22:47:37 -0800 Subject: [PATCH 2/9] add integration tests --- app/ante/eth_test.go | 6 ++---- tests/integration_tests/test_gas.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index 1e27afa568..21f2ec1e22 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -237,8 +237,6 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { tx3GasLimit := ethermint.BlockGasLimit(suite.ctx) + uint64(1) tx3 := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), tx3GasLimit, gasPrice, nil, nil, nil, ðtypes.AccessList{{Address: addr, StorageKeys: nil}}) - tx3.From = addr.Hex() - tx3Priority := int64(1) dynamicFeeTx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), tx2GasLimit, nil, // gasPrice @@ -279,10 +277,10 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { { "gas limit above block gas limit", tx3, - ethermint.BlockGasLimit(suite.ctx) + uint64(1), + math.MaxUint64, func() {}, false, false, - tx3Priority, + 0, }, { "not enough balance for fees", diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index ecdc8cf0d2..4019899416 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -1,3 +1,5 @@ +import pytest + from .utils import ( ADDRS, CONTRACTS, @@ -35,3 +37,20 @@ def test_equivalent_gas_consumption(geth, ethermint): ethermint.w3, CONTRACTS["TestERC20A"]) assert geth_contract_reciept.gasUsed == ethermint_contract_reciept.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") + exceededGasLimit = 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": exceededGasLimit, "gasPrice": ethermint_gas_price} + + # expect an error due to the block gas limit + with pytest.raises(Exception): + send_transaction(ethermint.w3, tx, KEYS["validator"]) From 54b9bbaff04c1dab9d26a7d2ec6cbe0fe1ad6f0d Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Sun, 27 Nov 2022 22:56:31 -0800 Subject: [PATCH 3/9] add back gas call test --- tests/integration_tests/test_gas.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index 289d036788..e1a26e7c6a 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -31,6 +31,36 @@ def test_gas_deployment(geth, ethermint): CONTRACTS["TestERC20A"]) assert geth_contract_receipt.gasUsed == ethermint_contract_receipt.gasUsed +def test_gas_call(geth, ethermint): + function_input = 10 + + # 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"]) + + # 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_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)) + + # ensure that the gasUsed is equivalent + assert geth_call_receipt.gasUsed == ethermint_call_receipt.gasUsed def test_block_gas_limit(ethermint): tx_value = 10 From e6288da509b89b23acbe48216f2b02cee2b4253b Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Sun, 27 Nov 2022 23:51:39 -0800 Subject: [PATCH 4/9] added integration tests v2 --- tests/integration_tests/test_gas.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index e1a26e7c6a..7126886806 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -31,6 +31,7 @@ def test_gas_deployment(geth, ethermint): CONTRACTS["TestERC20A"]) assert geth_contract_receipt.gasUsed == ethermint_contract_receipt.gasUsed + def test_gas_call(geth, ethermint): function_input = 10 @@ -62,6 +63,7 @@ def test_gas_call(geth, ethermint): # ensure that the gasUsed is equivalent assert geth_call_receipt.gasUsed == ethermint_call_receipt.gasUsed + def test_block_gas_limit(ethermint): tx_value = 10 @@ -72,8 +74,29 @@ def test_block_gas_limit(ethermint): # send a transaction exceeding the block gas limit ethermint_gas_price = ethermint.w3.eth.gas_price - tx = {"to": ADDRS["community"], "value": tx_value, "gas": exceededGasLimit, "gasPrice": ethermint_gas_price} + tx = {"to": ADDRS["community"], "value": tx_value, "gas": exceededGasLimit, + "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(exceededGasLimit) + .transact({'from': ADDRS["validator"], + "gas": exceededGasLimit, + "gasPrice": ethermint_gas_price})) + (ethermint.w3.eth.wait_for_transaction_receipt(ethermint_txhash)) + + +# todo: implement block gas limit being checked for sum of block transactions +# requires the ability to send batch transactions with web3.py +def test_many_block_gas_limit(ethermint): + return \ No newline at end of file From 3fae3329025264cee7fb2e0551979ded534fe1c1 Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Mon, 28 Nov 2022 00:02:24 -0800 Subject: [PATCH 5/9] linters --- tests/integration_tests/test_gas.py | 75 ++++++++++++++++------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index 7126886806..ed8d8b9113 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -1,6 +1,13 @@ import pytest -from .utils import ADDRS, CONTRACTS, KEYS, deploy_contract, send_transaction, w3_wait_for_new_blocks +from .utils import ( + ADDRS, + CONTRACTS, + KEYS, + deploy_contract, + send_transaction, + w3_wait_for_new_blocks, +) def test_gas_eth_tx(geth, ethermint): @@ -23,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 @@ -37,28 +42,24 @@ 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 @@ -66,7 +67,7 @@ def test_gas_call(geth, ethermint): 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") @@ -74,29 +75,35 @@ def test_block_gas_limit(ethermint): # send a transaction exceeding the block gas limit ethermint_gas_price = ethermint.w3.eth.gas_price - tx = {"to": ADDRS["community"], "value": tx_value, "gas": exceededGasLimit, - "gasPrice": ethermint_gas_price} + tx = { + "to": ADDRS["community"], + "value": tx_value, + "gas": exceededGasLimit, + "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"]) - + 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(exceededGasLimit) - .transact({'from': ADDRS["validator"], - "gas": exceededGasLimit, - "gasPrice": ethermint_gas_price})) + ethermint_txhash = ethermint_contract.functions.burnGas( + exceededGasLimit + ).transact( + { + "from": ADDRS["validator"], + "gas": exceededGasLimit, + "gasPrice": ethermint_gas_price, + } + ) (ethermint.w3.eth.wait_for_transaction_receipt(ethermint_txhash)) # todo: implement block gas limit being checked for sum of block transactions # requires the ability to send batch transactions with web3.py def test_many_block_gas_limit(ethermint): - return \ No newline at end of file + return From 807327e2ca398a5a7e65490be44b021c8bcc5842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:52:01 +0100 Subject: [PATCH 6/9] Update tests/integration_tests/test_gas.py --- tests/integration_tests/test_gas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index ed8d8b9113..f49f86b0a7 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -71,14 +71,14 @@ def test_block_gas_limit(ethermint): # get the block gas limit from the latest block w3_wait_for_new_blocks(ethermint.w3, 5) block = ethermint.w3.eth.get_block("latest") - exceededGasLimit = block.gasLimit + 100 + 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": exceededGasLimit, + "gas": exceeded_gas_limit, "gasPrice": ethermint_gas_price, } From b67fb6f8d801b7ccc173dfc7b70ced62cfa1201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:52:34 +0100 Subject: [PATCH 7/9] Update tests/integration_tests/test_gas.py --- tests/integration_tests/test_gas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index f49f86b0a7..72c266bb38 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -92,11 +92,11 @@ def test_block_gas_limit(ethermint): # expect an error on contract call due to block gas limit with pytest.raises(Exception): ethermint_txhash = ethermint_contract.functions.burnGas( - exceededGasLimit + exceeded_gas_limit ).transact( { "from": ADDRS["validator"], - "gas": exceededGasLimit, + "gas": exceeded_gas_limit, "gasPrice": ethermint_gas_price, } ) From 64911dce3fdb50d89b5a8e7ab8d8d11cc1dbd871 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 2 Dec 2022 13:02:15 +0100 Subject: [PATCH 8/9] update gomod2nix --- gomod2nix.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gomod2nix.toml b/gomod2nix.toml index 650e3d13a1..f09b5baeb7 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -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=" From b04c61049033e57984e5f1467966b81f7dda2e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 2 Dec 2022 13:15:54 +0100 Subject: [PATCH 9/9] Update tests/integration_tests/test_gas.py --- tests/integration_tests/test_gas.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index 72c266bb38..e35ae96cb6 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -103,7 +103,4 @@ def test_block_gas_limit(ethermint): (ethermint.w3.eth.wait_for_transaction_receipt(ethermint_txhash)) -# todo: implement block gas limit being checked for sum of block transactions -# requires the ability to send batch transactions with web3.py -def test_many_block_gas_limit(ethermint): return