From 58085b5822365ea9988ec46e801b4db1a7770016 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 11 Mar 2022 09:55:18 +0800 Subject: [PATCH] Problem: tx inclusion logic when block gas limit exceeded is not tested (#380) Closes: #379 Solution: - add integration test to test tx inclusion logic when block gas limit exceeded. --- integration_tests/test_basic.py | 36 +++++++++++++++++++++++++++++++ integration_tests/test_upgrade.py | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 5bc1f724ba..ac4bf02c22 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -598,3 +598,39 @@ def test_contract(cronos): # call contract greeter_call_result = contract.caller.greet() assert "world" == greeter_call_result + + +def test_tx_inclusion(cronos): + """ + - send multiple heavy transactions at the same time. + - check they are included in consecutively blocks without failure. + """ + w3 = cronos.w3 + # bigger than block_gas_limit/2, so at most one tx in a block + tx_gas_limit = 80000000 + amount = 1000 + # use different sender accounts to be able be send concurrently + signed_txs = [] + for account in ["validator", "community", "signer1", "signer2"]: + signed_txs.append( + sign_transaction( + w3, + { + "to": ADDRS["validator"], + "value": amount, + "gas": tx_gas_limit, + }, + KEYS[account], + ) + ) + + for signed in signed_txs: + w3.eth.send_raw_transaction(signed.rawTransaction) + + receipts = [ + w3.eth.wait_for_transaction_receipt(signed.hash) for signed in signed_txs + ] + + # the transactions should be included in differnt but consecutive blocks + for receipt, next_receipt in zip(receipts, receipts[1:]): + assert next_receipt.blockNumber == receipt.blockNumber + 1 diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 2ec4f3df4b..3e0daa9c97 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -36,7 +36,7 @@ def post_init(path, base_port, config): ini_path = path / chain_id / SUPERVISOR_CONFIG_FILE ini = configparser.RawConfigParser() ini.read_file(ini_path.open()) - reg = re.compile(fr"^program:{chain_id}-node(\d+)") + reg = re.compile(rf"^program:{chain_id}-node(\d+)") for section in ini.sections(): m = reg.match(section) if m: