From 4d7044e89078783e5aeef010a44d2d6555298b4a Mon Sep 17 00:00:00 2001 From: tate Date: Wed, 5 Apr 2023 13:56:23 +1000 Subject: [PATCH 1/3] fix: correct max date int in getWrapperData --- packages/ensjs/src/functions/getWrapperData.ts | 3 ++- packages/ensjs/src/utils/consts.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ensjs/src/functions/getWrapperData.ts b/packages/ensjs/src/functions/getWrapperData.ts index 309a0c19..7856d877 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' @@ -22,7 +23,7 @@ const decode = async ({ contracts }: ENSArgs<'contracts'>, data: string) => { const fuseObj = decodeFuses(fuses) const expiryDate = - expiry.gt(0) && expiry.lt(BigNumber.from(2).pow(32)) + expiry.gt(0) && expiry.lte(MAX_DATE_INT) ? new Date(expiry.mul(1000).toNumber()) : undefined 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 From adde4bd3956caf9c98598239f286a93c44d3db6c Mon Sep 17 00:00:00 2001 From: tate Date: Wed, 5 Apr 2023 14:01:42 +1000 Subject: [PATCH 2/3] set to max if above max --- packages/ensjs/src/functions/getWrapperData.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/ensjs/src/functions/getWrapperData.ts b/packages/ensjs/src/functions/getWrapperData.ts index 7856d877..761dbcac 100644 --- a/packages/ensjs/src/functions/getWrapperData.ts +++ b/packages/ensjs/src/functions/getWrapperData.ts @@ -22,10 +22,16 @@ const decode = async ({ contracts }: ENSArgs<'contracts'>, data: string) => { const fuseObj = decodeFuses(fuses) - const expiryDate = - expiry.gt(0) && expiry.lte(MAX_DATE_INT) - ? 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, From 216d1f113107ada89c7be60f857fc35ce140ed99 Mon Sep 17 00:00:00 2001 From: tate Date: Wed, 5 Apr 2023 14:22:10 +1000 Subject: [PATCH 3/3] add test --- packages/ensjs/deploy/00_register_wrapped.ts | 13 ++++++++++++- packages/ensjs/hardhat.config.ts | 1 + .../ensjs/src/functions/getWrapperData.test.ts | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) 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) + } + }) })