From 14b147f2d431fa8640d2a6eb4bbdf248f574cdf3 Mon Sep 17 00:00:00 2001 From: huangyi Date: Mon, 2 Sep 2024 11:52:19 +0800 Subject: [PATCH] test tx replacement --- integration_tests/test_mempool.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/integration_tests/test_mempool.py b/integration_tests/test_mempool.py index bdd921cab1..f70c663e49 100644 --- a/integration_tests/test_mempool.py +++ b/integration_tests/test_mempool.py @@ -80,3 +80,37 @@ def test_blocked_address(cronos_mempool): rsp = cli.transfer("signer1", cli.address("validator"), "1basecro") assert rsp["code"] != 0 assert "signer is blocked" in rsp["raw_log"] + + +@pytest.mark.flaky(max_runs=5) +def test_tx_replacement(cronos_mempool): + w3: Web3 = cronos_mempool.w3 + account = "community" + nonce = w3.eth.get_transaction_count(ADDRS[account]) + gas_price = w3.eth.gas_price + reduction = 1000000 + # the second tx should replace the first tx with higher priority, + # but the third one shouldn't replace the second one. + prices = [ + gas_price, + gas_price + 2 * reduction, + gas_price + reduction, + ] + txs = [ + sign_transaction( + w3, + { + "to": ADDRS[account], + "value": 1, + "gas": 21000, + "gasPrice": price, + "nonce": nonce, + }, + KEYS[account], + ) + for price in prices + ] + + txhashes = [w3.eth.send_raw_transaction(tx.rawTransaction) for tx in txs] + receipt = w3.eth.wait_for_transaction_receipt(txhashes[1]) + assert receipt.status == 1