Skip to content

test(electrum): replace electrumd with an in-process BDK wallet - #267

Open
Mohith26 wants to merge 1 commit into
Blockstream:new-indexfrom
Mohith26:test/bdk-electrum-wallet
Open

Mohith26 wants to merge 1 commit into
Blockstream:new-indexfrom
Mohith26:test/bdk-electrum-wallet

Conversation

@Mohith26

@Mohith26 Mohith26 commented Nov 4, 2026

Copy link
Copy Markdown

Closes #224.

Replaces the electrumd dev-dependency (which downloads and runs the Python Electrum wallet, Linux x86_64 only) with an in-process BDK wallet, following the plan in the issue.

What changed

  • Cargo.toml: drop electrumd and its [patch.crates-io.electrumd] section; add bdk_wallet = "3.2" and bdk_electrum = { version = "0.24.1", default-features = false } as dev-dependencies. Both use bitcoin 0.32, same as electrs, so no type conversions are needed.
  • tests/electrum.rs: WalletTester now holds a regtest BDK wallet (deterministic wpkh descriptors from a fixed seed) and a BdkElectrumClient pointed at the in-process electrs server. sync_wallet() does a full_scan through electrs and applies the update.
    • test_electrum_balance: same sequence as before (send, mine, send, mine), asserting confirmed and unconfirmed balances in sats.
    • test_electrum_history: looks transactions up by txid instead of relying on order, and checks confirmation heights (102, 103) and received amounts.
    • test_electrum_payment: builds a PSBT for 0.16 BTC with an explicit 0.001 BTC fee, signs it, broadcasts it through electrs, checks it reached bitcoind's mempool, then checks the fee and the 0.139 BTC change before and after it confirms. As the issue anticipated, BDK reports the unconfirmed change as pending rather than confirmed, so the assertion follows BDK's categories.
  • New test_electrum_subscription_notifications: BDK polls, so this covers the push path over a raw socket. It subscribes to headers and to a scripthash, then checks that notify() delivers a scripthash status change for a mempool tx, and both a new header (tip + 1) and a new status once it is mined.
  • electrumd::jsonrpc::serde_json references now use serde_json directly; the ElectrumD error variant and From<electrumd::Error> are gone from tests/common.rs.
  • The three wallet tests are now #[cfg(not(feature = "liquid"))] instead of allow(dead_code) under liquid, since the BDK types are Bitcoin-only.
  • flake.nix: removed ELECTRUMD_SKIP_DOWNLOAD and ELECTRUMD_EXE.

Testing (macOS, Apple Silicon arm64, no electrumd patch, Rust 1.96):

I haven't run it on Linux; CI should cover that.

The Electrum wallet tests drove the Python Electrum wallet through electrumd, which only builds on Linux x86_64. Use bdk_wallet + bdk_electrum against the in-process server instead, and cover the subscription push path with a raw-socket test. Closes Blockstream#224.
@shanurwan

Copy link
Copy Markdown

Tested this on Linux x86_64 (rust:1.92-bookworm container on a Rocky Linux 9 host), since the PR was tested on macOS:

  • Current new-index (4e8e6fe), with electrumd: cargo test --test electrum hangs at test_electrum_balance with dlopen(): error loading libfuse.so.2 until my 25-minute timeout. The Electrum AppImage that electrumd downloads needs FUSE, which containers usually don't have. This is the same hang I hit earlier on the electrs wallet tests.

  • This PR as is (6d99884): 12 passed, 0 failed, in 34 s, with no FUSE or Python needed.

  • This PR merged onto current new-index: two small things to update.

    1. Cargo.lock conflicts. Taking new-index's lock file and letting cargo add the BDK crates resolves it.
    2. test_electrum_broadcast_package_tx_limit (added in 4f0cb6c) still uses electrumd::jsonrpc::serde_json at tests/electrum.rs:523-524. Replacing it with serde_json, as this PR already does elsewhere, fixes the build (rustfmt then joins it onto one line).

    With those two changes: cargo test --test electrum gives 13 passed, 0 failed, and cargo test --lib gives 187 passed.

Happy to push the rebase to a branch if that's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace the electrumd dev-dependency in tests/electrum.rs with a pure-Rust wallet (BDK)

2 participants