tests: add additional gas consumption tests (#1477)
* split existing gas test * added contract call test * fix flake issues, update gomod2nix * isort imports * add stateful contract calls
This commit is contained in:
parent
feed84b09c
commit
be40f2bd6a
@ -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="
|
||||
|
13
tests/integration_tests/contracts/contracts/BurnGas.sol
Normal file
13
tests/integration_tests/contracts/contracts/BurnGas.sol
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
61
tests/integration_tests/test_gas.py
Normal file → Executable file
61
tests/integration_tests/test_gas.py
Normal file → Executable file
@ -1,37 +1,62 @@
|
||||
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
|
||||
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
|
||||
|
||||
w3_wait_for_new_blocks(geth.w3, 5)
|
||||
w3_wait_for_new_blocks(ethermint.w3, 5)
|
||||
|
||||
# repeat the above process with contract deployment
|
||||
_, geth_contract_reciept = deploy_contract(
|
||||
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"])
|
||||
_, 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):
|
||||
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
|
||||
|
@ -27,6 +27,7 @@ ETHERMINT_ADDRESS_PREFIX = "ethm"
|
||||
TEST_CONTRACTS = {
|
||||
"TestERC20A": "TestERC20A.sol",
|
||||
"Greeter": "Greeter.sol",
|
||||
"BurnGas": "BurnGas.sol",
|
||||
"TestChainID": "ChainID.sol",
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user