diff --git a/packages/ensnode-sdk/src/registrars/registration-expiration.test.ts b/packages/ensnode-sdk/src/registrars/registration-expiration.test.ts new file mode 100644 index 0000000000..35c9294103 --- /dev/null +++ b/packages/ensnode-sdk/src/registrars/registration-expiration.test.ts @@ -0,0 +1,67 @@ +import { describe, expect, it } from "vitest"; + +import { + isRegistrationExpired, + isRegistrationFullyExpired, + isRegistrationInGracePeriod, +} from "./registration-expiration"; + +describe("registration expiration", () => { + const expiry = 1000n; + const gracePeriod = 100n; + + describe("isRegistrationExpired", () => { + it.each([ + { now: 999n, expected: false, description: "before expiry" }, + { now: 1000n, expected: true, description: "at expiry" }, + { now: 1001n, expected: true, description: "after expiry" }, + ])("returns $expected when $description", ({ now, expected }) => { + expect(isRegistrationExpired({ expiry, gracePeriod }, now)).toBe(expected); + }); + + it("returns false when expiry is null", () => { + expect(isRegistrationExpired({ expiry: null, gracePeriod }, 2000n)).toBe(false); + }); + }); + + describe("isRegistrationFullyExpired", () => { + it.each([ + { now: 999n, expected: false, description: "before expiry" }, + { now: 1000n, expected: false, description: "at expiry" }, + { now: 1050n, expected: false, description: "during grace period" }, + { now: 1100n, expected: false, description: "at expiry + grace period" }, + { now: 1101n, expected: true, description: "after expiry + grace period" }, + ])("returns $expected when $description", ({ now, expected }) => { + expect(isRegistrationFullyExpired({ expiry, gracePeriod }, now)).toBe(expected); + }); + + it("returns false when expiry is null", () => { + expect(isRegistrationFullyExpired({ expiry: null, gracePeriod }, 2000n)).toBe(false); + }); + + it("treats null grace period as zero", () => { + expect(isRegistrationFullyExpired({ expiry, gracePeriod: null }, 1000n)).toBe(false); + expect(isRegistrationFullyExpired({ expiry, gracePeriod: null }, 1001n)).toBe(true); + }); + }); + + describe("isRegistrationInGracePeriod", () => { + it.each([ + { now: 999n, expected: false, description: "before expiry" }, + { now: 1000n, expected: true, description: "at expiry" }, + { now: 1050n, expected: true, description: "during grace period" }, + { now: 1100n, expected: false, description: "at expiry + grace period" }, + { now: 1101n, expected: false, description: "after expiry + grace period" }, + ])("returns $expected when $description", ({ now, expected }) => { + expect(isRegistrationInGracePeriod({ expiry, gracePeriod }, now)).toBe(expected); + }); + + it("returns false when expiry is null", () => { + expect(isRegistrationInGracePeriod({ expiry: null, gracePeriod }, 1050n)).toBe(false); + }); + + it("returns false when grace period is null", () => { + expect(isRegistrationInGracePeriod({ expiry, gracePeriod: null }, 1050n)).toBe(false); + }); + }); +}); diff --git a/packages/ensnode-sdk/src/registrars/registration-expiration.ts b/packages/ensnode-sdk/src/registrars/registration-expiration.ts index b81e7d696e..27a92c778a 100644 --- a/packages/ensnode-sdk/src/registrars/registration-expiration.ts +++ b/packages/ensnode-sdk/src/registrars/registration-expiration.ts @@ -23,8 +23,8 @@ export function isRegistrationFullyExpired(info: RegistrationExpiryInfo, now: bi // no expiry, never expired if (info.expiry == null) return false; - // otherwise it is expired if now >= expiry + grace - return now >= info.expiry + (info.gracePeriod ?? 0n); + // otherwise it is expired if now > expiry + grace + return now > info.expiry + (info.gracePeriod ?? 0n); } /**