Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: mempool nonce logic is not tested #1734

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Changes from 1 commit
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
51 changes: 51 additions & 0 deletions integration_tests/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from web3 import Web3

from .network import setup_custom_cronos
from .utils import (

Check failure on line 7 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_mempool.py:7:1: F401 '.utils.send_transaction' imported but unused
ADDRS,
CONTRACTS,
KEYS,
deploy_contract,
send_transaction,
yihuang marked this conversation as resolved.
Show resolved Hide resolved
send_txs,
sign_transaction,
wait_for_new_blocks,
Expand Down Expand Up @@ -80,3 +81,53 @@
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):
yihuang marked this conversation as resolved.
Show resolved Hide resolved
"""
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.
yihuang marked this conversation as resolved.
Show resolved Hide resolved
"""
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
Loading