From 9cf12f138ebdcc3b68b1744ecaf93b944d534d22 Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Fri, 18 Nov 2022 08:08:32 -0800 Subject: [PATCH 1/5] split existing gas test --- tests/integration_tests/test_gas.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index ecdc8cf0d2..1b0a51e20b 100644 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -8,7 +8,7 @@ ) -def test_equivalent_gas_consumption(geth, ethermint): +def test_equivalent_gas_consumption_tx(geth, ethermint): tx_value = 10 # send a transaction with geth @@ -24,10 +24,9 @@ def test_equivalent_gas_consumption(geth, ethermint): # ensure that the gasUsed is equivalent assert geth_reciept.gasUsed == ethermint_reciept.gasUsed - w3_wait_for_new_blocks(geth.w3, 5) - w3_wait_for_new_blocks(ethermint.w3, 5) - - # repeat the above process with contract deployment +def test_equivalent_gas_consumption_deployment(geth, ethermint): + # deploy an identical contract on geth and ethermint + # ensure that the gasUsed is equivalent _, geth_contract_reciept = deploy_contract( geth.w3, CONTRACTS["TestERC20A"]) From e5c01b53d70a8bd09008d7529768af2512e70ee0 Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Fri, 18 Nov 2022 10:15:49 -0800 Subject: [PATCH 2/5] added contract call test --- .../contracts/contracts/BurnGas.sol | 13 ++++++++++++ tests/integration_tests/test_gas.py | 21 +++++++++++++++++-- tests/integration_tests/utils.py | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/integration_tests/contracts/contracts/BurnGas.sol mode change 100644 => 100755 tests/integration_tests/test_gas.py diff --git a/tests/integration_tests/contracts/contracts/BurnGas.sol b/tests/integration_tests/contracts/contracts/BurnGas.sol new file mode 100644 index 0000000000..d5bfa11ce5 --- /dev/null +++ b/tests/integration_tests/contracts/contracts/BurnGas.sol @@ -0,0 +1,13 @@ +pragma solidity >0.5.0; + +contract BurnGas { + int[] expensive; + + function burnGas(uint256 count) public { + for (uint i = 0; i < count; i++) { + unchecked { + expensive.push(10); + } + } + } +} diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py old mode 100644 new mode 100755 index 1b0a51e20b..b251a77d9a --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -8,7 +8,7 @@ ) -def test_equivalent_gas_consumption_tx(geth, ethermint): +def test_gas_eth_tx(geth, ethermint): tx_value = 10 # send a transaction with geth @@ -24,7 +24,7 @@ def test_equivalent_gas_consumption_tx(geth, ethermint): # ensure that the gasUsed is equivalent assert geth_reciept.gasUsed == ethermint_reciept.gasUsed -def test_equivalent_gas_consumption_deployment(geth, ethermint): +def test_gas_deployment(geth, ethermint): # deploy an identical contract on geth and ethermint # ensure that the gasUsed is equivalent _, geth_contract_reciept = deploy_contract( @@ -34,3 +34,20 @@ def test_equivalent_gas_consumption_deployment(geth, ethermint): ethermint.w3, CONTRACTS["TestERC20A"]) assert geth_contract_reciept.gasUsed == ethermint_contract_reciept.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 locally (eth_call) and compare gas estimates + geth_estimated_gas = geth_contract.functions.burnGas(function_input).estimate_gas() + ethermint_estimated_gas = ethermint_contract.functions.burnGas(function_input).estimate_gas() + assert geth_estimated_gas == ethermint_estimated_gas diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index d53e610d9d..69a5ca92e0 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -27,6 +27,7 @@ TEST_CONTRACTS = { "TestERC20A": "TestERC20A.sol", "Greeter": "Greeter.sol", + "BurnGas": "BurnGas.sol", } From 5f68eed7b389e55cc29ab9e933ee703d11dcf138 Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Fri, 18 Nov 2022 10:27:33 -0800 Subject: [PATCH 3/5] fix flake issues, update gomod2nix --- gomod2nix.toml | 4 ++-- tests/integration_tests/test_gas.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gomod2nix.toml b/gomod2nix.toml index 1abff848ad..1f54e90024 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-alpha7" - hash = "sha256-2wCH+toTF2A6MfFjOa13muEH5oBCcxAhZEqirNOrBA0=" + version = "v1.0.0-alpha8" + hash = "sha256-iXzXoS5Kfh5DBy+PhdFWraDWXda/3M4j7j4VECjv4CA=" [mod."github.com/cosmos/cosmos-sdk"] version = "v0.46.5-0.20221114064055-2114ec42dfa1" hash = "sha256-swqznmZfl2dlj/8ReJJs0zagFN2xpzF2ehsfVvPbohc=" diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index b251a77d9a..bc76f7c0c5 100755 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -4,7 +4,6 @@ KEYS, deploy_contract, send_transaction, - w3_wait_for_new_blocks, ) @@ -24,9 +23,10 @@ def test_gas_eth_tx(geth, ethermint): # ensure that the gasUsed is equivalent assert geth_reciept.gasUsed == ethermint_reciept.gasUsed + def test_gas_deployment(geth, ethermint): - # deploy an identical contract on geth and ethermint - # ensure that the gasUsed is equivalent + # deploy an identical contract on geth and ethermint + # ensure that the gasUsed is equivalent _, geth_contract_reciept = deploy_contract( geth.w3, CONTRACTS["TestERC20A"]) @@ -35,6 +35,7 @@ def test_gas_deployment(geth, ethermint): CONTRACTS["TestERC20A"]) assert geth_contract_reciept.gasUsed == ethermint_contract_reciept.gasUsed + def test_gas_call(geth, ethermint): function_input = 10 @@ -48,6 +49,8 @@ def test_gas_call(geth, ethermint): CONTRACTS["BurnGas"]) # call the contract locally (eth_call) and compare gas estimates - geth_estimated_gas = geth_contract.functions.burnGas(function_input).estimate_gas() - ethermint_estimated_gas = ethermint_contract.functions.burnGas(function_input).estimate_gas() + geth_estimated_gas = (geth_contract.functions + .burnGas(function_input).estimate_gas()) + ethermint_estimated_gas = (ethermint_contract.functions + .burnGas(function_input).estimate_gas()) assert geth_estimated_gas == ethermint_estimated_gas From 4918387a91336e61389e140cbed946f69ebe3470 Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Fri, 18 Nov 2022 11:11:41 -0800 Subject: [PATCH 4/5] isort imports --- tests/integration_tests/test_gas.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index bc76f7c0c5..f3a818d15a 100755 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -1,10 +1,4 @@ -from .utils import ( - ADDRS, - CONTRACTS, - KEYS, - deploy_contract, - send_transaction, -) +from .utils import ADDRS, CONTRACTS, KEYS, deploy_contract, send_transaction def test_gas_eth_tx(geth, ethermint): From 5903589a5c6e619a925a50835a03edd4decd07ef Mon Sep 17 00:00:00 2001 From: adisaran64 Date: Fri, 18 Nov 2022 12:49:37 -0800 Subject: [PATCH 5/5] add stateful contract calls --- tests/integration_tests/test_gas.py | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/integration_tests/test_gas.py b/tests/integration_tests/test_gas.py index f3a818d15a..223f681dad 100755 --- a/tests/integration_tests/test_gas.py +++ b/tests/integration_tests/test_gas.py @@ -7,27 +7,27 @@ def test_gas_eth_tx(geth, ethermint): # send a transaction with geth geth_gas_price = geth.w3.eth.gas_price tx = {"to": ADDRS["community"], "value": tx_value, "gasPrice": geth_gas_price} - geth_reciept = send_transaction(geth.w3, tx, KEYS["validator"]) + geth_receipt = send_transaction(geth.w3, tx, KEYS["validator"]) # send an equivalent transaction with ethermint ethermint_gas_price = ethermint.w3.eth.gas_price tx = {"to": ADDRS["community"], "value": tx_value, "gasPrice": ethermint_gas_price} - ethermint_reciept = send_transaction(ethermint.w3, tx, KEYS["validator"]) + ethermint_receipt = send_transaction(ethermint.w3, tx, KEYS["validator"]) # ensure that the gasUsed is equivalent - assert geth_reciept.gasUsed == ethermint_reciept.gasUsed + assert geth_receipt.gasUsed == ethermint_receipt.gasUsed def test_gas_deployment(geth, ethermint): # deploy an identical contract on geth and ethermint # ensure that the gasUsed is equivalent - _, geth_contract_reciept = deploy_contract( + _, geth_contract_receipt = deploy_contract( geth.w3, CONTRACTS["TestERC20A"]) - _, ethermint_contract_reciept = deploy_contract( + _, ethermint_contract_receipt = deploy_contract( ethermint.w3, CONTRACTS["TestERC20A"]) - assert geth_contract_reciept.gasUsed == ethermint_contract_reciept.gasUsed + assert geth_contract_receipt.gasUsed == ethermint_contract_receipt.gasUsed def test_gas_call(geth, ethermint): @@ -42,9 +42,21 @@ def test_gas_call(geth, ethermint): ethermint.w3, CONTRACTS["BurnGas"]) - # call the contract locally (eth_call) and compare gas estimates - geth_estimated_gas = (geth_contract.functions - .burnGas(function_input).estimate_gas()) - ethermint_estimated_gas = (ethermint_contract.functions - .burnGas(function_input).estimate_gas()) - assert geth_estimated_gas == ethermint_estimated_gas + # 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