Commit Graph

183 Commits

Author SHA1 Message Date
Tobin C. Harding fd4586eaae
Invert dependency between io and hashes
Currently in order to release `hashes v1.0` we need to 1.0 `io` as well.
For multiple reasons, many out of our control, the `io` crate may not
stabalise any time soon.

Instead we can invert the dependency between the two crates.

This is an ingenious idea, props to Kixunil for coming up with it.

Notes

- `io` does not currently re-export the `hashes` crate.
- This work highlights that we cannot call `hash_reader` on a siphash.
- The `Hmac::hash_reader` uses the default key which may not be obvious.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2025-02-11 09:17:21 +11:00
Tobin C. Harding 9833ca32ce
primitives: Do not depend on bitcoin_io
Currently the `primitives` crate does not use the `io` dependency. I
don't know if this is just a mistake of if it used to and the manifest
is just stale.
2025-02-10 10:50:59 +11:00
merge-script a1bd90eb52
Merge rust-bitcoin/rust-bitcoin#4024: primitives: Add tests to Sequence
963dba2bdf Test sequence formatting (Jamil Lambert, PhD)
6c3d7f6443 Test Sequence properties (Jamil Lambert, PhD)

Pull request description:

  Add tests to kill the mutants found in Sequence.

ACKs for top commit:
  tcharding:
    ACK 963dba2bdf
  apoelstra:
    ACK 963dba2bdf102b2015393014d06cc56b8473520a; successfully ran local tests

Tree-SHA512: f03a02cd49df2b29232bf4f9baf663a7b51b0de504de88ae4d62de96d4e672800ac2387d0675aa48280dcbdfc0738f80484842f98b58324a09462c01956566cf
2025-02-08 15:10:46 +00:00
merge-script b70dd554be
Merge rust-bitcoin/rust-bitcoin#4018: Add missing re-exports to primitives crate root
e5c74c38a2 Add missing re-exports to primitives crate root (Jamil Lambert, PhD)

Pull request description:

  There are re-exports in the bitcoin root from primitives that were not re-exported in the primitives crate root.

  Add the missing re-exports to primitives crate root.

  First mentioned here https://github.com/rust-bitcoin/rust-bitcoin/pull/4012#discussion_r1943895283

ACKs for top commit:
  tcharding:
    ACK e5c74c38a2
  apoelstra:
    ACK e5c74c38a20e153f0919b43755d58dff8f2c8da2; successfully ran local tests

Tree-SHA512: c3355981ccd3a5db32423f6f44a6e169062c8cbce1f5e358ae2791e24801459a9db22065b83e54950dd3fd745ac4af4dcb1e1bd4625b5f25a9dd4f8fd4e6b860
2025-02-08 04:30:32 +00:00
merge-script 9aaf6ae358
Merge rust-bitcoin/rust-bitcoin#4020: primitives: Add tests to CompactTarget
b2d0737acc Add tests to CompactTarget (Jamil Lambert, PhD)

Pull request description:

  Add tests to pow.rs to kill the mutants found in CompactTarget.

ACKs for top commit:
  tcharding:
    ACK b2d0737acc
  apoelstra:
    ACK b2d0737accb998071e0f19cda6f988956b6c097a; successfully ran local tests

Tree-SHA512: 8245b2342fabb7142cc0369cc53f4213f8f685dd0ed9d357214b2f692237b3484236462a96315d2c9409625fcf59484fc505674859542311893c23e50da6ffdf
2025-02-07 21:44:22 +00:00
merge-script 9aef27a52b
Merge rust-bitcoin/rust-bitcoin#4019: primitives: Add test to opcodes
486d55f042 Add test to opcodes (Jamil Lambert, PhD)

Pull request description:

  Cargo mutant found a mutant in opcodes.

  Add a test to kill it.

ACKs for top commit:
  tcharding:
    ACK 486d55f042
  apoelstra:
    ACK 486d55f0421a05c0aaa8f883bc15cacd212dcc19; successfully ran local tests

Tree-SHA512: 8bd28d56d6e5d79a3531f0a3391ac26021f8351a77e632dcceb8a57b2f1cce05aa02ec5e37d5b5771c3a42a2a7010a241d8f232521678604cc6ecb4bdb3327a5
2025-02-07 20:11:16 +00:00
Jamil Lambert, PhD 963dba2bdf
Test sequence formatting
Add a test to kill the mutants in Sequence formatting.
2025-02-07 17:50:45 +00:00
Jamil Lambert, PhD 6c3d7f6443
Test Sequence properties
Cargo mutants found multiple mutants in the functions that return true
or false for various Sequence properties.

