Skip to content

Commit

Permalink
Fix clock flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Feb 6, 2024
1 parent c4bf385 commit 5841079
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/validator/src/util/clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class Clock implements IClock {
*/
export function getCurrentSlotAround(config: ChainForkConfig, genesisTime: TimeSeconds): Slot {
const diffInSeconds = Date.now() / 1000 - genesisTime;
const slotsSinceGenesis = Math.round(diffInSeconds / config.SECONDS_PER_SLOT);
const slotsSinceGenesis = Math.floor(diffInSeconds / config.SECONDS_PER_SLOT);
return GENESIS_SLOT + slotsSinceGenesis;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/validator/test/unit/utils/clock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe("util / Clock", function () {

beforeEach(() => {
controller = new AbortController();
vi.useFakeTimers();
// Feb 6, 2024 11:21:17.786 AM
vi.useFakeTimers({now: 1707214877786});
});

afterEach(() => {
Expand Down

0 comments on commit 5841079

Please sign in to comment.