-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: wait delays for IS, CL just 0.05s #6751
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
Changes from all commits
067aa25
71ef10a
0e9f7fb
1a5cee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1903,16 +1903,6 @@ def make_change(from_node, amount_in, amount_out, fee): | |||||||||||||||||||||||||||||||||||
| ret = {**decoded, **ret} | ||||||||||||||||||||||||||||||||||||
| return ret | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def wait_for_tx(self, txid, node, expected=True, timeout=60): | ||||||||||||||||||||||||||||||||||||
| def check_tx(): | ||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||
| self.bump_mocktime(1) | ||||||||||||||||||||||||||||||||||||
| return node.getrawtransaction(txid) | ||||||||||||||||||||||||||||||||||||
| except: | ||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||
| if self.wait_until(check_tx, timeout=timeout, sleep=1, do_assert=expected) and not expected: | ||||||||||||||||||||||||||||||||||||
| raise AssertionError("waiting unexpectedly succeeded") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def create_isdlock(self, hextx): | ||||||||||||||||||||||||||||||||||||
| tx = tx_from_hex(hextx) | ||||||||||||||||||||||||||||||||||||
| tx.rehash() | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1935,15 +1925,19 @@ def create_isdlock(self, hextx): | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return isdlock | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # due to privacy reasons random delay is used before sending transaction by network | ||||||||||||||||||||||||||||||||||||
| # most times is just 2-5 seconds, but once in 1000 it's up to 1000 seconds. | ||||||||||||||||||||||||||||||||||||
| # it's recommended to bump mocktime for 30 seconds before wait_for_instantlock | ||||||||||||||||||||||||||||||||||||
| def wait_for_instantlock(self, txid, node, expected=True, timeout=60): | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def check_instantlock(): | ||||||||||||||||||||||||||||||||||||
| self.bump_mocktime(1) | ||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||
| return node.getrawtransaction(txid, True)["instantlock"] | ||||||||||||||||||||||||||||||||||||
| except: | ||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| self.log.info(f"Expecting InstantLock for {txid}") | ||||||||||||||||||||||||||||||||||||
| if self.wait_until(check_instantlock, timeout=timeout, sleep=1, do_assert=expected) and not expected: | ||||||||||||||||||||||||||||||||||||
| if self.wait_until(check_instantlock, timeout=timeout, do_assert=expected) and not expected: | ||||||||||||||||||||||||||||||||||||
| raise AssertionError("waiting unexpectedly succeeded") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1932
to
1942
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approve the simplified wait_for_instantlock method with one improvement needed. The removal of internal mocktime bumping aligns with the PR objective to make tests more deterministic. However, the bare Apply this diff to make the exception handling more specific: - except:
+ except Exception:Or even better, catch the specific exception you expect: - except:
+ except JSONRPCException:📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.11.9)1936-1936: Do not use bare (E722) 🪛 Flake8 (7.2.0)[error] 1936-1936: do not use bare 'except' (E722) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| def wait_for_chainlocked_block(self, node, block_hash, expected=True, timeout=15): | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1954,15 +1948,15 @@ def check_chainlocked_block(): | |||||||||||||||||||||||||||||||||||
| except: | ||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||
| self.log.info(f"Expecting ChainLock for {block_hash}") | ||||||||||||||||||||||||||||||||||||
| if self.wait_until(check_chainlocked_block, timeout=timeout, sleep=0.1, do_assert=expected) and not expected: | ||||||||||||||||||||||||||||||||||||
| if self.wait_until(check_chainlocked_block, timeout=timeout, do_assert=expected) and not expected: | ||||||||||||||||||||||||||||||||||||
| raise AssertionError("waiting unexpectedly succeeded") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def wait_for_chainlocked_block_all_nodes(self, block_hash, timeout=15, expected=True): | ||||||||||||||||||||||||||||||||||||
| for node in self.nodes: | ||||||||||||||||||||||||||||||||||||
| self.wait_for_chainlocked_block(node, block_hash, expected=expected, timeout=timeout) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def wait_for_best_chainlock(self, node, block_hash, timeout=15): | ||||||||||||||||||||||||||||||||||||
| self.wait_until(lambda: node.getbestchainlock()["blockhash"] == block_hash, timeout=timeout, sleep=0.1) | ||||||||||||||||||||||||||||||||||||
| self.wait_until(lambda: node.getbestchainlock()["blockhash"] == block_hash, timeout=timeout) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def wait_for_sporks_same(self, timeout=30): | ||||||||||||||||||||||||||||||||||||
| def check_sporks_same(): | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix the bare except clause in the wait_for_tx helper method
The bare
exceptclause should be replaced with a more specific exception to improve code quality and debugging.Apply this diff to fix the exception handling:
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.11.9)
32-32: Do not use bare
except(E722)
🪛 Flake8 (7.2.0)
[error] 32-32: do not use bare 'except'
(E722)
🤖 Prompt for AI Agents