Add a test to kill the mutants.
2025-02-07 17:48:17 +00:00
Jamil Lambert, PhD e5c74c38a2
Add missing re-exports to primitives crate root
There are re-exports in the bitcoin root from primitives that were not
re-exported in the primitives crate root.

Add the missing re-exports to primitives crate root.
2025-02-07 08:01:46 +00:00
merge-script 21d1defced
Merge rust-bitcoin/rust-bitcoin#4011: Update example imports to use `relative::*`
a4fe67645a Use relative::* or absolute::* in locktime example (ndungudedan)

Pull request description:

  Aims to resolve #3976

  Apart from the examples in the `relative.rs` file, I see others in the **examples** folder. If this patch is good, I can continue with them.

  I will happily appreciate a review.

ACKs for top commit:
  tcharding:
    ACK a4fe67645a
  jamillambert:
    ACK a4fe67645a

Tree-SHA512: a9551c77bf91fdc212126d387adb110a7dc71635620f4efa25dc1e4306a9953968a4ad0e1528c990d5083bd9833702e62ae819db474a49f1284327fd042fb1c2
2025-02-07 06:09:16 +00:00
ndungudedan a4fe67645a
Use relative::* or absolute::* in locktime example
Users should be encouraged to explicitly use relative::* or

absolute::* instead of just LockTime, Time, or Height so that

it is clear when looking at the code if it is a relative or

absolute locktime.
2025-02-06 22:28:13 +03:00
Jamil Lambert, PhD b2d0737acc
Add tests to CompactTarget
Add tests to pow.rs to kill the mutants found in CompactTarget.
2025-02-06 17:06:41 +00:00
Jamil Lambert, PhD 486d55f042
Add test to opcodes
Cargo mutant found a mutant in opcodes.

Add a test to kill it.
2025-02-06 16:30:52 +00:00
Jamil Lambert, PhD ff3b3ddb67
Add a test for Header size
Calculate the header size and test it is equal to `Header::SIZE`
2025-02-06 14:28:22 +00:00
Jamil Lambert, PhD 0df15d5cfd
Add version test
Mutant found in Version.

Add a round trip test for version::from_consensus to kill the mutant.
2025-02-06 14:17:28 +00:00
Jamil Lambert, PhD 927251ef8e
Expand version signalling test
Add a check for max soft fork signalling bit 28
2025-02-06 14:11:07 +00:00
merge-script f81d10b2b6
Merge rust-bitcoin/rust-bitcoin#3996: Automated nightly rustfmt (2025-02-02)
282bc14d6e 2025-02-02 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK 282bc14d6e38ec78b0df01b1169b7ed42a2265cf; successfully ran local tests
  tcharding:
    ACK 282bc14d6e

Tree-SHA512: 88771b5ed72cd357e1bf0bd12d2bbe12b2bb469e667172c8ab4d7beeab46df2270471a586e9b10d7296ef62fc92f7932e4fa7da5905136a7055d42902d580ee2
2025-02-02 23:48:53 +00:00
merge-script 4e355b3843
Merge rust-bitcoin/rust-bitcoin#3987: primitives: Add `script` tests
12a1c3c4b7 Add `script` tests (Jamil Lambert, PhD)

Pull request description:

  Together with #3971 this fixes all of the mutants in `primitives/src/script` except for those related to `serde`.

ACKs for top commit:
  tcharding:
    ACK 12a1c3c4b7
  apoelstra:
    ACK 12a1c3c4b7bc097553fbfb05a0e92320ae42975c; successfully ran local tests
  Kixunil:
    ACK 12a1c3c4b7

Tree-SHA512: c0b757ae672999799e105befb6a2907b8cecb54c3e6d86dbf3e877ddf54e6fd102ebb2604381d0fa89bce0b3b4f70db6cb9ed3b5c85076e13de8369e81431926
2025-02-02 20:58:10 +00:00
Fmt Bot 282bc14d6e 2025-02-02 automated rustfmt nightly 2025-02-02 01:18:01 +00:00
merge-script bc1e3c0bfc
Merge rust-bitcoin/rust-bitcoin#3968: Add `LockTime` examples
c16eab7723 Add examples to `absolute::LockTime` (Jamil Lambert, PhD)
2d73746ad1 Improve `from_consensus` example (Jamil Lambert, PhD)
25a6742573 Add examples to `relative::LockTime` (Jamil Lambert, PhD)

