From 3aa8544171f317a7daca2aec12f9e97cc671e958 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Fri, 9 Feb 2024 15:00:26 +0100 Subject: [PATCH] fix: Fix computation of genesisSlot time range and fix test --- client/src/helpers/nova/novaTimeUtils.spec.ts | 4 ++-- client/src/helpers/nova/novaTimeUtils.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/helpers/nova/novaTimeUtils.spec.ts b/client/src/helpers/nova/novaTimeUtils.spec.ts index 9c0a19c2f..b704953c1 100644 --- a/client/src/helpers/nova/novaTimeUtils.spec.ts +++ b/client/src/helpers/nova/novaTimeUtils.spec.ts @@ -78,8 +78,8 @@ describe("slotIndexToUnixTimestamp", () => { test("should return genesis slot timestamp when passed a slotIndex lower than genesisSlot", () => { let target = genesisSlot - 1; // 4 const expectedGenesisTimestampRange = { - from: genesisUnixTimestamp, - to: genesisUnixTimestamp + slotDurationInSeconds, + from: genesisUnixTimestamp - slotDurationInSeconds, + to: genesisUnixTimestamp, }; let slotIndex = slotIndexToUnixTimeRange(target); diff --git a/client/src/helpers/nova/novaTimeUtils.ts b/client/src/helpers/nova/novaTimeUtils.ts index a4954bfc5..d92978589 100644 --- a/client/src/helpers/nova/novaTimeUtils.ts +++ b/client/src/helpers/nova/novaTimeUtils.ts @@ -19,13 +19,13 @@ export function unixTimestampToSlotIndexConverter(protocolInfo: ProtocolInfo): ( export function slotIndexToUnixTimeRangeConverter(protocolInfo: ProtocolInfo): (targetSlotIndex: number) => { from: number; to: number } { return (targetSlotIndex: number) => { const genesisSlot = protocolInfo.parameters.genesisSlot; - const genesisUnixTimestamp = protocolInfo.parameters.genesisUnixTimestamp; + const genesisUnixTimestamp = Number(protocolInfo.parameters.genesisUnixTimestamp); const slotDurationInSeconds = protocolInfo.parameters.slotDurationInSeconds; if (targetSlotIndex < genesisSlot) { return { - from: Number(genesisUnixTimestamp), - to: Number(genesisUnixTimestamp) + slotDurationInSeconds, + from: genesisUnixTimestamp - slotDurationInSeconds, + to: genesisUnixTimestamp, }; }