karalabe / ssz

Opinionated 0-alloc SSZ codec for Go
https://github.com/ethereum/consensus-specs/blob/dev/ssz/simple-serialize.md
BSD 3-Clause "New" or "Revised" License
39 stars 7 forks source link

ssz, tests: fix slice init on empty decode #26

Closed karalabe closed 1 month ago

karalabe commented 1 month ago

Fixes https://github.com/karalabe/ssz/issues/18.

The issue was that decoding an zero-length dynamic array into a nil slice left the destination slice as nil, which isn't inherently bad, but it's a bit wonky since it should ideally become a zero length array, signalling that there's "no data" vs. "missing field". That does require an allocation, but feels better than leaving nil.

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@a8a0df8). Learn more about missing BASE report. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #26 +/- ## ======================================= Coverage ? 86.85% ======================================= Files ? 81 Lines ? 4452 Branches ? 0 ======================================= Hits ? 3867 Misses ? 378 Partials ? 207 ``` | [Components](https://app.codecov.io/gh/karalabe/ssz/pull/26/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=P%C3%A9ter+Szil%C3%A1gyi) | Coverage Δ | | |---|---|---| | [ssz](https://app.codecov.io/gh/karalabe/ssz/pull/26/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=P%C3%A9ter+Szil%C3%A1gyi) | `85.07% <100.00%> (?)` | | | [sszgen](https://app.codecov.io/gh/karalabe/ssz/pull/26/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=P%C3%A9ter+Szil%C3%A1gyi) | `75.45% <ø> (?)` | |