Pull request description:

  To conform to API guidelines add examples to both `relative` and `absolute` `LockTime`.

  As discussed in #3967 add an example that doesn't round trip in `relative::LockTime::from_consensus`.

ACKs for top commit:
  tcharding:
    ACK c16eab7723
  apoelstra:
    ACK c16eab772375a0b8f82789a3453f7e983523fd50; successfully ran local tests

Tree-SHA512: 898db2dbcccfc54971c65bb72030505dbcfffb035aa74eb376cc1eb8d3619c205338899a58fb9f267fca192c11e7ae48fc17a2d9019c5ff4bd34bf029fa9a48f
2025-01-31 23:37:40 +00:00
Jamil Lambert, PhD 12a1c3c4b7
Add `script` tests
Add tests to kill all the mutants found by `cargo mutants` in `scripts`,
except for those related to `serde`.
2025-01-30 21:46:11 +00:00
Martin Habovstiak dd2df2bf10 Delete `TxOut::NULL`
We've stopped using `TxOut::NULL` in the code and we want to restrict
`Amount` to 21M BTC, so we are now deleting this constant without
deprecation. Deprecation can be backported if needed.
2025-01-29 23:02:51 +01:00
merge-script 98db7bca74
Merge rust-bitcoin/rust-bitcoin#3971: primitives: Add tests to `script::borrowed` and `script::owned`
6cde537d9b Add `ScriptBuf` tests (Jamil Lambert, PhD)
566a6e5da6 Add `Script` tests (Jamil Lambert, PhD)

Pull request description:

  Add tests to both `primitives/src/script/borrowed.rs` and `primitives/src/script/owned.rs` to kill the mutants found by running `cargo mutants`.

ACKs for top commit:
  tcharding:
    ACK 6cde537d9b
  apoelstra:
    ACK 6cde537d9ba9bd56495ca47afb3f9a560e9b4358; successfully ran local tests
  Kixunil:
    ACK 6cde537d9b

Tree-SHA512: fc36c1e9249753ebcb0f72e8195c85a7eccd3a0b8b3e4e753102d405494e1f72cd1cdfb6f12af41a9aa6f2ff10142b95827039fa428997b96510a5e262007b25
2025-01-29 19:20:33 +00:00
Jamil Lambert, PhD c16eab7723
Add examples to `absolute::LockTime` 2025-01-29 16:07:49 +00:00
Jamil Lambert, PhD 2d73746ad1
Improve `from_consensus` example
The existing example at first look seemed to contradict the doc above
that the function would not round trip.

Update the example to show the useage for both a time and height based
lock time.

Replace unwrap() with ?
2025-01-29 16:07:49 +00:00
Jamil Lambert, PhD 25a6742573
Add examples to `relative::LockTime` 2025-01-29 16:07:35 +00:00
Jamil Lambert, PhD 6cde537d9b
Add `ScriptBuf` tests
Add tests to `owned` to kill the mutants found by `cargo mutants`.
2025-01-28 20:31:17 +00:00
Jamil Lambert, PhD 566a6e5da6
Add `Script` tests
Add tests to `borrowed` to kill the mutants found by `cargo mutants`.
Tests for `to_bytes` were not added since it is deprecated.
2025-01-28 20:30:31 +00:00
merge-script 28b867d8de
Merge rust-bitcoin/rust-bitcoin#3966: Change `#[must_use]` to be the same as stdlib
cb5ffde9ee Change `#[must_use]` to be the same as stdlib (Jamil Lambert, PhD)

Pull request description:

  Change the iterator `#[must_use]` message to be the same as stdlib uses.

  Message taken from https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#38

  Close #3962

ACKs for top commit:
  Kixunil:
    ACK cb5ffde9ee
  tcharding:
    ACK cb5ffde9ee

