Skip to content

Add test for Esplora client on Regtest #967

Open
thunderbiscuit wants to merge 2 commits intobitcoindevkit:masterfrom
thunderbiscuit:test/regtest-infinity-pro
Open

Add test for Esplora client on Regtest #967
thunderbiscuit wants to merge 2 commits intobitcoindevkit:masterfrom
thunderbiscuit:test/regtest-infinity-pro

Conversation

@thunderbiscuit
Copy link
Copy Markdown
Member

This PR brings in the regtest-toolbox library as a test dependency (not shipped with the release artifacts) in order to control a local regtest node and allow for testing clients in our CI workflows. It also brings in the Regtest Infinity Pro as a service that gets fired up before the CI runs the tests.

We are currently using this setup in bdk-jvm with success.

Using this would allow us to test clients, and better see/verify changes in the API on client PRs (for example in #965).

Notes to the reviewers

Opened as a discussion piece.

Documentation

It does not affect the public API.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing
  • I've added a changelog in the next release tracking issue (see example)
  • I've linked the relevant upstream docs or specs above

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Copy link
Copy Markdown
Collaborator

@ItoroD ItoroD left a comment

Choose a reason for hiding this comment

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

ACK 9ad254e

Loving the toolbox

regtestEnv.mine(2)

//Wait 8 second for mining to complete and for esplora to index the new blocks before scanning
delay(8.seconds)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

has 8 seconds proven to always be enough time for this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So far yes. Check this out too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes the 8 second delay is really not a clean way to do this (what if the CI is much slower than local, or the opposite? One side or another you're waiting for longer than you should and it's just overall hacky).

We used this approach to get something working and opened an issue on regtest-toolbox thinking maybe a solution could be added there, but I think @ItoroD's idea of polling the Electrum server until it sees the transaction or block is probably the best way to do this test-side.

I'll add the polling loop here and test locally between runs to see the general feel for it (maybe looping on 1/10th of a second is too much? Maybe not). But in any case I'll use that approach here, and we should clean up the JVM tests as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah the polling loop sounds cleaner, I like it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I ended up with this:

// Wait for the Esplora client to see the transaction. Try 5x per second for 20 seconds.
repeat(100) {
    if (esploraClient.getTx(txid) != null) return@repeat
    delay(200.milliseconds)
}

Which usually takes between 10 and 30 loops to complete on my machine.

Copy link
Copy Markdown
Collaborator

@ItoroD ItoroD Mar 11, 2026

Choose a reason for hiding this comment

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

LGTM!

Since this is a closed test setup it is reasonable to call 5 times per second without it being considered spamming.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is definitely a good direction, but I dont think return@repeat breaks the loop? I think it might only return from the current iteration. Maybe we switch this to a while loop or helper that exits early and fails explicitly on timeout?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

return@runBlocking breaks out of the loop.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

return@runBlocking is nice but I think it would exit the whole test body here not just the polling loop?

Copy link
Copy Markdown
Collaborator

@ItoroD ItoroD Mar 11, 2026

Choose a reason for hiding this comment

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

Ahh that's what I used in my fork test I think the reason I didn't notice was the test still said success although I have unknowingly existed the program. Blinded by success 😁. Really good catch @reez

This is what I meant to do here return run not runBlocking

@thunderbiscuit thunderbiscuit force-pushed the test/regtest-infinity-pro branch from 9ad254e to 2c7c7f6 Compare March 9, 2026 18:01
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.

3 participants