Add Electrum coverage and wait_until helpers#1091
Open
moisesPompilio wants to merge 5 commits into
Open
Conversation
Replaced manual waiting logic with the `wait_until` utility in the getblock, gettxout, getblockhash, getblockcount, getbestblockhash and reorg_chain tests and in the function wait_for_peers_connections in the test_framework/init.py. The `wait_until` function periodically evaluates a given predicate and returns `True` when the condition is met. If the condition is not met within the timeout, it raises an exception.
Socket reads are now optimized with a 4KB buffer instead of byte-by-byte reads, JSON-RPC error validation raises ValueError on server errors, and only the result field is returned to simplify client usage.
Tests the blockchain.block.header endpoint by validating header consistency between Electrum and RPC responses, ensuring proper error handling for out-of-range heights, and including random height validation for comprehensive coverage.
…endpoint Add new test file blockchain_block_headers.py with full test coverage for the blockchain.block.headers endpoint. The tests cover out-of-range requests, invalid parameters, valid requests across different ranges, and validation of the max count limit. Compares Electrum headers against RPC responses to ensure consistency validation. Additionally, rename the ElectrumClient method from get_headers() to block_headers()
Davidson-Souza
requested changes
Jun 2, 2026
| compare_headers(florestad, 0) | ||
| compare_headers(florestad, MINE_BLOCKS) | ||
|
|
||
| random_height = random.randint(1, MINE_BLOCKS - 1) |
Member
There was a problem hiding this comment.
randomness in tests is a big footgun, debug becomes really annoying if the test isn't reproducible
| json_rpc_res!(request, { | ||
| "count": count, | ||
| "hex": String::from_iter(headers), | ||
| "headers": headers.collect::<Vec<_>>(), |
Member
There was a problem hiding this comment.
I think this is a 1.6 change, we need to keep versioning in mind for these, see #1109
| time.sleep(1) | ||
|
|
||
| wait_until( | ||
| predicate=lambda: florestad.rpc.get_block_count() |
Member
There was a problem hiding this comment.
Perhaps you could give some specialized functions for common cases like this one?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description and Notes
This change adds integration test coverage for Electrum-related behavior, focusing on the
blockchain.block.headersandblockchain.block.headerendpoints. The new tests compare Electrum headers with RPC responses to validate consistency, while also checking error handling for invalid parameters, out-of-range requests, valid ranges, and maximum count limits. They also include random height validation to improve coverage.In addition to the Electrum tests, this change introduces
wait_untilin places where the test suite needs to wait for asynchronous conditions, such as chain synchronization or peer connection state. This replaces manual waiting logic with a reusable helper that periodically evaluates a predicate until the condition is met or a timeout is reached.Supporting changes were also made to improve the integration framework, including renaming
ElectrumClient.get_headers()toblock_headers(), changing the Electrum response key fromhextoheaders, and improving socket buffer reading and JSON-RPC error handling.How to verify the changes you have done?
blockchain.block.headersandblockchain.block.headerreturn results consistent with RPC responses.wait_untilworks correctly for asynchronous conditions such as chain synchronization and peer connection establishment.