Skip to content

Commit

Permalink
Problem: mempool nonce logic is not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jan 17, 2025
1 parent 253338e commit 63dd7aa
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions integration_tests/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CONTRACTS,
KEYS,
deploy_contract,
send_transaction,
send_txs,
sign_transaction,
wait_for_new_blocks,
Expand Down Expand Up @@ -80,3 +81,53 @@ 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"]


def test_mempool_nonce(cronos_mempool):
"""
test the nonce logic in check-tx after new block is created.
we'll insert several transactions into mempool with increasing nonces,
the tx body is so large that they won't be included in next block at the same time,
then we'll try to send a new tx with local nonce to see if it still get accepted even if

Check failure on line 92 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_mempool.py:92:89: E501 line too long (92 > 88 characters)
check-tx state get reset.
"""
w3: Web3 = cronos_mempool.w3
cli = cronos_mempool.cosmos_cli(0)
wait_for_new_blocks(cli, 1, sleep=0.1)
sender = ADDRS["validator"]
orig_nonce = w3.eth.get_transaction_count(sender)
height = w3.eth.get_block_number()
local_nonce = orig_nonce
tx_bytes = 1000000 # can only include one tx at a time

def send_with_nonce(nonce):
tx = {
"to": ADDRS["community"],
"value": 1,
"gas": 4121000,
"data": "0x" + "00" * tx_bytes,
"nonce": nonce,
}
signed = sign_transaction(w3, tx, KEYS["validator"])
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
return txhash

for i in range(3):
txhash = send_with_nonce(local_nonce)
print(f"txhash: {txhash.hex()}")
local_nonce += 1

new_height = wait_for_new_blocks(cli, 1, sleep=0.1)
assert orig_nonce + (new_height-height) == w3.eth.get_transaction_count(sender)

Check failure on line 122 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_mempool.py:122:36: BLK100 Black would make changes.
assert orig_nonce + 3 == local_nonce

for i in range(3):
# send a new tx with the next nonce
txhash = send_with_nonce(local_nonce)
print(f"txhash: {txhash.hex()}")
local_nonce += 1

new_height = wait_for_new_blocks(cli, 1, sleep=0.1)
assert orig_nonce + (new_height-height) == w3.eth.get_transaction_count(sender)
assert orig_nonce + 4 + i == local_nonce

0 comments on commit 63dd7aa

Please sign in to comment.