chore: extract `TestEnv` into separate crate
Description
TestEnv is extracted into its own crate with electrsd support added so that TestEnv can also serve esplora and electrum.
The tests in the esplora crate have also been updated to use TestEnv.
The tx_can_become_unconfirmed_after_reorg() test in test_electrum suggests that the electrum issue where a reorged tx would be stuck at confirmed does not exist anymore.
Notes to the reviewers
The code for tx_can_become_unconfirmed_after_reorg() was adapted from the same test in bitcoind_rpc/test_emitter. This electrum version of the test requires extra review, as I am uncertain if I used the API efficiently.
All Submissions:
- [x] I've signed all my commits
- [x] I followed the contribution guidelines
- [x] I ran
cargo fmtandcargo clippybefore committing
The commit message does not need ().
We need to change the internals to use
electrsdso the test env can serveesploraandelectrumas well.
I will look into this().
I think having reorg functions for all backends will help. I had to use a hack from Steve to implement reorg for electrum. You should see the code in #979. Read more here: https://bitcoin.stackexchange.com/questions/114044/how-can-i-simulate-a-reorg-for-testing.
@vladimirfomene that's a great point.
https://github.com/bitcoindevkit/bdk/blob/release/0.29/src/testutils/blockchain_tests.rs
Maybe the old testutils is something to base this work on.
A simple electrsd reorg test was written and runs without having to pass in bitcoinD references to mine_blocks() and reorg(). I have therefore removed the extraneous bitcoind input parameters from TestEnv. Will have this commit sorted out tomorrow.
A test_chain_sync() test has been added that reproduces the issue described in #1125 and also confirms that the fix in #1145 at least partially fixes the problem (in that there may be additional bugs as seen by @danielabrozzoni).
In terms of commit-hygiene, I think this PR should be at least two commits. One for extracting the TestEnv, one for introducing the electrum tests.
I think you will need to do a really annoying rebase :/ sorry about that!
This one needs a rebase after alpha.5 release.
I think git is being weird, can you re-rebase on master? Make sure your remote is up to date!
Also could you please add a simple README for bdk_testenv? Thanks!
I know that we're testing it in other crates.
But do we plan to expose this in the future?
If yes, I think we should add tests for the test_env crate (I know that this sounds like an oxymoron, but bear with me ...)
Now that #1351 is open, I made LagginTimes/bdk#1 to test stop_gap in ElectrumExt::full_scan