Skip to content

Commit

Permalink
test: update clock tests to run deterministically (ChainSafe#6828)
Browse files Browse the repository at this point in the history
* Fix test case

* Lint

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
  • Loading branch information
divyesh87 and nflaig committed Jun 17, 2024
1 parent f29a6db commit 7e35c92
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/validator/test/unit/utils/clock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ describe("util / Clock", function () {
// eslint-disable-next-line @typescript-eslint/naming-convention
const testConfig = {SECONDS_PER_SLOT: 12} as BeaconConfig;
const genesisTime = Math.floor(new Date("2021-01-01").getTime() / 1000);

// Tests can fail under certain time slots, overriding the system time
// with a specific value allows us to run tests deterministically
beforeEach(() => {
vi.setSystemTime(genesisTime * 1000);
});

const testCase: {name: string; delta: number}[] = [
{name: "should return next slot after 11.5s", delta: 11.5},
{name: "should return next slot after 12s", delta: 12},
Expand Down

0 comments on commit 7e35c92

Please sign in to comment.