-
Notifications
You must be signed in to change notification settings - Fork 5
feat(params): UnmarshalChainJSONConfig and MarshalChainConfigJSON
#92
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
32afb0b to
a41a78d
Compare
a6ebb69 to
a46252d
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.
nice, let's add MarshalJSON, we can do it in this or a separate PR
params/json.libevm.go
Outdated
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.
(style) Please don't use such verbose variable names when the scope is only 3 lines; they distract from reading of the code. I'd personally be happy with just r, but understand that others are not—as long as it's not 5 syllables.
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've read a few style guides including that one, my view on it, unless it's a really obvious use (i.e. i for a range index), it's nice to have a meaningful name almost always. For example c instead of extraConstructors made me wonder what was c and had to lookup where it was created and what .Get() was returning, and, because it's a generic function, had to dig into extraConstructors struct. Not a big deal obviously, but it does make readability worst in my opinion.
Obviously that's my opinion on this, so I'll conform to the existing code and use shorter variable names 😉
EDIT: also one more reason is I do like to use a single letter for the receiving struct for methods, so using single letter variables in there makes things confusing imo
EDIT2: my brain is kind of very formed (malformed or ok-formed, debatable 😄) to use explicit non-single-letter variable names, so feel free to hammer with style comments in case you feel like it should be a smaller variable name. I got the extraConstructors -> ec but after going through the rest of the code I wrote, I'm feeling like:
params/json.libevm_test.go
Outdated
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.
The rest of libevm uses "want" instead of "expected" and "got" instead of "actual".
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.
Changed expected prefixes to want prefixes.
However - ha I want shorter variable names perhaps - regarding actual (and got), I think i.e. data, ok := MarshalXYZ in a test is better than actualData, actualOk := MarshalXYZ and there is no need for an actual prefix really? And if it's only one variable being checked, why not name it to what it actually is i.e. data instead of actual
da45de2 to
2172aa7
Compare
UnmarshalChainConfig functionUnmarshalChainJSONConfig and MarshalChainJSONConfig
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.
Approving with changes requested because I don't need to re-review them. Most are suggestions (since we're new to working together and sharing my preferred style for libevm) and I'm happy for you to use your judgement in deciding whether or not to implement them, but the following I'd like to discuss if you disagree with them:
- The 4 external comments on
ChainConfig.{Un}Marshal()and on{Un}MarshalChainConfigJSON(). - All 3 comments on the tests.
params/json.libevm.go
Outdated
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 for this and the extras too we should just return a raw error and decorate it in toJSONRawMessages() instead, for consistency. I'd add a suggestion but GitHub review UI sucks and I can't comment on unmodified code in the same file.
fmt.Errorf("encoding %T into %T: %s", v, msgs, err) on line 154.
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 fmt.Errorf("encoding %T into %T: %s", v, msgs, err) is a bit confusing, since technically we are encoding then decoding into a different Go element (map). I still think converting config to JSON raw messages explains it alright. I've added error wrappings in 359448d66f0a15e7f62b8aaef7bd734872690975 but it might be a bit too-muchey, feel free to let me know and i'll drop that commit.
params/json.libevm_test.go
Outdated
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.
Using a full error message like this is a change-detector test that results in false positives (e.g. they will all break if you accept my suggestions). Alternative options:
- Limit to a pertinent and specific sub-string for each error.
- Create (unexported)
var errXglobal variables and wrap them on return, usingerrors.Isin the test. - Create a custom error type with an internal identifier that you can assert here (e.g. although not appropriate, something like gRPC
statuscodes, but unique).
This applies to the marshalling tests too.
See https://google.github.io/styleguide/go/decisions#test-error-semantics
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.
Agreed, although I would like to add checking error messages does help build decent error messages through error wrappings and avoid repetitions (and also make sure it logs out well formed things, not pointer addresses for example). But the cost of this outweights the benefits, so changing this to an error message regex checking the 'important part' and not the whole error message.
c656984 to
0d06fe7
Compare
…igJSON` Co-authored-by: Arran Schlosberg <[email protected]> Signed-off-by: Quentin McGaw <[email protected]>
Co-authored-by: Arran Schlosberg <[email protected]> Signed-off-by: Quentin McGaw <[email protected]>
Co-authored-by: Arran Schlosberg <[email protected]> Signed-off-by: Quentin McGaw <[email protected]>
0d06fe7 to
b48fb8a
Compare
UnmarshalChainJSONConfig and MarshalChainJSONConfigUnmarshalChainJSONConfig and MarshalChainConfigJSON

Why this should be merged
How this works
UnmarshalChainConfigJSONis a standalone deserialization function taking a data byte slice, the destination pointers*ChainConfigand a generic extra*C, as well as areuseJSONRootboolean.MarshalChainConfigJSONis a standalone serialization function taking aChainConfig, an extra of generic typeCandreuseJSONRootboolean.How this was tested
New unit tests
TestUnmarshalChainConfigJSON_ErrorsandTestMarshalChainConfigJSON_Errorsfor unhappy code paths, existing testTestChainConfigJSONRoundTripfor happy code paths.