diff --git a/packages/ensjs/deploy/00_register_wrapped.ts b/packages/ensjs/deploy/00_register_wrapped.ts index 07eb22d3..cba4bdb5 100644 --- a/packages/ensjs/deploy/00_register_wrapped.ts +++ b/packages/ensjs/deploy/00_register_wrapped.ts @@ -4,6 +4,7 @@ import { BigNumber } from '@ethersproject/bignumber' import { ethers } from 'hardhat' import { DeployFunction } from 'hardhat-deploy/types' import { HardhatRuntimeEnvironment } from 'hardhat/types' +import { MAX_DATE_INT } from '../src/utils/consts' import { encodeFuses } from '../src/utils/fuses' import { namehash } from '../src/utils/normalise' @@ -19,7 +20,7 @@ export const names: { fuses?: number expiry?: number }[] - duration?: number + duration?: number | BigNumber }[] = [ { label: 'wrapped', @@ -42,6 +43,16 @@ export const names: { subnames: [{ label: 'test', namedOwner: 'owner2' }], duration: 2419200, }, + { + label: 'wrapped-big-duration', + namedOwner: 'owner3', + duration: Math.floor((MAX_DATE_INT - Date.now()) / 1000), + }, + { + label: 'wrapped-max-duration', + namedOwner: 'owner3', + duration: BigNumber.from('18446744073709'), + }, { label: 'wrapped-with-expiring-subnames', namedOwner: 'owner', diff --git a/packages/ensjs/hardhat.config.ts b/packages/ensjs/hardhat.config.ts index fe6d6421..6502f626 100644 --- a/packages/ensjs/hardhat.config.ts +++ b/packages/ensjs/hardhat.config.ts @@ -44,6 +44,7 @@ const config: HardhatUserConfig = { default: 1, }, owner2: 2, + owner3: 3, }, external: { contracts: [ diff --git a/packages/ensjs/src/functions/getWrapperData.test.ts b/packages/ensjs/src/functions/getWrapperData.test.ts index 5ce69975..de8d1dde 100644 --- a/packages/ensjs/src/functions/getWrapperData.test.ts +++ b/packages/ensjs/src/functions/getWrapperData.test.ts @@ -69,4 +69,22 @@ describe('getWrapperData', () => { expect(Number.isNaN(result.expiryDate?.getTime())).toBe(false) } }) + it('should return correct expiry for large expiry', async () => { + const result = await ensInstance.getWrapperData('wrapped-big-duration.eth') + expect(result).toBeTruthy() + if (result) { + expect(result.expiryDate).toBeInstanceOf(Date) + expect(result.expiryDate!.getFullYear()).toBe(275760) + expect(Number.isNaN(result.expiryDate?.getTime())).toBe(false) + } + }) + it('should return correct max expiry for expiry larger than maximum for date', async () => { + const result = await ensInstance.getWrapperData('wrapped-max-duration.eth') + expect(result).toBeTruthy() + if (result) { + expect(result.expiryDate).toBeInstanceOf(Date) + expect(result.expiryDate!.getFullYear()).toBe(275760) + expect(Number.isNaN(result.expiryDate?.getTime())).toBe(false) + } + }) }) diff --git a/packages/ensjs/src/functions/getWrapperData.ts b/packages/ensjs/src/functions/getWrapperData.ts index 309a0c19..761dbcac 100644 --- a/packages/ensjs/src/functions/getWrapperData.ts +++ b/packages/ensjs/src/functions/getWrapperData.ts @@ -1,5 +1,6 @@ import { BigNumber } from '@ethersproject/bignumber' import { ENSArgs } from '../index' +import { MAX_DATE_INT } from '../utils/consts' import { decodeFuses } from '../utils/fuses' import { namehash } from '../utils/normalise' @@ -21,10 +22,16 @@ const decode = async ({ contracts }: ENSArgs<'contracts'>, data: string) => { const fuseObj = decodeFuses(fuses) - const expiryDate = - expiry.gt(0) && expiry.lt(BigNumber.from(2).pow(32)) - ? new Date(expiry.mul(1000).toNumber()) - : undefined + let expiryDate: Date | undefined + + if (expiry.gt(0)) { + const msBigNumber = expiry.mul(1000) + if (msBigNumber.gte(MAX_DATE_INT)) { + expiryDate = new Date(MAX_DATE_INT) + } else { + expiryDate = new Date(msBigNumber.toNumber()) + } + } return { ...fuseObj, diff --git a/packages/ensjs/src/utils/consts.ts b/packages/ensjs/src/utils/consts.ts index 542d5c99..faf5c371 100644 --- a/packages/ensjs/src/utils/consts.ts +++ b/packages/ensjs/src/utils/consts.ts @@ -1,3 +1,4 @@ export const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000' export const MAX_INT_64 = BigInt('18446744073709551615') +export const MAX_DATE_INT = 8640000000000000 export const MINIMUM_DOT_ETH_CHARS = 3