Fix json serialization of UInt192Type - #828
Conversation
Signed-off-by: nkramer44 <noah.ph.kramer@gmail.com>
Signed-off-by: nkramer44 <noah.ph.kramer@gmail.com>
This reverts commit 39e485a.
There was a problem hiding this comment.
The core fix (UInt192Type.toJson override writing raw toHex() as a TextNode) correctly resolves the described serialization bug. The new BinarySerializationTests additions look fine. However, the new UInt192TypeTest.java has a likely compile-breaking test: encodeOutOfBounds() passes a raw String to fromJson(JsonNode), whereas the adjacent encode() test correctly wraps the value in a TextNode.
There was a problem hiding this comment.
Straightforward, correct fix: UInt192Type now overrides toJson() to emit the raw hex string via TextNode instead of inheriting UIntType's toJson (which wrapped the value in UnsignedLong and overflowed for 192-bit values). The change is minimal, matches the existing UInt192Type.fromJson pattern, and is backed by new unit tests (UInt192TypeTest) plus new MPToken serialization round-trip tests that exercise MpTokenIssuanceId (a UInt192 field) through JSON<->binary conversion. No correctness, security, or consistency issues found in the changed lines.
Signed-off-by: nkramer44 <noah.ph.kramer@gmail.com>
There was a problem hiding this comment.
The core fix is a minimal, correct override of toJson() on UInt192Type that emits the raw hex string instead of routing through UIntType's default implementation, which tries to parse the value as an UnsignedLong and overflows for 192-bit values. The change is consistent with how other large fixed-width UInt types (e.g., UInt256) should behave, and the accompanying tests (unit test for UInt192Type round-trip, plus MPToken transaction serialization tests exercising the UInt192-typed MpTokenIssuanceId field) adequately cover the fix. No correctness, security, or consistency issues found in the added code.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Small, correct fix: UInt192Type now overrides toJson() to emit the raw hex string instead of routing through UIntType's UnsignedLong-based toJson(), which overflowed for 192-bit values. The change is minimal, consistent with how other large fixed-width types (e.g., UInt256) likely handle this, and is backed by new unit and serialization tests. No issues found in the changed lines.
UInt192Type does not override
toJson, so when deserializing binary to JSON,UIntType'stoJsonmethod gets invoked, which looks likeUInt192s are too large to fit in an UnsignedLong, so this method blows up. The fix is to just overload
toJsonand writetoHex()without wrapping it in any kind of number class