Skip to content
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

Fix LeafVersion serde #1523

Merged
merged 2 commits into from Jan 9, 2023
Merged

Conversation

sanket1729
Copy link
Member

The default implementation maps to visit_u64. The current implementation
does not roundtrip with many deserializers, including serde_json. See
the failing test in the second commit

The default implementation maps to visit_u64. The current implementation
does not roundtrip with many deserializers, including serde_json. See
failing test in the subsequent commit
@sanket1729
Copy link
Member Author

This still fails on secp256k1::Parity type because of the same reason. I think we should also fix it there to use visit_u64 so that we users can use serde_json. Even though we are testing the structures with serde_test, I think it should be considered a bug if the given serde_json test fails.

Anyways, input from people using serde is appreciated. My intention is to fix #1327.

@apoelstra
Copy link
Member

Heh, I'm surprised we're using serde_test anywhere because IME it's completely useless.

@apoelstra
Copy link
Member

Having said this, okay, I'm fine deserializing u64s like this but IMO it's a bug in serde(_json) that you cannot actually roundtrip u8s by using serialize_u8 and deserialize_u8.

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 2, 2023

This looks like robustness principle on the surface but actually isn't so concept ACK.

IMO it's a bug in serde(_json)

Yeah, looks like one.

@apoelstra
Copy link
Member

Looks like the CI failure is an actual code breakage of some sort.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

tACK a400757

Checked that the test is failing before the fix.

@tcharding
Copy link
Member

Heh, I'm surprised we're using serde_test anywhere because IME it's completely useless.

You meant "IMO", right? Can you expand on this? I ask because we use it in a few places and I added tests using it thinking it was useful, I'm interested to know if I was wrong?

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 a400757

@sanket1729 sanket1729 merged commit cc1e6c0 into rust-bitcoin:master Jan 9, 2023
@apoelstra
Copy link
Member

You meant "IMO", right? Can you expand on this? I ask because we use it in a few places and I added tests using it thinking it was useful, I'm interested to know if I was wrong?

I meant "IME". This is one such case. The other I remember had to do with all of the types in rust-secp that wrap bytestrings. It is trivial to create things that serde_test will round-trip but actual de/serializers will not.

I went to search the git history for the removal of these tests but I actually it looks like we just left them in...presumably to avoid a json dependency, and because (hopefully) downstream users have round-trip tests of their own.

@tcharding
Copy link
Member

lol, as my kids are fond of telling me "I'm such a boomer" I had to look up the definition of IME (In My Experience) :)

We have a serde_json dev dependency already so should it be on my todo-at-some-stage list to remove the serde_test usage and favour roundtrip tests with serde_json?

@sanket1729
Copy link
Member Author

I think serde_test is the recommended way of testing. serde_json just has a weird bug around requiring everything as either u64 or i64.

@apoelstra
Copy link
Member

@sanket1729 yes, serde_json has a bug around u64 and i64. But I have also run into trouble with its handling of byteslices (or at least, serde_test okayed something which did not round trip with serde_json).

Maybe I'm just upset about some old long-fixed bug. But it made me distrust serde_test.

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.

None yet

4 participants