Skip to content

Commit

Permalink
chore(json): update json to use 20 sig digits, tweak arns monitor che…
Browse files Browse the repository at this point in the history
…ck (#120)
  • Loading branch information
dtfiedler authored Oct 23, 2024
2 parents 84b53c6 + 7938c80 commit 9e6395b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ local function encode_number(val)
if val ~= val or val <= -math.huge or val >= math.huge then
error("unexpected number value '" .. tostring(val) .. "'")
end
if math.floor(val) == val then
-- Large integers: avoid scientific notation and print as an integer
return string.format("%.0f", val)
-- Handle integer values separately to avoid floating-point conversion
if math.type(val) == "integer" then
return string.format("%d", val) -- Format as an integer
else
-- Decimals: use the 'g' format to print floating point with precision, up to 14 significant digits
return string.format("%.14g", val)
-- Use 20 significant digits for non-integer numbers
return string.format("%.20g", val)
end
end

Expand Down
16 changes: 8 additions & 8 deletions tests/monitor/monitor.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ describe('setup', () => {
);

let cursor = '';
let countedTotalGateways = 0;
let totalGateways = 0;
const uniqueGateways = new Set();
do {
const {
items: gateways,
Expand All @@ -376,9 +376,9 @@ describe('setup', () => {
cursor,
});
totalGateways = totalItems;
countedTotalGateways += gateways.length;
for (const gateway of gateways) {
if (gateway.status === 'joined') {
uniqueGateways.add(gateway.gatewayAddress);
assert(
Number.isInteger(gateway.operatorStake),
`Gateway ${gateway.gatewayAddress} has an invalid operator stake: ${gateway.operatorStake}`,
Expand Down Expand Up @@ -473,8 +473,8 @@ describe('setup', () => {
cursor = nextCursor;
} while (cursor !== undefined);
assert(
countedTotalGateways === totalGateways,
`Counted total gateways (${countedTotalGateways}) does not match total gateways (${totalGateways})`,
uniqueGateways.size === totalGateways,
`Counted total gateways (${uniqueGateways.size}) does not match total gateways (${totalGateways})`,
);
});
});
Expand All @@ -484,8 +484,8 @@ describe('setup', () => {
const twoWeeks = 2 * 7 * 24 * 60 * 60 * 1000;
it('should not have any arns records older than two weeks', async () => {
let cursor = '';
let countedTotalArns = 0;
let totalArns = 0;
const uniqueNames = new Set();
do {
const {
items: arns,
Expand All @@ -495,8 +495,8 @@ describe('setup', () => {
cursor,
});
totalArns = totalItems;
countedTotalArns += arns.length;
for (const arn of arns) {
uniqueNames.add(arn.name);
assert(arn.processId, `ARNs name '${arn.name}' has no processId`);
assert(arn.type, `ARNs name '${arn.name}' has no type`);
assert(
Expand Down Expand Up @@ -532,8 +532,8 @@ describe('setup', () => {
cursor = nextCursor;
} while (cursor !== undefined);
assert(
countedTotalArns === totalArns,
`Counted total ARNs (${countedTotalArns}) does not match total ARNs (${totalArns})`,
uniqueNames.size === totalArns,
`Counted total ARNs (${uniqueNames.size}) does not match total ARNs (${totalArns})`,
);
});
});
Expand Down

0 comments on commit 9e6395b

Please sign in to comment.