-
Notifications
You must be signed in to change notification settings - Fork 831
Serde regression tests #724
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
Conversation
Cool! concept ACK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
100b5d5
to
ac6552f
Compare
There are a few private types in Do we need this one?
|
Private types shouldn't need serde impls. If they do (because something in the crate uses them inside) then tests are useful to pinpoint the source of problem if something goes wrong. Change the array to slice to fix compile issue: let want = &[32, 0 ...] as &[_]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need one of the following:
- move
tests/bincode
andtests/hex
insidetest_data
- create
tests/data
and movetest_data
,tests/bincode
andtests/hex
inside it
Cool, I think I'll leave this one out. Since we cannot guarantee that the regression tests test all the serde impls I think its probably better to just keep the public API tests, then they are all in one place. Also this test, as its written, won't help pin point any errors that much more than the
Oh nice, thanks. |
Good suggestion, I elected to move the files from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did only a light review. Since this is not very urgent we can afford a bit of bikesheding, right?
Bikeshed all day! Thanks for the review, I learned a bunch from this review. |
7db1726
to
95356d1
Compare
9a86e87
to
ac33d08
Compare
35eba47
to
80d9879
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 3ef6935149892e6ab7c6320606f4fbe593d262bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't do a full review RN just note that I'd prefer having short test strings (e.g. hex public key) inline in tests. At least unless they are some shared canonical test vectors. Wouldn't block the PR for that though.
tests/data/serde/README.md
Outdated
Files here contain hex strings and binary data representing types used for | ||
regression testing. | ||
|
||
- *_hex: consensus encoded types represented as hex strings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need _hex
files? Shouldn't we test hex decoding separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'd rather drop the binary vectors than the hex ones.
Agreed that they're pretty-much redundant and we shouldn't duplicate everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I can't really remember why I put some in hex (I did the bulk of this work in November last year) but my guess was that I was lazy and just used hex strings when they appeared elsewhere in the codebase (the binary stuff I generated for each type manually). I do remember going through at the end and moving the hex stuff to files instead of inline. My reasoning was that the data is not meaningful so better to conceal it in a file and keep the test source code clean. I can't remember why I used binary instead of hex for the manually generated types, perhaps because we have the two blocks there in tests/data
that are in binary - if we move to hex we should be uniform. We exclude the tests/
directory in Cargo.toml
so data size is not a consideration. I do not know what other trade offs there are between the two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hex helps reviewers see the data without using hexdump
and on github. But is it worth complicating the test code that now has to parse hex too? Maybe with my hex_lit
macro it wouldn't be so bad but still, if someone makes a mistake in hex parsing impl he'll get tons of unrelated errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine -- usually they'll just be "parsing" the hex to a Vec<u8>
then parsing from there as though it were binary data. And hex->byte vector is write-once code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never need the hex
crate.
We should probably add a deserialize_hex
method analogous to serialize_hex
which uses the bitcoin_hashes::hex
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, we are explicitly trying to test the serde implementations, we have to use a crate serializes using serde to do so, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware that hex
uses serde. What serialization format does it use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it just serializes as ascii chars: https://docs.rs/hex/latest/hex/serde/fn.serialize.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's simple enough for us to NIH it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK 3ef6935149892e6ab7c6320606f4fbe593d262bc
We have two ACKs but I'm not clear whether we want to modify this PR to answer "what should we be doing about hex vs binary" question here. |
I am unclear also. |
When in doubt I usually prefer "make some progress unless this affects API". This already improves things from previous state of the code and we can resolve the remaining issues later. Unfortunately this needs rebase. |
9a4c79a
3ef6935
to
9a4c79a
Compare
Rebased and used qualified path for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 9a4c79a390bcedcb78c65a5688f269c36f090823
9a4c79a
to
75fff7a
Compare
Rebased and added tests for |
FTR I have no clue if this covers all types since its been open for so long, I'm not super enthusiastic about auditing again while the PR is open, if/when it merges I can re-audit the whole codebase though. |
458add6
to
16fd5f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 16fd5f6e8160317b7053b74dc12a1692f1d94475
In order that we can safely change/maintain de/serialization code we need to have regression tests with hard coded serializations for each type that implements serde. It is enough to test a single serde data format, use JSON for `opcodes` and bincode for other types. Do regression testing in a newly added `tests` module.
16fd5f6
to
962abcc
Compare
Re-base and remove the patch to move test data since its on master already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 962abcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 962abcc. This has been open for a long time. Merging this in the interest of progress.
Attempts to add regression tests for all types defined in
rust-bitcoin
that implementSerialize
/Deserialize
.tests
directory and implement regression tests in thereinclude_bytes!
usage from RCasatta's PRutil/taproot.rs
for private typesNote to reviewers
tests/regression_opcodes.rs
), for all other tests uses bincode.Fixes #723