Tree-SHA512: 4866d9bddccdc28e2ba2b15cb4041851abb1512cea0317f20d2e2306df6dcd1addb828d61a84a2083d3ef47abb5cf9276e857cf098de2d28b4706ecd0a1f24fa
2025-01-28 16:53:58 +00:00
Jamil Lambert, PhD cb5ffde9ee
Change `#[must_use]` to be the same as stdlib 2025-01-27 20:13:29 +00:00
Jamil Lambert, PhD bc8a378187
Rename `day_` variables to `time_`
To be consistent with similar lock height test function rename
`day_after/before` to `time_after/before` and change the same `time` to
`time_same`.
2025-01-27 16:45:24 +00:00
Jamil Lambert, PhD 922392268f
Combine satisfied by into singe tests
Include the satisfied by same time/height into the previous test that
checks above and below.
2025-01-27 16:44:41 +00:00
Jamil Lambert, PhD 33a7a35bbb
Make naming consistent in tests
Rename all occurrences of LockTime to specify if it is by height or
time.
2025-01-27 16:42:45 +00:00
Fmt Bot a3d2b2a93a 2025-01-26 automated rustfmt nightly 2025-01-26 01:16:37 +00:00
Jamil Lambert, PhD 40dc896932
Improve relative::LockTime tests
Cargo mutants found some untested mutants.

Add test cases to kill the mutants.
2025-01-23 19:29:42 +00:00
Jamil Lambert, PhD 2c73546454
Improve absolute::LockTime tests
Cargo mutants found some untested mutants.

Add test cases and refactor to improve readability.
2025-01-23 19:29:35 +00:00
Tobin C. Harding 7277092af4
Remove mutagen
Back in 2022 we elected to use `mutagen` for mutation testing. Since
then `cargo mutants` has progressed to a point where we would now like
to use it instead.

Remove all the `mutagen` stuff and update the lock files.

Close: #2829
2025-01-21 09:43:12 +11:00
Tobin C. Harding 39523ea1f5
units: Remove InputString from the public API
Currently `InputString` is in the public API of `units` because of the
trait bound on `parse::int()`. We can just do the monomorphisisation
manually to remove it.

This patch renames `int` to have three different names, one for `&str`
one for `String`, and one for `Box<str>`.
2025-01-15 08:09:38 +11:00
Fmt Bot 762f6630fe 2025-01-05 automated rustfmt nightly 2025-01-05 01:22:00 +00:00
merge-script 3b2363b2c6
Merge rust-bitcoin/rust-bitcoin#3846: Remove `test_` prefix from unit tests
85e04315d5 Remove test_ prefix from unit tests (Tobin C. Harding)

Pull request description:

  There is a loose convention in Rust to not use `test_` prefix. The reason being that `cargo test` outputs 'test <test name>' using the prefix makes the output stutter.

  This patch smells a bit like code-churn but having the prefix in some places and not others is confusing to new contributors and is leading me to explain this many times now. Lets just fix it.

  Remove the prefix unless doing so breaks the code.

ACKs for top commit:
  shinghim:
    ACK 85e04315d5
  apoelstra:
    ACK 85e04315d5eb90075ce55bf18fab8876a4583def; successfully ran local tests

Tree-SHA512: d90ae5ef75cc5e5a8f43f60819544f1a447f13cbe660ba71e84b8f27bfcc04a11d3afde0ed56e4eea5c73ebc3925024b800a1b995f73142cab892f97a414f14a
2025-01-04 00:23:46 +00:00
merge-script dddb63f4ad
Merge rust-bitcoin/rust-bitcoin#3842: Remove usage of impl_from_infallible in leaf crates
0d8e9ef096 Remove usage of impl_from_infallible in leaf crates (Tobin C. Harding)

Pull request description:

  Rust macros, while at times useful, are a maintenance nightmare. And we have been bitten by calling macros from other crates multiple times in the past.

  In a push to just use less macros remove the usage of the `impl_from_infallible` macro in all the leaf crates and just write the code.

ACKs for top commit:
  apoelstra:
    ACK 0d8e9ef096fd60fcdb7928697c8f554bf428b754; successfully ran local tests; this is a great change

Tree-SHA512: c4cff4517f7846d91142f26d451c2bcafc014a0921d11ac1487eab087449f12023c3b4fc57e1bc72ed3ea58406b4c3d24bbd846df21353f5d7ecb4a4b8bfb0b2
2025-01-03 23:42:21 +00:00
merge-script 192ea44d87
Merge rust-bitcoin/rust-bitcoin#3841: Remove macro `debug_from_display`
fd8d563b87 Remove macro debug_from_display (Tobin C. Harding)

