Skip to content

Add feature (parity) tests for API methods #10

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

Merged

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Sep 16, 2022

This PR adds basic feature (parity) tests for the API methods:

  • get_tx
  • get_tx_no_opt
  • get_tx_at_block_index
  • get_tx_status
  • get_header
  • get_merkle_proof
  • get_output_status
  • get_height
  • get_tip_hash
  • get_fee_estimates
  • scripthash_txs

@coveralls
Copy link

coveralls commented Sep 16, 2022

Pull Request Test Coverage Report for Build 3068063421

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 106 of 107 (99.07%) changed or added relevant lines in 3 files are covered.
  • 64 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+38.4%) to 49.045%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/lib.rs 104 105 99.05%
Files with Coverage Reduction New Missed Lines %
src/async.rs 25 44.71%
src/blocking.rs 39 28.78%
Totals Coverage Status
Change from base Build 3061069813: 38.4%
Covered Lines: 308
Relevant Lines: 628

💛 - Coveralls

@tnull tnull marked this pull request as draft September 16, 2022 13:13
@tnull tnull marked this pull request as ready for review September 16, 2022 13:48
@tnull
Copy link
Contributor Author

tnull commented Sep 16, 2022

I now covered all feasible API methods. Testing the feature parity of get_fee_estimates is not really feasible since the results vary quite a bit.

@tnull tnull force-pushed the 2022-09-add-feature-parity-tests branch 2 times, most recently from 087559c to 0624093 Compare September 16, 2022 14:19
@tnull
Copy link
Contributor Author

tnull commented Sep 16, 2022

Squashed fixups.

Copy link
Contributor

@vladimirfomene vladimirfomene left a comment

Choose a reason for hiding this comment

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

Tested ACK.

@notmandatory
Copy link
Member

Tests look good but I'd like to see if we can run the tests against a local regtest bitcoind and esplora rather than hitting the blockstream server URL. I'm going to give it a try using the electrsd crate, feel free to give it a try also, and/or when I get it working I'll show you how to do it.

@notmandatory
Copy link
Member

@tnull, @vladimirfomene has the local regtest setup working in vladimirfomene@829b2fc, I'd like to get his changes in as a setup function that all the tests can share. Then can we put each of your tests in it's own test function ? I know each test will be very small but it's a good idea for unit tests to only test a single thing, it will make it easier to read and to see if a method call fails which one it is.

@tnull
Copy link
Contributor Author

tnull commented Sep 19, 2022

@tnull, @vladimirfomene has the local regtest setup working in vladimirfomene@829b2fc, I'd like to get his changes in as a setup function that all the tests can share. Then can we put each of your tests in it's own test function ? I know each test will be very small but it's a good idea for unit tests to only test a single thing, it will make it easier to read and to see if a method call fails which one it is.

Sounds good, will add the setup function and break the test code down into individual methods!

@vladimirfomene
Copy link
Contributor

@tnull, you can find the updated code here: https://github.com/vladimirfomene/rust-esplora-client/tree/add-testing

@vladimirfomene
Copy link
Contributor

@tnull, will it help if I refactor my code into a setup function and write a couple of test functions?

@tnull
Copy link
Contributor Author

tnull commented Sep 20, 2022

@tnull, will it help if I refactor my code into a setup function and write a couple of test functions?

Don't worry. I already started making the changes, will probably push an update in the next 1-2 days.

@tnull
Copy link
Contributor Author

tnull commented Sep 21, 2022

Now split the tests and updated to run against local ElectrsD/BitcoinD instances.

@tnull tnull force-pushed the 2022-09-add-feature-parity-tests branch 3 times, most recently from d5ac02f to 4fdd176 Compare September 21, 2022 13:16
@tnull
Copy link
Contributor Author

tnull commented Sep 21, 2022

I now covered all feasible API methods. Testing the feature parity of get_fee_estimates is not really feasible since the results vary quite a bit.

Also added basic functionality testing of get_fee_estimates now.

@afilini
Copy link
Member

afilini commented Sep 22, 2022

(needs rebase because #14 changed the CI)

@tnull tnull force-pushed the 2022-09-add-feature-parity-tests branch from 4fdd176 to e390c20 Compare September 22, 2022 11:08
src/lib.rs Outdated
Comment on lines 213 to 214
let bitcoind_exe =
bitcoind::downloaded_exe_path().expect("bitcoind version feature must be enabled");
Copy link
Member

Choose a reason for hiding this comment

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

Normally we read an env variable for the bitcoind/electrsd binaries and only if that's not set we try to use the embedded one. I personally use this on nixos because the binaries downloaded by the crate don't work right out of the box, and it's just easier to have my own bitcoind/electrsd and use them

Copy link
Member

Choose a reason for hiding this comment

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

I think they are called BITCOIND_EXE and ELECTRSD_EXEin bdk

Copy link
Contributor Author

@tnull tnull Sep 22, 2022

Choose a reason for hiding this comment

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

Done in 37e2142

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now adopted the somewhat inconsistent ELECTRS_EXE naming from BDK (vs. ELECTRSD_EXE) to make it more convenient.

@tnull
Copy link
Contributor Author

tnull commented Sep 22, 2022

(needs rebase because #14 changed the CI)

Rebased on master, squashed commits, and added a minor clippy warning fix.

@tnull tnull force-pushed the 2022-09-add-feature-parity-tests branch from 1a90378 to 400676c Compare September 22, 2022 11:20
@tnull tnull force-pushed the 2022-09-add-feature-parity-tests branch 3 times, most recently from fa39cde to d1b5877 Compare September 22, 2022 12:41
@tnull
Copy link
Contributor Author

tnull commented Sep 22, 2022

Wow, clippy can be a pain 😁 . But passes CI now, squashed the fixups.

Copy link
Contributor

@vladimirfomene vladimirfomene left a comment

Choose a reason for hiding this comment

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

Tested ACK

src/lib.rs Outdated
.ok()
.or_else(|| bitcoind::downloaded_exe_path().ok())
.expect(
"you should provide env var BITCOIND_EXE or specifiy a bitcoind version feature",
Copy link
Member

Choose a reason for hiding this comment

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

nit, spelling typo

Suggested change
"you should provide env var BITCOIND_EXE or specifiy a bitcoind version feature",
"you should provide env var BITCOIND_EXE or specify a bitcoind version feature",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, fixed and directly squashed the changes.

Btw., I blatantly copied these typos from https://github.com/bitcoindevkit/bdk/blob/c3faf05be9361eb8e0afa2c066448fd10fe30b58/src/testutils/blockchain_tests.rs#L329-L340

Not sure if it warrants a PR for BDK, but if someone is already editing that file, fixing them there also might make sense.

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 d1b5877

I commented on some small spelling typos, but everything else looks great to me.

@notmandatory
Copy link
Member

If ok for everyone I'd like to get this published with Vlad on Mon or Tues so we can get a PR into bdk for the next release to remove the esplora client code there and use this crate.

@tnull tnull force-pushed the 2022-09-add-feature-parity-tests branch from d1b5877 to ee8aee0 Compare September 26, 2022 08:04
@notmandatory notmandatory merged commit 8067110 into bitcoindevkit:master Sep 26, 2022
@notmandatory notmandatory added this to the Release 0.1.0 milestone Sep 26, 2022
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.

5 participants