Skip to content

Conversation

@Kixunil
Copy link
Collaborator

@Kixunil Kixunil commented Mar 23, 2025

This is supposed to go in front of #4250

Witness lacked a bunch of APIs that were making it harder to use and test, so this also adds them in addition to cleaning up tests. (I only realized they are missing when I tried to clean up tests and got a bunch of errors.)

@Kixunil Kixunil added Tests code quality Makes code easier to understand and less likely to lead to problems API hole Important API missing - significantly degrades usability or idiomatic usage labels Mar 23, 2025
@Kixunil Kixunil requested a review from tcharding March 23, 2025 20:12
@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate C-primitives labels Mar 23, 2025
@coveralls
Copy link

coveralls commented Mar 23, 2025

Pull Request Test Coverage Report for Build 14022679486

Details

  • 42 of 85 (49.41%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 83.012%

Changes Missing Coverage Covered Lines Changed/Added Lines %
primitives/src/witness.rs 29 72 40.28%
Totals Coverage Status
Change from base Build 14012811000: -0.2%
Covered Lines: 21990
Relevant Lines: 26490

💛 - Coveralls

Kixunil added 4 commits March 23, 2025 21:22
`Witness` was missing conversions from arrays (and variations) which was
annoying when creating known-sized witnesses. These come up when
spending statically-known inputs and in tests.
Since `Witness` is semantically equivalent to `&[&[u8]]` they should
also be comparable. However we only had the impl to compare `Witness`
with itself. Being able to compare `Witness` with other containers is
particularly needed in tests.
Accessing the internals of tested object is problematic because it makes
changes to layout harder, it makes tests harder to read and it checks
implementation details rather than semantics of the API (behvaior).

We had such tests in `primitives::witness` so this changes them to use
the newly added APIs instead. However, it still leaves
`from_parts__unstable` which needs to be dealt with separately.
The `Witness`-related tests were constructing `Witness` in
over-complicated way by serializing `Vec<Vec<u8>>` and then
deserializing `Witness` even though they were not supposed to test
serialization but Taproot accessor methods. This was difficult to
understand and maintain.

This change simplifies them to just construct the `Witness` from array
of `Vec<u8>`s using the recently-added constructors. Note that we
already have serialization tests written separately so we're not losing
meaningful coverage here.
@Kixunil Kixunil force-pushed the witness-api-improvements-and-test-cleanups branch from 3f6c700 to 84bee2f Compare March 23, 2025 20:24
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 84bee2f

@tcharding
Copy link
Member

FWIW I rebase #4250 on top of this.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 84bee2f; successfully ran local tests

@apoelstra apoelstra merged commit 143531d into rust-bitcoin:master Mar 26, 2025
24 checks passed
@Kixunil Kixunil deleted the witness-api-improvements-and-test-cleanups branch March 26, 2025 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API hole Important API missing - significantly degrades usability or idiomatic usage C-bitcoin PRs modifying the bitcoin crate C-primitives code quality Makes code easier to understand and less likely to lead to problems Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants