Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
fix: transfer tests for buildTimePeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
lightwalker-eth committed Apr 29, 2024
1 parent 0fd5225 commit 93d7342
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/time.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";

import { buildTimestamp, buildTimestampMs, fromTimestampToDate, msToSeconds, now } from "./time";
import { addSeconds, buildTimePeriod, buildTimestamp, buildTimestampMs, fromTimestampToDate, msToSeconds, now } from "./time";

describe("msToSeconds() function", () => {
it("Correctly returns 0s for less than 1000ms params", () => {
Expand Down Expand Up @@ -70,3 +70,28 @@ describe("fromTimestampToDate() function", () => {
);
});
});

describe("buildTimePeriod function", () => {
it("Correctly creates new TimePeriod", () => {
const nowTime = now();
const period = buildTimePeriod(nowTime, addSeconds(nowTime, 1000n));

expect(period.begin).toStrictEqual(nowTime);
expect(period.end).toStrictEqual(addSeconds(nowTime, 1000n));
});

it("Correctly creates new TimePeriod when both Timestamps are equal", () => {
const nowTime = now();
const period = buildTimePeriod(nowTime, nowTime);

expect(period.begin).toStrictEqual(nowTime);
expect(period.end).toStrictEqual(nowTime);
});

it("Throws error on smaller end Timestamp provided", () => {
const nowTime = now();
expect(() => {
buildTimePeriod(addSeconds(nowTime, 1000n), nowTime);
}).toThrow();
});
});

0 comments on commit 93d7342

Please sign in to comment.