Skip to content

Fix deserialization#188

Merged
apoelstra merged 1 commit intorust-bitcoin:masterfrom
A-Manning:2025-08-12-fix-serde
Aug 17, 2025
Merged

Fix deserialization#188
apoelstra merged 1 commit intorust-bitcoin:masterfrom
A-Manning:2025-08-12-fix-serde

Conversation

@A-Manning
Copy link
Contributor

@A-Manning A-Manning commented Aug 12, 2025

Fixes #189.

The changes in src/display.rs and src/iter.rs were necessary, since using serde_json in tests brings an impl PartialEq<serde_json::Value> for usize into context, which makes some code in the aforementioned tests ambiguous without explicitly specifying types

@apoelstra
Copy link
Member

I think the version of serde_json in Cargo.lock (and Cargo.toml) is too old.

@A-Manning A-Manning force-pushed the 2025-08-12-fix-serde branch from 8e926de to 594983c Compare August 12, 2025 16:03
@A-Manning
Copy link
Contributor Author

A-Manning commented Aug 12, 2025

I think the version of serde_json in Cargo.lock (and Cargo.toml) is too old.

Fixed

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 594983c

@tcharding
Copy link
Member

To get past CI you'll need to run 'just update-lock-files' and force push please.

@tcharding
Copy link
Member

I had play with your tests, perhaps this is cleaner?

#[cfg(test)]
mod test {
    use serde_json::value::Serializer;

    use super::*;

    #[test]
    fn serialize_lower_roundtrip() {
        let bytes: [u8; 4] = [0xdeu8, 0xad, 0xbe, 0xef];

        let serialized = serialize_lower(&bytes, Serializer).expect("serialize");
        let deserialized: [u8; 4] = deserialize(serialized).expect("deserialize");

        assert_eq!(deserialized, bytes);
    }

    #[test]
    fn serialize_upper_roundtrip() {
        let bytes: [u8; 4] = [0xdeu8, 0xad, 0xbe, 0xef];

        let serialized = serialize_upper(&bytes, Serializer).expect("serialize");
        let deserialized: [u8; 4] = deserialize(serialized).expect("deserialize");

        assert_eq!(deserialized, bytes);
    }
}

@tcharding
Copy link
Member

And thanks for the contribution, and for finding our (my) bugs!

@tcharding tcharding mentioned this pull request Aug 12, 2025
@A-Manning A-Manning force-pushed the 2025-08-12-fix-serde branch from 594983c to e1fa1d8 Compare August 13, 2025 07:36
@A-Manning
Copy link
Contributor Author

To get past CI you'll need to run 'just update-lock-files' and force push please.

Pushed

@A-Manning
Copy link
Contributor Author

I had play with your tests, perhaps this is cleaner?

IMO it is cleaner for tests to return Result<(), SomeError> than to have .expect("some error message") throughout. I also prefer to avoid wildcard imports where possible. I'd prefer to keep the tests as-is

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 e1fa1d8; successfully ran local tests

@tcharding
Copy link
Member

I had play with your tests, perhaps this is cleaner?

IMO it is cleaner for tests to return Result<(), SomeError> than to have .expect("some error message") throughout. I also prefer to avoid wildcard imports where possible. I'd prefer to keep the tests as-is

Sure, I'm not that bothered but for the record neither of these is done anywhere else in this codebase (or the rust-bitocin org) as far as I'm aware.

@apoelstra
Copy link
Member

Huh. I actually didn't notice the Result return type here, nor did I know that it was allowed (since Rust 2018, apparently). I kinda prefer it.

@apoelstra
Copy link
Member

As for avoiding wildcards, in the specific case of super::* in inline modules, I don't mind them, because any symbols it exports you know are defined in the same file that you're already looking at.

But agreed in general it's better to avoid them.

I'm gonna go ahead and merge this, and if we want to do some broader unit test refactoring effort, we can do that separately.

@apoelstra apoelstra merged commit bbcf09c into rust-bitcoin:master Aug 17, 2025
14 checks passed
@tcharding
Copy link
Member

I also didn't know it was allowed. Interestingly GitHub does not pick up the mention, here it is: rust-bitcoin/rust-bitcoin#4882

tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 23, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189, a bug in serde deserialization.

Manual backport of e1fa1d8 because it
did not cherry-pick cleanly.
tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 23, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189, a bug in serde deserialization.

Manual backport of e1fa1d8 because it
did not cherry-pick cleanly.
tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 23, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189. This is a manual backport, less changes
needed than the original. Just the test, the fix, and uptade the
`serde_json` dev dependency. Other changes in the original patch were
not needed.
@tcharding
Copy link
Member

Backported to 0.3.x in #201 and to 0.2.x in #202

tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 25, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189, a bug in serde deserialization.

Manual backport of e1fa1d8 because it
did not cherry-pick cleanly.

Update the `Cargo-minimal.lock` because of the dev-dep change (I
think).
tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 25, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189, a bug in serde deserialization.

Manual backport of e1fa1d8 because it
did not cherry-pick cleanly.

Patch adds a dev dependency that causes the MSRV build to choke.
Update the `Cargo-minimal.lock` by using `-Z minimal-versions`.
tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 25, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189, a bug in serde deserialization.

Manual backport of e1fa1d8 because it
did not cherry-pick cleanly.

Patch adds a dev dependency that causes the MSRV build to choke.
Update the `Cargo-minimal.lock` by using `-Z minimal-versions`.
tcharding added a commit to tcharding/hex-conservative that referenced this pull request Feb 25, 2026
PR rust-bitcoin#188 fixes issue rust-bitcoin#189, a bug in serde deserialization.

Manual backport of e1fa1d8 because it
did not cherry-pick cleanly.

Patch adds a dev dependency that causes the MSRV build to choke.
Update the `Cargo-minimal.lock` by using `-Z minimal-versions`.

And then pin `proc-macro2` back to what it was with:

  `cargo update -p proc-macro2 --precise  1.0.63`
apoelstra added a commit that referenced this pull request Mar 3, 2026
14b4bab Remove incorrect write_err import (Tobin C. Harding)
e84b76c Backport 188 serde deserialization bug (Tobin C. Harding)

Pull request description:

  PR #188 fixes issue #189. This is a manual backport, less changes needed than the original. Just the test, the fix, and uptade the `serde_json` dev dependency. Other changes in the original patch were not needed.
  
  Requires fix to pinning in CI (which uses the very old ci script on this branch). Whinge, whinge, whinge.


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


Tree-SHA512: 01ed03e1cb25594a49adbc46ade9e3307b94241b0ab20e41522745cb6ad23498b84f2a1626271401db393de21d2d33f9619a52e240f1550eda093402fb2e407f
apoelstra added a commit that referenced this pull request Mar 3, 2026
903730c Backport 188 serde deserialization bug (Tobin C. Harding)

Pull request description:

  PR #188 fixes issue #189, a bug in serde deserialization.
  
  Manual backport of e1fa1d8 because it did not cherry-pick cleanly.
  
  Patch adds a dev dependency that causes the MSRV build to choke. Update the `Cargo-minimal.lock` by using `-Z minimal-versions`.
      
  And then pin `proc-macro2` back to what it was with:  `cargo update -p proc-macro2 --precise  1.0.63`


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


Tree-SHA512: 0f9d0f45ecb3e559c0821462a6e239680241ef9a653c79cd5a7806299351f2643162d53f93e0c5c651985a465b868074fdb85bf3b64d2799aafaf98b0c69570a
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.

Serde deserialization is broken

3 participants