-
Notifications
You must be signed in to change notification settings - Fork 631
[CDEC-506] Make JSON golden tests check FromJSON
decoding in addition to ToJSON
encoding
#3415
Conversation
Make JSON golden tests check `FromJSON` decoding in addition to `ToJSON` encoding.
"\22940\29914\144828\177644\52019\16682\5563\142278\22269\41464\ | ||
\\64899\153034\134491\51443\9384\49583\41181\16586\45161\55231\ | ||
\\127978\3521\6732\67841\152627\1796\53978\28040\68524\45059\ | ||
\\46383\4326" |
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 have hex encoding\decoding helpers somewhere. Is i worth using them for this? IMO hex is much more readable and uniform than this stuff.
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.
Do you mean the Base16 stuff? Yeah, that might make this more readable (although these are just random Char
's I generated).
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 is more readable than what you have :)
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 just force-pushed a new version which uses Serokell.Util.Base16
to encode the ByteStrings. Let me know if that's more like what you imagined.
{"spec":{"avvmDistr":{"nNq87DMqu8b9-IPKW_Oor93Kab_qwUwBMwTaiKwDL-Y=":37343863242999412,"4qF3OiqC0QwwiQy_hOzL3Bqq7pIElkJNNuhoA52ctRk=":36524597913081152},"ftsSeed":"RTVTNGZTSDZldE5vdWlYZXpDeUVqS2MzdEc0amEwa0Y=","heavyDelegation":{"ed41bf35f4cd2109bdee27b0439942f6de3f55f0ac8d170de7136d3d":{"pskDelegatePk":"3cppv+rBTAEzBNqIrAMu5jKBqwNsGxuRiOSxdLMD9D5VFjsXjpmbn9UGN7Ltq4yFioeaw8S9PmEAlUGaGWllcw==","pskOmega":68300481033,"pskCert":"bae5422af5405e3803154a4ad986da5d14cf624d6701c5c78a79ec73777f74e13973af83752114d9f18166085997fc81e432cab7fee99a275d8bf138ad04e103","pskIssuerPk":"4qF3OiqC0QwwiQy/hOzL3Bqq7pIElkJNNuhoA52ctRkhsl7+Az2bANTwLM2c2rzsMyq7xv34g8pb86iv9KrCfg=="}},"blockVersionData":{"scriptVersion":999,"slotDuration":999,"maxBlockSize":999,"maxHeaderSize":999,"maxTxSize":999,"maxProposalSize":999,"mpcThd":9.9e-14,"heavyDelThd":9.9e-14,"updateVoteThd":9.9e-14,"updateProposalThd":9.9e-14,"updateImplicit":99,"softforkRule":{"initThd":9.9e-14,"minThd":9.9e-14,"thdDecrement":9.9e-14},"txFeePolicy":{"txSizeLinear":{"a":9.99e-7,"b":7.7e-8}},"unlockStakeEpoch":99},"protocolConstants":{"k":37,"protocolMagic":1783847074,"vssMaxTTL":1477558317,"vssMinTTL":744040476},"initializer":{"testBalance":{"poors":2448641325904532856,"richmen":14071205313513960321,"totalBalance":10953275486128625216,"richmenShare":4.2098713311249885,"useHDAddresses":true},"fakeAvvmBalance":{"count":17853231730478779264,"oneBalance":15087947214890024355},"avvmBalanceFactor":0.366832547637728,"useHeavyDlg":false,"seed":0}}} |
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.
Curious about what changed here :)
Maybe we could use aeson-pretty to as part of these JSON golden tests to make these a little more human readable.
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.
Good idea - I think that would make the tests easier to inspect. Although, when a mismatch does occur, goldenTestBi
does a good job of highlighting the diff.
The change here was that many of the keys (newtype wrappers around ByteString) were too short, and the decoders check data invariants, so were complaining. It's hard to tell from that diff, of course 🙂
Should I make the change in this PR or in another one? I've been trying to smash these ones out quickly so I can get back to the meat of CO-354.
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.
If you just want to merge this and get back to CO-354, raise a YT ticket for yourself :)
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.
Just raised a ticket here.
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'm ok with seeing this merged now if there is a ticket raised for the issues I raised.
4a3265a
to
61e4d2f
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.
LGTM
A number of fields were of the wrong lengths, which wasn't caught on `encode`ing, but is checked on `decode`ing. The last commit added a decoding check to `goldenTestJSON`, which caught this error. This commit fixes up the ByteString fields so the test passes.
61e4d2f
to
1d9316b
Compare
Description
It recently came to my attention that our
goldenTestJSON
helper function only checks that the provided datastructure's JSON encoding is equal to the ByteString in the file. It doesn't check that the decoding of the ByteString is a datastructure which is==
to the provided datastructure.By comparison
goldenTestBi
checks both ways. Compare to:goldenTestJSON
This means we're missing about half of the test coverage we want on all JSON golden tests.
These 2 commits fix these issues.
Linked issue
https://iohk.myjetbrains.com/youtrack/issue/CDEC-506
Type of change
Developer checklist
^ minor fix - will record in a YouTrack comment, and it can be mentioned in the parent CHANGELOG entry.
Testing checklist
^ existing tests should cover this bugfix. I fixed up one test.