From 37d0b1014069c5c7dc9390c89ce8063ace0b2e30 Mon Sep 17 00:00:00 2001 From: geeekyfocus Date: Fri, 27 Mar 2026 12:30:29 +0100 Subject: [PATCH] feat: Add uint64 round-trip test for max uint64 boundary - Add TestEncodeMuxedUint64MaxRoundtrip to validate round-trip encoding/decoding at max uint64 (18446744073709551615) - Ensures bit-for-bit correctness without buffer overflow or precision loss during serialization - Uses maxUint64 := ^uint64(0) as specified in issue requirements - Includes explicit uint64 conversion validation to detect precision loss - Tests following established patterns in muxed test suite Closes #78 --- packages/core-go/muxed/muxed_test.go | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/core-go/muxed/muxed_test.go b/packages/core-go/muxed/muxed_test.go index 940406e5..c815c351 100644 --- a/packages/core-go/muxed/muxed_test.go +++ b/packages/core-go/muxed/muxed_test.go @@ -125,3 +125,49 @@ func TestEncodeMuxedJSONUnmarshalWithJS53Boundary(t *testing.T) { t.Fatalf("decoded id mismatch: got %q want %q", decodedID, boundaryIDStr) } } + +// TestEncodeMuxedUint64MaxRoundtrip validates round-trip encoding/decoding at the uint64 maximum boundary. +// This test ensures that maxUint64 (18446744073709551615) preserves bit-for-bit correctness without +// buffer overflow or precision loss during serialization and deserialization. +func TestEncodeMuxedUint64MaxRoundtrip(t *testing.T) { + kp, err := keypair.Random() + if err != nil { + t.Fatalf("keypair.Random returned error: %v", err) + } + + baseG := kp.Address() + maxUint64 := ^uint64(0) + idStr := strconv.FormatUint(maxUint64, 10) + + // Round-trip: encode the max uint64 value + encoded, err := EncodeMuxed(baseG, idStr) + if err != nil { + t.Fatalf("EncodeMuxed with maxUint64 returned error: %v", err) + } + + // Round-trip: decode and verify bit-for-bit correctness + decodedBaseG, decodedID, err := DecodeMuxed(encoded) + if err != nil { + t.Fatalf("DecodeMuxed returned error: %v", err) + } + + // Verify base account matches exactly + if decodedBaseG != baseG { + t.Fatalf("decoded base account mismatch: got %q want %q", decodedBaseG, baseG) + } + + // Verify ID matches exactly (bit-for-bit) + if decodedID != idStr { + t.Fatalf("decoded id mismatch: got %q want %q", decodedID, idStr) + } + + // Additional validation: ensure the decoded ID can be converted back to uint64 without loss + decodedUint64, err := strconv.ParseUint(decodedID, 10, 64) + if err != nil { + t.Fatalf("ParseUint returned error: %v", err) + } + + if decodedUint64 != maxUint64 { + t.Fatalf("uint64 round-trip precision loss: got %d want %d", decodedUint64, maxUint64) + } +}