Skip to content

Add regtest CI integration test for example_bitcoind_rpc_polling#2143

Open
Brijesh-Thakkar wants to merge 1 commit intobitcoindevkit:masterfrom
Brijesh-Thakkar:feat/ci-regtest-cli-examples
Open

Add regtest CI integration test for example_bitcoind_rpc_polling#2143
Brijesh-Thakkar wants to merge 1 commit intobitcoindevkit:masterfrom
Brijesh-Thakkar:feat/ci-regtest-cli-examples

Conversation

@Brijesh-Thakkar
Copy link

Closes #1618

Adds a regtest integration test for example_bitcoind_rpc_polling that:

  • Spins up a local bitcoind regtest node via bdk_testenv
  • Initializes the example wallet
  • Mines 101 blocks to make coins spendable
  • Sends 0.05 BTC to the wallet address
  • Syncs and verifies unconfirmed balance (5,000,000 sats)
  • Mines 1 confirming block
  • Syncs and verifies confirmed balance (5,000,000 sats)
  • Lists UTXOs to confirm received output

Also adds a regtest-examples CI job to cont_integration.yml
that runs these tests on every push and pull request.

Changelog

  • example_bitcoind_rpc_polling: add regtest integration test using bdk_testenv
  • .github/workflows/cont_integration.yml: add regtest-examples CI job

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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bitcoind regtest node (via bdk_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());
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +73
let wallet_address = bdk_chain::bitcoin::Address::from_str(address_str)
.expect("valid address")
.assume_checked();
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +75
env.send(&wallet_address, Amount::from_btc(0.05).unwrap())
.expect("failed to send to wallet");
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +86 to +90
assert!(
balance_str.contains("5000000"),
"expected 5000000 sats unconfirmed, got: {}",
balance_str
);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +105 to +109
assert!(
balance_str.contains("5000000"),
"expected 5000000 sats confirmed, got: {}",
balance_str
);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +114
// 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));
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Test CLI examples using a regtest node in CI

2 participants