bdk icon indicating copy to clipboard operation
bdk copied to clipboard

chore: extract `TestEnv` into separate crate

Open LagginTimes opened this issue 2 years ago • 13 comments

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 fmt and cargo clippy before committing

LagginTimes avatar Oct 12 '23 08:10 LagginTimes

The commit message does not need ().

evanlinjin avatar Oct 12 '23 08:10 evanlinjin

We need to change the internals to use electrsd so the test env can serve esplora and electrum as well.

I will look into this().

LagginTimes avatar Oct 12 '23 08:10 LagginTimes

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 avatar Oct 12 '23 22:10 vladimirfomene

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

evanlinjin avatar Oct 13 '23 06:10 evanlinjin

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.

LagginTimes avatar Nov 03 '23 20:11 LagginTimes

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

LagginTimes avatar Nov 11 '23 20:11 LagginTimes

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.

evanlinjin avatar Nov 17 '23 03:11 evanlinjin

I think you will need to do a really annoying rebase :/ sorry about that!

evanlinjin avatar Jan 31 '24 16:01 evanlinjin

This one needs a rebase after alpha.5 release.

notmandatory avatar Jan 31 '24 16:01 notmandatory

I think git is being weird, can you re-rebase on master? Make sure your remote is up to date!

evanlinjin avatar Feb 02 '24 19:02 evanlinjin

Also could you please add a simple README for bdk_testenv? Thanks!

evanlinjin avatar Feb 02 '24 20:02 evanlinjin

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

storopoli avatar Feb 15 '24 07:02 storopoli

Now that #1351 is open, I made LagginTimes/bdk#1 to test stop_gap in ElectrumExt::full_scan

ValuedMammal avatar Feb 19 '24 02:02 ValuedMammal