"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Time_1 = require("@wireio/sdk-core/chain/Time");
const constants_1 = require("@wireio/sdk-core/chain/constants");
describe("Time", () => {
    describe("TimePointSec", () => {
        test("from ISO string creates a valid instance", () => {
            const tp = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            expect(tp).toBeInstanceOf(Time_1.TimePointSec);
        });
        test("toDate roundtrips from ISO string", () => {
            const tp = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            const date = tp.toDate();
            expect(date.toISOString()).toBe("2024-01-01T00:00:00.000Z");
        });
        test("toMilliseconds returns correct ms", () => {
            const tp = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            const expected = Date.parse("2024-01-01T00:00:00Z");
            expect(tp.toMilliseconds()).toBe(expected);
        });
        test("toString returns ISO string without milliseconds", () => {
            const tp = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            expect(tp.toString()).toBe("2024-01-01T00:00:00");
        });
        test("equals method works correctly", () => {
            const tp1 = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            const tp2 = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            expect(tp1.equals(tp2)).toBe(true);
        });
        test("equals returns false for different times", () => {
            const tp1 = Time_1.TimePointSec.from("2024-01-01T00:00:00");
            const tp2 = Time_1.TimePointSec.from("2024-06-15T12:00:00");
            expect(tp1.equals(tp2)).toBe(false);
        });
    });
    describe("TimePoint", () => {
        test("fromMilliseconds roundtrips", () => {
            const tp = Time_1.TimePoint.fromMilliseconds(1000);
            expect(tp.toMilliseconds()).toBe(1000);
        });
        test("fromMilliseconds with larger value", () => {
            const ms = 1704067200000;
            const tp = Time_1.TimePoint.fromMilliseconds(ms);
            expect(tp.toMilliseconds()).toBe(ms);
        });
    });
    describe("BlockTimestamp", () => {
        test("from string creates a valid instance", () => {
            const bt = Time_1.BlockTimestamp.from("2025-01-01T00:00:00");
            expect(bt).toBeInstanceOf(Time_1.BlockTimestamp);
        });
        test("epoch date produces slot 0", () => {
            const epochDate = new Date(constants_1.BLOCK_TIMESTAMP_EPOCH_MS);
            const bt = Time_1.BlockTimestamp.fromMilliseconds(epochDate.getTime());
            expect(bt.toMilliseconds()).toBe(constants_1.BLOCK_TIMESTAMP_EPOCH_MS);
        });
        test("epoch + one interval produces slot 1", () => {
            const bt = Time_1.BlockTimestamp.fromMilliseconds(constants_1.BLOCK_TIMESTAMP_EPOCH_MS + constants_1.BLOCK_TIMESTAMP_INTERVAL_MS);
            expect(bt.toMilliseconds()).toBe(constants_1.BLOCK_TIMESTAMP_EPOCH_MS + constants_1.BLOCK_TIMESTAMP_INTERVAL_MS);
        });
        test("roundtrips through toDate", () => {
            const bt = Time_1.BlockTimestamp.from("2025-01-01T00:00:00");
            const date = bt.toDate();
            expect(date.getUTCFullYear()).toBe(2025);
            expect(date.getUTCMonth()).toBe(0);
            expect(date.getUTCDate()).toBe(1);
        });
        test("fromMilliseconds and toMilliseconds roundtrip", () => {
            const ms = constants_1.BLOCK_TIMESTAMP_EPOCH_MS + 5000; // epoch + 5 seconds
            const bt = Time_1.BlockTimestamp.fromMilliseconds(ms);
            expect(bt.toMilliseconds()).toBe(ms);
        });
        test("uses correct epoch (Jan 1, 2025)", () => {
            const jan1_2025 = Date.parse("2025-01-01T00:00:00Z");
            expect(constants_1.BLOCK_TIMESTAMP_EPOCH_MS).toBe(jan1_2025);
        });
        test("uses 500ms interval", () => {
            expect(constants_1.BLOCK_TIMESTAMP_INTERVAL_MS).toBe(500);
        });
        test("equals method works correctly", () => {
            const bt1 = Time_1.BlockTimestamp.from("2025-01-01T00:00:00");
            const bt2 = Time_1.BlockTimestamp.from("2025-01-01T00:00:00");
            expect(bt1.equals(bt2)).toBe(true);
        });
        test("equals returns false for different times", () => {
            const bt1 = Time_1.BlockTimestamp.from("2025-01-01T00:00:00");
            const bt2 = Time_1.BlockTimestamp.from("2025-06-15T12:00:00");
            expect(bt1.equals(bt2)).toBe(false);
        });
        test("toString returns ISO-like string", () => {
            const bt = Time_1.BlockTimestamp.from("2025-01-01T00:00:00");
            expect(bt.toString()).toContain("2025-01-01");
        });
        test("slot calculation matches formula: (ms - epoch) / interval", () => {
            const ms = constants_1.BLOCK_TIMESTAMP_EPOCH_MS + 10000; // 10 seconds past epoch
            const bt = Time_1.BlockTimestamp.fromMilliseconds(ms);
            const expectedSlot = Math.round((ms - constants_1.BLOCK_TIMESTAMP_EPOCH_MS) / constants_1.BLOCK_TIMESTAMP_INTERVAL_MS);
            expect(Number(bt.value)).toBe(expectedSlot);
        });
    });
});
//# sourceMappingURL=Time.test.js.map