mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
fix: edge case constructing from string '0' (#121)
* fix: edge case constructing from string '0'
This commit is contained in:
@@ -54,6 +54,10 @@ class UInt64 extends UInt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof val === "string") {
|
if (typeof val === "string") {
|
||||||
|
if (val === "0") {
|
||||||
|
return UInt64.from(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (!HEX_REGEX.test(val)) {
|
if (!HEX_REGEX.test(val)) {
|
||||||
throw new Error(`${val} is not a valid hex-string`);
|
throw new Error(`${val} is not a valid hex-string`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,32 @@
|
|||||||
const { coreTypes } = require("../dist/types");
|
const { coreTypes } = require("../dist/types");
|
||||||
const { UInt8, UInt64 } = coreTypes;
|
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]", () => {
|
test("compareToTests[0]", () => {
|
||||||
expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(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);
|
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", () => {
|
test("valueOfTests", () => {
|
||||||
let val = UInt8.from(1);
|
let val = UInt8.from(1);
|
||||||
val |= 0x2;
|
val |= 0x2;
|
||||||
|
|||||||
Reference in New Issue
Block a user