Add regtest CI integration test for example_bitcoind_rpc_polling#2143
Add regtest CI integration test for example_bitcoind_rpc_polling#2143Brijesh-Thakkar wants to merge 1 commit intobitcoindevkit:masterfrom
Conversation
Adds a regtest integration test for the example_bitcoind_rpc_polling binary. The test spins up a local bitcoind node using bdk_testenv, initializes the example wallet, sends funds, syncs, and verifies confirmed and unconfirmed balances. Also adds a new CI job 'regtest-examples' that runs these tests on every push and pull request. Closes bitcoindevkit#1618
There was a problem hiding this comment.
Pull request overview
Adds CI coverage for running the example_bitcoind_rpc_polling CLI against a real regtest node, validating that the example can initialize, sync, detect incoming funds, and display UTXOs in an automated environment.
Changes:
- Add a regtest integration test that spawns a local
bitcoindregtest node (viabdk_testenv) and drives the example binary end-to-end. - Add dev-dependencies required for the new integration test (
bdk_testenv,tempfile). - Add a dedicated GitHub Actions job to run the regtest example test on every push/PR.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| examples/example_bitcoind_rpc_polling/tests/regtest.rs | New end-to-end regtest test driving the example binary (init/address/sync/balance/txout). |
| examples/example_bitcoind_rpc_polling/Cargo.toml | Adds dev-dependencies needed to run the regtest integration test. |
| .github/workflows/cont_integration.yml | Adds a regtest-examples CI job to run the new test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let env = TestEnv::new().expect("failed to create testenv"); | ||
| let tmp = tempfile::tempdir().expect("failed to create tempdir"); | ||
|
|
||
| let rpc_url = format!("127.0.0.1:{}", env.bitcoind.params.rpc_socket.port()); |
There was a problem hiding this comment.
rpc_url is manually constructed from the port only. electrsd::corepc_node::Node already exposes rpc_url() (used elsewhere in the repo) which avoids mismatches (e.g., missing http:// scheme or non-local bind addresses). Prefer using env.bitcoind.rpc_url() here for the client URL.
| let wallet_address = bdk_chain::bitcoin::Address::from_str(address_str) | ||
| .expect("valid address") | ||
| .assume_checked(); |
There was a problem hiding this comment.
Address::from_str(...).assume_checked() bypasses network validation. Since the test expects a regtest address, require the network (e.g., require_network(regtest)), so the test fails if the CLI ever prints an address for the wrong network.
| env.send(&wallet_address, Amount::from_btc(0.05).unwrap()) | ||
| .expect("failed to send to wallet"); |
There was a problem hiding this comment.
Using Amount::from_btc(0.05) relies on float parsing and unwrap(). For deterministic tests, prefer using satoshis directly (e.g., Amount::from_sat(5_000_000)) and avoid the unwrap failure mode.
| assert!( | ||
| balance_str.contains("5000000"), | ||
| "expected 5000000 sats unconfirmed, got: {}", | ||
| balance_str | ||
| ); |
There was a problem hiding this comment.
The balance assertion uses contains("5000000"), which can produce false positives (e.g., 50000000 also matches). Consider parsing the numeric field(s) from the balance output and asserting exact values (and ideally also that confirmed is 0 at this stage).
| assert!( | ||
| balance_str.contains("5000000"), | ||
| "expected 5000000 sats confirmed, got: {}", | ||
| balance_str | ||
| ); |
There was a problem hiding this comment.
Same issue as above: contains("5000000") can pass even if the amount is wrong but includes that substring. Parse and assert the exact confirmed/unconfirmed totals to make this test reliably detect regressions.
| // 10. List txouts - should show our received utxo | ||
| let out = run_cmd(&["txout", "list"], &rpc_url, cookie, tmp.path()); | ||
| assert_cmd_success(&out, "txout list"); | ||
| println!("txout list:\n{}", String::from_utf8_lossy(&out.stdout)); |
There was a problem hiding this comment.
The txout list step only prints output; it doesn't assert that the expected UTXO (value/address/outpoint) is present. Adding an assertion here would make the test actually verify the behavior described in the PR (listing the received output).
Closes #1618
Adds a regtest integration test for
example_bitcoind_rpc_pollingthat:bdk_testenvAlso adds a
regtest-examplesCI job tocont_integration.ymlthat runs these tests on every push and pull request.
Changelog
example_bitcoind_rpc_polling: add regtest integration test usingbdk_testenv.github/workflows/cont_integration.yml: addregtest-examplesCI job