Commit 2c64de05 authored by Piotr Piwoński's avatar Piotr Piwoński Committed by GitHub

fix: `get_transaction_count` does not count pending transactions (#299)

Fix a few issues resulting from merge and display errors properly
parent a1ce72aa
...@@ -26,6 +26,7 @@ SENDER = os.getenv("SENDER_PRIVATE_KEY", "17fdf89989597e8bcac6cdfcc001b6241c64ce ...@@ -26,6 +26,7 @@ SENDER = os.getenv("SENDER_PRIVATE_KEY", "17fdf89989597e8bcac6cdfcc001b6241c64ce
RECEIVER = os.getenv("RECEIVER_PUBLIC_KEY", "0x878705ba3f8Bc32FCf7F4CAa1A35E72AF65CF766") RECEIVER = os.getenv("RECEIVER_PUBLIC_KEY", "0x878705ba3f8Bc32FCf7F4CAa1A35E72AF65CF766")
EL_URI = os.getenv("EL_RPC_URI", 'http://0.0.0.0:53913') EL_URI = os.getenv("EL_RPC_URI", 'http://0.0.0.0:53913')
def send_transaction(): def send_transaction():
# Setting w3 as constant causes recursion exceeded error after ~500 transactions # Setting w3 as constant causes recursion exceeded error after ~500 transactions
# Thus it's created everytime a transaction is sent # Thus it's created everytime a transaction is sent
...@@ -40,9 +41,10 @@ def send_transaction(): ...@@ -40,9 +41,10 @@ def send_transaction():
"to": RECEIVER, "to": RECEIVER,
"data": "0xabcd", "data": "0xabcd",
"gasPrice": w3.eth.gas_price, "gasPrice": w3.eth.gas_price,
"nonce": w3.eth.get_transaction_count(sender_account.address)
} }
estimated_gas = w3.eth.estimate_gas(transaction)
transaction["gas"] = estimated_gas transaction["gas"] = estimated_gas
tx_hash = w3.eth.send_transaction(transaction) tx_hash = w3.eth.send_transaction(transaction)
...@@ -51,6 +53,7 @@ def send_transaction(): ...@@ -51,6 +53,7 @@ def send_transaction():
logging.info(tx_hash.hex()) logging.info(tx_hash.hex())
assert tx["from"] == sender_account.address assert tx["from"] == sender_account.address
def delayed_send(interval_between_transactions): def delayed_send(interval_between_transactions):
send_transaction() send_transaction()
time.sleep(interval_between_transactions) time.sleep(interval_between_transactions)
...@@ -65,7 +68,7 @@ def run_infinitely(interval_between_transactions): ...@@ -65,7 +68,7 @@ def run_infinitely(interval_between_transactions):
try: try:
spam() spam()
except Exception as e: except Exception as e:
print("e") print(e)
print("restarting flood as previous one failed") print("restarting flood as previous one failed")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment