Improve witness unit tests#3409
Conversation
The current unit test is incorrect, the indices field of a witness with a single element starts at 1 because 0 is encode as a single byte (compact encoded integer). Fix the debug test and add a test that pushes an empty slice.
6d48eaa to
42a962e
Compare
|
I think the CI failure is a bug that the new tests expose, though I can't tell what exactly it is. It may be related to our use of |
|
code review ACK 42a962ee082778b781154885bd04796642e726de but we need to address this failure before we can merge this. |
|
Mad, this might be a bug. In EDIT: I have a nagging feeling that we have discussed this before in the past. |
|
Related comment you made (before my time): https://github.com/rust-bitcoin/rust-bitcoin/pull/627/files#r660852407 |
|
@tcharding we don't ever use that in the consensus encoding though. The consensus encoding uses varints. AFAICT we symmetrically use |
|
I don't think the comment you linked is related to this. That was about using |
|
Ah you are right we are only encoding the index in the index area of |
Make an effort to clean up the `Witness::push` unit test. This patch dose not change the test, it only attempts to make it easier to read.
Make an effort to clean up the encoding unit test, by doing: - Remove element accessor assertions (tested already above) - Add roundtrip encoding assertion
In preparation for moving unit tests to `primitives` give the serde tests some love by doing: - Split them up to do one thing only - Round trip arbitrary witness - Use better names
Rust convention is to not use `test_` prefix on unit tests. Also this unit test is testing that the `ExactSizedIterator` trait is implemented and working. Re-name unit test to `exact_sized_iterator`.
42a962e to
5fab6b1
Compare
|
Merge please. This is holding up more |
In preparation for moving the
Witnesstype over toprimitivesrefactor and improve all the unit tests that will be moved, do not touch the ones that will stay behind.The first five patches are from #3406, the last is just a re-name of the test function I tried to refactor in ac6fe3a