Skip to content

Commit 9fc9aba

Browse files
update legacyRegisterHelpers test
1 parent 984d63a commit 9fc9aba

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

packages/ensjs/src/functions/wallet/legacyRegisterName.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { getNameType } from '../../utils/getNameType.js'
1818
import {
1919
makeLegacyRegistrationTuple,
2020
type LegacyRegistrationParameters,
21-
isLegacyRegistrationWithConfig,
21+
isLegacyRegistrationWithConfigParameters,
2222
makeLegacyRegistrationWithConfigTuple,
2323
} from '../../utils/legacyRegisterHelpers.js'
2424
import {
@@ -61,7 +61,7 @@ export const makeFunctionData = <
6161
details: 'Only 2ld-eth name registration is supported',
6262
})
6363

64-
const data = isLegacyRegistrationWithConfig(args)
64+
const data = isLegacyRegistrationWithConfigParameters(args)
6565
? encodeFunctionData({
6666
abi: legacyEthRegistrarControllerRegisterWithConfigSnippet,
6767
functionName: 'registerWithConfig',

packages/ensjs/src/utils/legacyRegisterHelpers.test.ts

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { type Address, type Hex } from 'viem'
22
import { beforeAll, describe, expect, it } from 'vitest'
33
import {
4-
isLegacyRegistrationWithConfig,
4+
isLegacyRegistrationWithConfigParameters,
55
makeLegacyCommitment,
66
makeLegacyCommitmentTuple,
77
makeLegacyRegistrationTuple,
88
type LegacyRegistrationParameters,
9+
makeLegacyCommitmentWithConfigTuple,
10+
makeLegacyRegistrationWithConfigTuple,
911
} from './legacyRegisterHelpers.js'
1012
import { EMPTY_ADDRESS } from './consts.js'
1113
import { randomSecret } from './registerHelpers.js'
@@ -42,10 +44,10 @@ beforeAll(async () => {
4244
;[owner, address] = accounts
4345
})
4446

45-
describe('isLegacyRegistrationWithConfig', () => {
47+
describe('isLegacyRegistrationWithConfigParameters', () => {
4648
it('return false when resolverAddress and address are undefined', () => {
4749
expect(
48-
isLegacyRegistrationWithConfig({
50+
isLegacyRegistrationWithConfigParameters({
4951
name,
5052
owner,
5153
duration,
@@ -56,7 +58,7 @@ describe('isLegacyRegistrationWithConfig', () => {
5658

5759
it('return false when resolverAddress and address are empty addresses', () => {
5860
expect(
59-
isLegacyRegistrationWithConfig({
61+
isLegacyRegistrationWithConfigParameters({
6062
name,
6163
owner,
6264
duration,
@@ -69,7 +71,7 @@ describe('isLegacyRegistrationWithConfig', () => {
6971

7072
it('return true when resolverAddress and address are defined', () => {
7173
expect(
72-
isLegacyRegistrationWithConfig({
74+
isLegacyRegistrationWithConfigParameters({
7375
name,
7476
owner,
7577
duration,
@@ -82,7 +84,7 @@ describe('isLegacyRegistrationWithConfig', () => {
8284

8385
it('return true when resolverAddress is defined and address is NOT defined', () => {
8486
expect(
85-
isLegacyRegistrationWithConfig({
87+
isLegacyRegistrationWithConfigParameters({
8688
name,
8789
owner,
8890
duration,
@@ -94,7 +96,7 @@ describe('isLegacyRegistrationWithConfig', () => {
9496

9597
it('should throw an error when address is defined and resolverAddress is NOT defined', () => {
9698
expect(() =>
97-
isLegacyRegistrationWithConfig({
99+
isLegacyRegistrationWithConfigParameters({
98100
name,
99101
owner,
100102
duration,
@@ -106,7 +108,7 @@ describe('isLegacyRegistrationWithConfig', () => {
106108

107109
it('should throw an error when address is defined and resolverAddress is empty address', () => {
108110
expect(() =>
109-
isLegacyRegistrationWithConfig({
111+
isLegacyRegistrationWithConfigParameters({
110112
name,
111113
owner,
112114
duration,
@@ -128,9 +130,11 @@ describe('makeLegacyCommitmentTuple', () => {
128130
})
129131
expect(tuple).toEqual(['test', owner, secret])
130132
})
133+
})
131134

135+
describe('makeLegacyCommitmentWithConfigTuple', () => {
132136
it('should return args for makeCommitWithConfig if resolverAddress is defined', () => {
133-
const tuple = makeLegacyCommitmentTuple({
137+
const tuple = makeLegacyCommitmentWithConfigTuple({
134138
name: 'test.eth',
135139
owner,
136140
duration,
@@ -145,18 +149,6 @@ describe('makeLegacyCommitmentTuple', () => {
145149
EMPTY_ADDRESS,
146150
])
147151
})
148-
149-
it('should throw error if resolverAddress is NOT defined and address is defined', () => {
150-
expect(() =>
151-
makeLegacyCommitmentTuple({
152-
name: 'test.eth',
153-
owner,
154-
duration,
155-
secret,
156-
address,
157-
}),
158-
).toThrowErrorMatchingInlineSnapshot(makeSnapshot(address))
159-
})
160152
})
161153

162154
describe('makeLegacyRegistrationTuple', () => {
@@ -174,34 +166,19 @@ describe('makeLegacyRegistrationTuple', () => {
174166
secret,
175167
])
176168
})
169+
})
177170

178-
it('should return args for register if resolverAddress and address are empty addresses', () => {
179-
const params: LegacyRegistrationParameters = {
180-
name,
181-
owner,
182-
duration,
183-
secret,
184-
resolverAddress: EMPTY_ADDRESS,
185-
address: EMPTY_ADDRESS,
186-
}
187-
expect(makeLegacyRegistrationTuple(params)).toEqual([
188-
'test',
189-
owner,
190-
31536000n,
191-
secret,
192-
])
193-
})
194-
195-
it('should return args for register if resolverAddress and address are not undefined', () => {
196-
const params: LegacyRegistrationParameters = {
171+
describe('makeLegacyRegistrationWithConfigTuple', () => {
172+
it('should return args for register if resolverAddress and address are defined', () => {
173+
const tuple = makeLegacyRegistrationWithConfigTuple({
197174
name: 'test.eth',
198175
owner,
199176
duration,
200177
secret,
201178
resolverAddress,
202179
address,
203-
}
204-
expect(makeLegacyRegistrationTuple(params)).toEqual([
180+
})
181+
expect(tuple).toEqual([
205182
'test',
206183
owner,
207184
31536000n,
@@ -254,7 +231,7 @@ describe('makeLegacyCommitment', () => {
254231
client: publicClient,
255232
contract: 'legacyEthRegistrarController',
256233
}),
257-
args: makeLegacyCommitmentTuple(params),
234+
args: makeLegacyCommitmentWithConfigTuple(params),
258235
})
259236

260237
expect(commitment).toBe(commitment2)

packages/ensjs/src/utils/legacyRegisterHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type LegacyRegistrationWithConfigParameters =
2929
address?: Address
3030
}
3131

32-
export const isLegacyRegistrationWithConfig = (
32+
export const isLegacyRegistrationWithConfigParameters = (
3333
params: LegacyRegistrationParameters,
3434
): params is LegacyRegistrationWithConfigParameters => {
3535
const { resolverAddress = EMPTY_ADDRESS, address = EMPTY_ADDRESS } =
@@ -140,7 +140,7 @@ export const makeLegacyCommitmentFromTuple = ([label, ...others]:
140140
export const makeLegacyCommitment = (
141141
params: LegacyRegistrationParameters | LegacyRegistrationWithConfigParameters,
142142
): Hex => {
143-
const touple = isLegacyRegistrationWithConfig(params)
143+
const touple = isLegacyRegistrationWithConfigParameters(params)
144144
? makeLegacyCommitmentWithConfigTuple(params)
145145
: makeLegacyCommitmentTuple(params)
146146
return makeLegacyCommitmentFromTuple(touple)

0 commit comments

Comments
 (0)