Fix flakey endorsements expiration test
This commit is contained in:
parent
7f8cb5f0a4
commit
c04ba6b9a9
2 changed files with 6 additions and 4 deletions
|
@ -8,8 +8,9 @@ import { DAY, HOUR, SECOND } from '../../util/durations';
|
|||
describe('groupSendEndorsements', () => {
|
||||
describe('validateGroupSendEndorsementsExpiration', () => {
|
||||
function validateDistance(distance: number) {
|
||||
const expiration = Date.now() + distance;
|
||||
return validateGroupSendEndorsementsExpiration(expiration);
|
||||
const now = Date.now();
|
||||
const expiration = now + distance;
|
||||
return validateGroupSendEndorsementsExpiration(expiration, now);
|
||||
}
|
||||
|
||||
function checkValid(label: string, distance: number) {
|
||||
|
|
|
@ -134,10 +134,11 @@ export type ValidationResult =
|
|||
| { valid: false; reason: string };
|
||||
|
||||
export function validateGroupSendEndorsementsExpiration(
|
||||
expiration: number
|
||||
expiration: number,
|
||||
now: number = Date.now()
|
||||
): ValidationResult {
|
||||
const expSeconds = DurationInSeconds.fromMillis(expiration);
|
||||
const nowSeconds = DurationInSeconds.fromMillis(Date.now());
|
||||
const nowSeconds = DurationInSeconds.fromMillis(now);
|
||||
const info = `now: ${nowSeconds}, exp: ${expSeconds}`;
|
||||
if (expSeconds <= nowSeconds) {
|
||||
return { valid: false, reason: `already expired, ${info}` };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue