Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

tests: add additional gas consumption tests #1477

Merged
merged 7 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
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-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="
Expand Down
13 changes: 13 additions & 0 deletions tests/integration_tests/contracts/contracts/BurnGas.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
37 changes: 25 additions & 12 deletions tests/integration_tests/test_gas.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
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


def test_equivalent_gas_consumption(geth, ethermint):
def test_gas_eth_tx(geth, ethermint):
tx_value = 10

# send a transaction with geth
Expand All @@ -24,14 +17,34 @@ 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_gas_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"])
_, ethermint_contract_reciept = deploy_contract(
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
1 change: 1 addition & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
TEST_CONTRACTS = {
"TestERC20A": "TestERC20A.sol",
"Greeter": "Greeter.sol",
"BurnGas": "BurnGas.sol",
"TestChainID": "ChainID.sol",
}

Expand Down