Pull request description:

  Rust macros, while at times useful, are a maintenance nightmare. And we have been bitten by calling macros from other crates multiple times in the past.

  In a push to just use less macros remove the `debug_from_display` macro and just write the code.

  This is an API breaking change to `internals` but an internal change only to any of the _real_ crates.

ACKs for top commit:
  apoelstra:
    ACK fd8d563b873c87a996d82062285169e16e3f0c13; successfully ran local tests; this is a great change

Tree-SHA512: 26faa6645d010c1b5873d584c36d0fc52b73553d88be3226937431210ccc2479548757593b8a151936e9fa280cb3c604b241511f24ef0aa5cbf3f424d7ecf215
2025-01-03 23:01:11 +00:00
merge-script 93241c3cc8
Merge rust-bitcoin/rust-bitcoin#3838: primitives: Add core re-exports
79791e7444 primitives: Add core re-exports (Tobin C. Harding)

Pull request description:

  This is not strictly needed but we would like to copy the public macros from `units` to primitives and they use `$crate::_export` paths.

ACKs for top commit:
  apoelstra:
    ACK 79791e7444326d284bdf42c40926f6b05a6b65f7; successfully ran local tests; sure, lgtm

Tree-SHA512: cdf683041dca07bc53ae8e70806cfb74ef79e94b8699112774e3bfb3efd29cc270bd24ab03a448197edd1d143dec07d18d9a3a92d74097d87478d40954392ee4
2025-01-03 17:53:22 +00:00
Tobin C. Harding 85e04315d5
Remove test_ prefix from unit tests
There is a loose convention in Rust to not use `test_` prefix. The
reason being that `cargo test` outputs 'test <test name>' using the
prefix makes the output stutter.

This patch smells a bit like code-churn but having the prefix in some
places and not others is confusing to new contributors and is leading me
to explain this many times now. Lets just fix it.

Remove the prefix unless doing so breaks the code.
2025-01-02 10:06:50 +11:00
Tobin C. Harding 0d8e9ef096
Remove usage of impl_from_infallible in leaf crates
Rust macros, while at times useful, are a maintenance nightmare. And
we have been bitten by calling macros from other crates multiple times
in the past.

In a push to just use less macros remove the usage of the
`impl_from_infallible` macro in all the leaf crates and just write the
code.
2025-01-02 07:51:21 +11:00
Tobin C. Harding fd8d563b87
Remove macro debug_from_display
Rust macros, while at times useful, are a maintenance nightmare. And
we have been bitten by calling macros from other crates multiple times
in the past.

In a push to just use less macros remove the `debug_from_display`
macro and just write the code.

This is an API breaking change to `internals` but an internal change
only to any of the _real_ crates.
2025-01-02 07:31:13 +11:00
Tobin C. Harding 1a8f5b19fb
Update to rust-ordered 0.4.0
We just released a version of `ordered` that makes `ArbitraryOrd` object
safe - use it.

Upgrade to the latest version of `rust-ordered` - `v0.4.0`.
2024-12-31 10:42:24 +11:00
Tobin C. Harding 20b798175c
Update to latest rust-ordered
I just went to town on the `rust-ordered` crate to get it ready for
releasing a `1.0` version. None of the changes effect our usage here in
`rust-bitcoin`.

Upgrade to the latest version of `rust-ordered` - `v0.3.0`.
2024-12-30 08:35:01 +11:00
Tobin C. Harding 79791e7444
primitives: Add core re-exports
This is not strictly needed but we would like to copy the public macros
from `units` to primitives and they use `$crate::_export` paths.
2024-12-28 09:03:42 +11:00
merge-script f4069fcd61
Merge rust-bitcoin/rust-bitcoin#3780: Use uniform capitalisation of SegWit in rustdocs
e56f461916 Make capitalization of SegWit uniform in strings (Jamil Lambert, PhD)
3520e832ac Make capitalization of SegWit uniform in rustdocs (Jamil Lambert, PhD)

Pull request description:

  Fixes #3770

  - Searched and replaced all occurrences of `//` * `segwit` (case insensitive) with `//` * `SegWit`
  - Searched and replaced all occurrences of `"` * `segwit` (case insensitive) with `"` * `SegWit`

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

Tree-SHA512: c56704102d8e86f26378bb302d5fdc7ea21d41fd49f55606e589ec32ff896f1adfb1960d8fb29abccfbf298b90fc357ed609d80fd0163dcb4ff01573646b02c3
2024-12-17 18:10:44 +00:00