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

support uint16/32, and tests added #15

Closed Lavishq closed 3 months ago

Lavishq commented 3 months ago

https://github.com/karalabe/ssz/issues/12

image image

karalabe commented 3 months ago

Sweet, very nice :)

One more thing to make it perfect if you're up for it: tests :D But don't worry, it's easy because the test data is there, it just needs to be called:

If you're feeling a bit more adventurous, you can also add VarTestStruct and ComplexTestStruct, which isn't much harder, just the fields types are not only primitives any more, rather you'll need to dig a bit deeper. But if you don't want to, I'm happy with the first two types only too :)

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 81.44330% with 18 lines in your changes missing coverage. Please review.

Project coverage is 83.85%. Comparing base (be92ed9) to head (ba211b5).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #15 +/- ## ========================================== - Coverage 84.00% 83.85% -0.15% ========================================== Files 59 61 +2 Lines 2938 3035 +97 ========================================== + Hits 2468 2545 +77 - Misses 313 324 +11 - Partials 157 166 +9 ``` | [Components](https://app.codecov.io/gh/karalabe/ssz/pull/15/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/15/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) | `83.11% <79.41%> (-0.31%)` | :arrow_down: | | [sszgen](https://app.codecov.io/gh/karalabe/ssz/pull/15/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) | `70.99% <77.77%> (+0.15%)` | :arrow_up: |
Lavishq commented 3 months ago

did the tests and able to go generate w/o errors for SmallTestStruct and FixedTestStruct here

where as having issues getting complex dynamic dtypes work, since idk golang

type VarTestStruct struct {
    A [1]byte `ssz-size:"2" ssz:"bits"`
    // B [1]byte `ssz-size:"2" ssz:"bits" ssz-max:"1024"`
    C [1]byte `ssz-size:"1" ssz:"bits"`
}

type ComplexTestStruct struct {
    A [1]byte `ssz-size:"2" ssz:"bits"`
    // B [1]byte `ssz-size:"2" ssz:"bits" ssz-max:"128"`
    C [1]byte `ssz-size:"1" ssz:"bits"`
    // D [1]byte `ssz-max:"256"`
    E VarTestStruct
    // F [1]FixedTestStruct `ssz-size:"4" ssz:"bits"`
    // G [1]VarTestStruct `ssz-size:"2" ssz:"bits"`
}

have reached til^

sorry, if im wrong w/ things since this is the first time im programming in go- so learning while trying this :)`

karalabe commented 3 months ago

@Lavishq Just one more tip in general, in Go, you can run all the tests from all packages via go test ./.... The one you did running go test only ran it for tests in the root folder, which aren't really many/any. This is generally not the case for Go packages of course, but for this specific project there is such an extensive external test suite, that it made little sense to redo internal unit tests when I could just rely on the external suite.

Thanks again :)

Lavishq commented 3 months ago

hm, i know nothing about go, i once did tour of go upto variables and imports, probably a little more for about 20-30 mins and that is all [ also dont remember much ] so i do need to learn it the right way, recently was looking at op-geth and didnt understand much, thought that since it is gfg i would quickly learn from gobyexample or the codebase itself ^^

thanks ser, for bearing with me, it was embarrasing to make silly mistakes but was a learning exp and would do again but maybe after i finish tour of go this time :)