diff --git a/packages/ripple-binary-codec/src/types/uint-64.ts b/packages/ripple-binary-codec/src/types/uint-64.ts index 50a3b124..2c2f888c 100644 --- a/packages/ripple-binary-codec/src/types/uint-64.ts +++ b/packages/ripple-binary-codec/src/types/uint-64.ts @@ -54,6 +54,10 @@ class UInt64 extends UInt { } if (typeof val === "string") { + if (val === "0") { + return UInt64.from(0); + } + if (!HEX_REGEX.test(val)) { throw new Error(`${val} is not a valid hex-string`); } diff --git a/packages/ripple-binary-codec/test/uint.test.js b/packages/ripple-binary-codec/test/uint.test.js index 258979e3..c59309c8 100644 --- a/packages/ripple-binary-codec/test/uint.test.js +++ b/packages/ripple-binary-codec/test/uint.test.js @@ -1,6 +1,32 @@ const { coreTypes } = require("../dist/types"); const { UInt8, UInt64 } = coreTypes; +const { encode } = require("../dist"); + +const binary = + "11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F"; +const json = { + Balance: { + currency: "USD", + issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji", + value: "0", + }, + Flags: 196608, + HighLimit: { + currency: "USD", + issuer: "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK", + value: "1000", + }, + HighNode: "0", + LedgerEntryType: "RippleState", + LowLimit: { + currency: "USD", + issuer: "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", + value: "1000", + }, + LowNode: "0", +}; + test("compareToTests[0]", () => { expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(0); }); @@ -33,6 +59,11 @@ test("compareToTest[7]", () => { expect(UInt8.from(124).compareTo(13)).toBe(1); }); +test("UInt64 from string zero", () => { + expect(UInt64.from("0")).toEqual(UInt64.from(0)); + expect(encode(json)).toEqual(binary); +}); + test("valueOfTests", () => { let val = UInt8.from(1); val |= 0x2;