Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extract TestEnv into separate crate #1171

Merged
merged 5 commits into from Mar 23, 2024

Conversation

LagginTimes
Copy link
Contributor

@LagginTimes LagginTimes commented Oct 12, 2023

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:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

@evanlinjin

This comment was marked as resolved.

@LagginTimes LagginTimes changed the title chore(): extract TestEnv into separate crate chore: extract TestEnv into separate crate Oct 12, 2023
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

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

Can use #979 as a reference to see what electrum-server methods we need.

@LagginTimes
Copy link
Contributor Author

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

@vladimirfomene
Copy link
Contributor

vladimirfomene commented Oct 12, 2023

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.

@evanlinjin
Copy link
Member

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

@LagginTimes LagginTimes marked this pull request as draft October 15, 2023 15:55
@LagginTimes LagginTimes force-pushed the extract_testenv branch 2 times, most recently from 50c5ccd to 12403a1 Compare October 17, 2023 09:59
@LagginTimes LagginTimes marked this pull request as ready for review October 17, 2023 11:43
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

Thanks for taking this forward. The code looks pretty good.

The documentation was a little lacking. It's important to communicate why things are implemented the way they are.

crates/bitcoind_rpc/tests/test_emitter.rs Outdated Show resolved Hide resolved
crates/bitcoind_rpc/tests/test_emitter.rs Outdated Show resolved Hide resolved
crates/bitcoind_rpc/Cargo.toml Outdated Show resolved Hide resolved
crates/testenv/src/lib.rs Outdated Show resolved Hide resolved
crates/testenv/src/lib.rs Show resolved Hide resolved
crates/testenv/src/lib.rs Show resolved Hide resolved
@nondiremanuel nondiremanuel added this to the 1.0.0-beta.0 milestone Oct 24, 2023
@LagginTimes
Copy link
Contributor Author

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

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 LagginTimes force-pushed the extract_testenv branch 2 times, most recently from 6bb1a40 to cc50303 Compare November 12, 2023 00:14
danielabrozzoni added a commit that referenced this pull request Nov 13, 2023
1010efd fix(electrum): fixed chain sync issue (Wei Chen)

Pull request description:

  ### Description

  This may or may not fix #1125.
  Fixed what appeared to be a logic error in `construct_update_tip` in `electrum_ext.rs` that caused the local chain tip to always be a block behind the newest confirmed block.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  danielabrozzoni:
    ACK 1010efd - although I've been able to reproduce the issue in #1125, I'm convinced that this PR fixes at least a bug, as demonstrated in #1171 (yet to be reviewed and merged).

Tree-SHA512: 92790e9072d17be74d2cd24bec3503e1ad5d97f728ee81490eeb09ac3f8d4a3a7e8d9628e943bc801246d5bfd345152c11d5dbe25246f5a57b3118727d3ae315
@storopoli
Copy link
Contributor

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

@ValuedMammal
Copy link
Contributor

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

Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK 2903697

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

Overall looks like a great improvement, related tests are much easier to read too. I just have one comment/question about a CI change.

.github/workflows/nightly_docs.yml Show resolved Hide resolved
crates/testenv/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@storopoli storopoli left a comment

Choose a reason for hiding this comment

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

ACK e8dc8d3

Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

Overall looks pretty good!

I just left one minor comment about the documentation that I was uncertain about, and a general question for further discussion.

crates/electrum/tests/test_electrum.rs Outdated Show resolved Hide resolved
@@ -744,7 +624,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
// emission.
// TODO: How can have have reorg logic in `TestEnv` NOT blacklast old blocks first?
Copy link
Contributor

Choose a reason for hiding this comment

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

@LagginTimes general question: after this PR is merged, do you think we'll be able to solve this TODO ?

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately no. This can be done in a follow-up PR!

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, thanks!

`TestEnv` is extracted into its own crate to serve as a framework
for testing other block explorer APIs.
Added scan and reorg tests to check electrum functionality using
`TestEnv`.
Comment on lines 27 to 28
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
electrsd = { version= "0.25.0", features = ["bitcoind_25_0", "esplora_a33e97e1", "legacy"] }
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to make the tests run in WASM? Because electrsd is a mandatory dependency of bdk_testenv.

Copy link
Member

Choose a reason for hiding this comment

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

Right now for CI we only do a cargo check for WASM and don't rerun the tests for that target. Since I haven't heard of any WASM issues that slipped through by not running the tests I don't think we need to change TestEnv to work with WASM.

Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

ACK 04d0ab5

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK 04d0ab5

Great job, this will be a big help with testing.

Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK 7c9ba3c

@evanlinjin evanlinjin merged commit 80e190b into bitcoindevkit:master Mar 23, 2024
12 checks passed
@evanlinjin evanlinjin mentioned this pull request Mar 23, 2024
3 tasks
@notmandatory notmandatory mentioned this pull request Mar 26, 2024
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

10 participants