Skip to content

Commit 98038ee

Browse files
Fix test mocks for wrapped name desync detection
The wrapper data mock was using GRACE_PERIOD (milliseconds) while the expiry mock uses gracePeriod in seconds, causing unit mismatch in the isWrappedNameDesynced check. This made all wrapped name tests fail with unexpected 'desynced' status. - Replace GRACE_PERIOD constant with 7776000 (seconds) in wrapper mock - Add grace-period variants for emancipated and locked wrapper data types - Update test configs to use correct grace-period wrapper types - Fix typo: "licked" -> "locked" in test name Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 269996d commit 98038ee

File tree

3 files changed

+111
-15
lines changed

3 files changed

+111
-15
lines changed

src/hooks/nameType/useNameType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe('useNameType', () => {
155155
expect(result.current.data).toEqual('eth-emancipated-2ld:grace-period')
156156
})
157157

158-
it('should return for grace period licked', async () => {
158+
it('should return for grace period locked', async () => {
159159
mockBasicData.mockReturnValue(makeMockUseBasicName('eth-locked-2ld:grace-period'))
160160
const { result } = renderHook(() => useNameType('name.eth'))
161161
expect(result.current.data).toEqual('eth-locked-2ld:grace-period')

test/mock/makeMockUseBasicName.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ export const mockUseBasicNameConfig = {
8787
'eth-emancipated-2ld:grace-period': {
8888
useValidateType: 'valid-2ld',
8989
useOwnerType: 'namewrapper:grace-period',
90-
useWrapperDataType: 'emancipated',
90+
useWrapperDataType: 'emancipated:grace-period',
9191
useExpiryType: 'grace-period',
9292
usePriceType: 'base',
9393
} as MockUseBasicNameConfig,
9494
'eth-emancipated-2ld:grace-period:unowned': {
9595
useValidateType: 'valid-2ld',
9696
useOwnerType: 'namewrapper:grace-period',
97-
useWrapperDataType: 'emancipated:unowned',
97+
useWrapperDataType: 'emancipated:grace-period:unowned',
9898
useExpiryType: 'grace-period',
9999
usePriceType: 'base',
100100
} as MockUseBasicNameConfig,
@@ -115,14 +115,14 @@ export const mockUseBasicNameConfig = {
115115
'eth-locked-2ld:grace-period': {
116116
useValidateType: 'valid-2ld',
117117
useOwnerType: 'namewrapper:grace-period',
118-
useWrapperDataType: 'locked',
118+
useWrapperDataType: 'locked:grace-period',
119119
useExpiryType: 'grace-period',
120120
usePriceType: 'base',
121121
} as MockUseBasicNameConfig,
122122
'eth-locked-2ld:grace-period:unowned': {
123123
useValidateType: 'valid-2ld',
124124
useOwnerType: 'namewrapper:grace-period',
125-
useWrapperDataType: 'locked:unowned',
125+
useWrapperDataType: 'locked:grace-period:unowned',
126126
useExpiryType: 'grace-period',
127127
usePriceType: 'base',
128128
} as MockUseBasicNameConfig,

test/mock/makeMockUseWrapperDataData.ts.ts

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { Address } from 'viem'
55

66
import { GetWrapperDataReturnType } from '@ensdomains/ensjs/public'
77

8-
import { GRACE_PERIOD } from '@app/utils/constants'
9-
108
import { createAccounts } from '../../playwright/fixtures/accounts'
119

1210
const mockUseWrapperDataTypes = [
1311
'wrapped',
1412
'wrapped:unowned',
1513
'emancipated',
1614
'emancipated:unowned',
15+
'emancipated:grace-period',
16+
'emancipated:grace-period:unowned',
1717
'locked',
1818
'locked:unowned',
19+
'locked:grace-period',
20+
'locked:grace-period:unowned',
1921
'burnt',
2022
'burnt:unowned',
2123
] as const
@@ -67,8 +69,8 @@ export const makeMockUseWrapperDataData = (
6769
value: 0,
6870
},
6971
expiry: {
70-
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
71-
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
72+
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
73+
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
7274
},
7375
owner: _type.endsWith('unowned') ? user2Address : userAddress,
7476
}))
@@ -111,8 +113,55 @@ export const makeMockUseWrapperDataData = (
111113
value: 196608,
112114
},
113115
expiry: {
114-
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
115-
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
116+
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
117+
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
118+
},
119+
owner: _type.endsWith('unowned') ? user2Address : userAddress,
120+
}))
121+
.with(P.union('emancipated:grace-period', 'emancipated:grace-period:unowned'), (_type) => ({
122+
fuses: {
123+
parent: {
124+
PARENT_CANNOT_CONTROL: true,
125+
CAN_EXTEND_EXPIRY: false,
126+
IS_DOT_ETH: true,
127+
unnamed: {
128+
'0x80000': false,
129+
'0x100000': false,
130+
'0x200000': false,
131+
'0x400000': false,
132+
'0x800000': false,
133+
'0x1000000': false,
134+
},
135+
},
136+
child: {
137+
CANNOT_UNWRAP: false,
138+
CANNOT_BURN_FUSES: false,
139+
CANNOT_TRANSFER: false,
140+
CANNOT_SET_RESOLVER: false,
141+
CANNOT_SET_TTL: false,
142+
CANNOT_CREATE_SUBDOMAIN: false,
143+
CANNOT_APPROVE: false,
144+
unnamed: {
145+
'0x80': false,
146+
'0x100': false,
147+
'0x200': false,
148+
'0x400': false,
149+
'0x800': false,
150+
'0x1000': false,
151+
'0x2000': false,
152+
'0x4000': false,
153+
'0x8000': false,
154+
},
155+
CAN_DO_EVERYTHING: true,
156+
},
157+
value: 196608,
158+
},
159+
// Grace period wrapper expiry = registrar expiry + gracePeriod
160+
// Registrar expiry for grace-period mock = Date.now() - 7776000/2
161+
// So wrapper expiry = Date.now() - 7776000/2 + 7776000 = Date.now() + 7776000/2
162+
expiry: {
163+
date: new Date(Date.now() + 7776000 / 2),
164+
value: BigInt(Date.now() + 7776000 / 2),
116165
},
117166
owner: _type.endsWith('unowned') ? user2Address : userAddress,
118167
}))
@@ -155,8 +204,55 @@ export const makeMockUseWrapperDataData = (
155204
value: 196609,
156205
},
157206
expiry: {
158-
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
159-
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
207+
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
208+
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
209+
},
210+
owner: _type.endsWith('unowned') ? user2Address : userAddress,
211+
}))
212+
.with(P.union('locked:grace-period', 'locked:grace-period:unowned'), (_type) => ({
213+
fuses: {
214+
parent: {
215+
PARENT_CANNOT_CONTROL: true,
216+
CAN_EXTEND_EXPIRY: false,
217+
IS_DOT_ETH: true,
218+
unnamed: {
219+
'0x80000': false,
220+
'0x100000': false,
221+
'0x200000': false,
222+
'0x400000': false,
223+
'0x800000': false,
224+
'0x1000000': false,
225+
},
226+
},
227+
child: {
228+
CANNOT_UNWRAP: true,
229+
CANNOT_BURN_FUSES: false,
230+
CANNOT_TRANSFER: false,
231+
CANNOT_SET_RESOLVER: false,
232+
CANNOT_SET_TTL: false,
233+
CANNOT_CREATE_SUBDOMAIN: false,
234+
CANNOT_APPROVE: false,
235+
unnamed: {
236+
'0x80': false,
237+
'0x100': false,
238+
'0x200': false,
239+
'0x400': false,
240+
'0x800': false,
241+
'0x1000': false,
242+
'0x2000': false,
243+
'0x4000': false,
244+
'0x8000': false,
245+
},
246+
CAN_DO_EVERYTHING: false,
247+
},
248+
value: 196609,
249+
},
250+
// Grace period wrapper expiry = registrar expiry + gracePeriod
251+
// Registrar expiry for grace-period mock = Date.now() - 7776000/2
252+
// So wrapper expiry = Date.now() - 7776000/2 + 7776000 = Date.now() + 7776000/2
253+
expiry: {
254+
date: new Date(Date.now() + 7776000 / 2),
255+
value: BigInt(Date.now() + 7776000 / 2),
160256
},
161257
owner: _type.endsWith('unowned') ? user2Address : userAddress,
162258
}))
@@ -199,8 +295,8 @@ export const makeMockUseWrapperDataData = (
199295
value: 196735,
200296
},
201297
expiry: {
202-
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
203-
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + GRACE_PERIOD),
298+
date: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
299+
value: BigInt(Date.now() + 1000 * 60 * 60 * 24 * 365 + 7776000),
204300
},
205301
owner: _type.endsWith('unowned') ? user2Address : userAddress,
206302
}))

0 commit comments

Comments
 (0)