Skip to content

WIP: Tests for API surface of primitives#3992

Closed
rockcoolsaint wants to merge 2 commits intorust-bitcoin:masterfrom
rockcoolsaint:primitives-API-test-module
Closed

WIP: Tests for API surface of primitives#3992
rockcoolsaint wants to merge 2 commits intorust-bitcoin:masterfrom
rockcoolsaint:primitives-API-test-module

Conversation

@rockcoolsaint
Copy link
Copy Markdown
Contributor

@rockcoolsaint rockcoolsaint commented Jan 31, 2025

Please help review if the following changes are inline with the objectives of this issue

Resolves #3928

@rockcoolsaint rockcoolsaint marked this pull request as draft January 31, 2025 23:24
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 13082433226

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.292%

Totals Coverage Status
Change from base Build 13081092118: 0.0%
Covered Lines: 21032
Relevant Lines: 25251

💛 - Coveralls

@rockcoolsaint rockcoolsaint changed the title Tests for API surface of primitives WIP: Tests for API surface of primitives Jan 31, 2025
@tcharding
Copy link
Copy Markdown
Member

Yes you are on the right track. While reviewing I noticed that it was not trivial to check the imports tested here against the ones done in units/tests/api.rs - perhaps this layout would be better (note I had to rustfmt::skip to keep the comments in the.

#[test]
fn api_can_use_all_types_from_module_block() {
    {
        // New types added in `primitives`.
        use bitcoin_primitives::block::{
            Block, BlockHash, Checked, Header, Unchecked, Version, WitnessCommitment,
        };
    }
    {
        // Re-exports from `units` - `primitives` module layout should mimic `units`.
        use bitcoin_primitives::block::{
            BlockHeight, BlockInterval, TooBigForRelativeBlockHeightError,
        };
    }
}

@rockcoolsaint
Copy link
Copy Markdown
Contributor Author

Yes you are on the right track. While reviewing I noticed that it was not trivial to check the imports tested here against the ones done in units/tests/api.rs - perhaps this layout would be better (note I had to rustfmt::skip to keep the comments in the.

#[test]
fn api_can_use_all_types_from_module_block() {
    {
        // New types added in `primitives`.
        use bitcoin_primitives::block::{
            Block, BlockHash, Checked, Header, Unchecked, Version, WitnessCommitment,
        };
    }
    {
        // Re-exports from `units` - `primitives` module layout should mimic `units`.
        use bitcoin_primitives::block::{
            BlockHeight, BlockInterval, TooBigForRelativeBlockHeightError,
        };
    }
}

Is there any reason why the primitives module should mimic the units but not the other way around?

@apoelstra
Copy link
Copy Markdown
Member

Yes, because primitives depends on units but not the other way around.

Modules and data type API surface tests to ensure that the public API
of the primitives library remains stable and adheres to best practices
@rockcoolsaint
Copy link
Copy Markdown
Contributor Author

Some structs like TapBranchTag that don't // All public types implement Debug (C-DEBUG). should not be considered in the primitives API surface, am I right?
@tcharding @apoelstra

@rockcoolsaint
Copy link
Copy Markdown
Contributor Author

rockcoolsaint commented Feb 26, 2025

Some structs like TapBranchTag that don't // All public types implement Debug (C-DEBUG). should not be considered in the primitives API surface, am I right? @tcharding @apoelstra

I currently get the following error when I include such structs

`TapBranchTag` doesn't implement `Debug`
the trait `Debug` is not implemented for `TapBranchTag`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic message [1]?1#file:///home/innocent/Documents/qala/deliverables/rust-bitcoin/primitives/tests/api.rs)
api.rs(40, 10): Error originated from macro call here
bitcoin_primitives::taproot
pub struct TapBranchTag

Or alternatively, is it necessary to implement the Debug trait manually?

@rockcoolsaint rockcoolsaint force-pushed the primitives-API-test-module branch from c8d1e8e to 005f72e Compare February 26, 2025 12:01
@rockcoolsaint
Copy link
Copy Markdown
Contributor Author

Some structs like TapBranchTag that don't // All public types implement Debug (C-DEBUG). should not be considered in the primitives API surface, am I right? @tcharding @apoelstra

I currently get the following error when I include such structs

`TapBranchTag` doesn't implement `Debug`
the trait `Debug` is not implemented for `TapBranchTag`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic message [1]?1#file:///home/innocent/Documents/qala/deliverables/rust-bitcoin/primitives/tests/api.rs)
api.rs(40, 10): Error originated from macro call here
bitcoin_primitives::taproot
pub struct TapBranchTag

Or alternatively, is it necessary to implement the Debug trait manually?

@apoelstra @tcharding

@apoelstra
Copy link
Copy Markdown
Member

cc @Kixunil shouldn't we just put the Debug bound on all the tag types so that we can do this derive?

apoelstra added a commit that referenced this pull request May 9, 2025
e2d9a8a primitives: Add an API test module (Tobin C. Harding)
8ec2d35 primitives: Derive Clone on witness::Iter (Tobin C. Harding)

Pull request description:

  In preparation for 1.0-ing `primitives` add an `api` test module that makes an effort to verify the API surface.

  This is similar to what is in `units` and what is in development for `hashes` (in #4017).

  Note, there is a WIP attempt at this in #3992.

  Close: #3928

ACKs for top commit:
  apoelstra:
    ACK e2d9a8a; successfully ran local tests

Tree-SHA512: 5ec5c87c9aa5e86e579283a5485dcb2b3b5ae59359ae5ab96f8e6634285072bef0d0f111b6780852fd88fe29677f1a84c791a3343a0cb2b09093e77125f3962b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

primitives: Add an API test module

4 participants