Skip to content

Commit

Permalink
update legacyRegisterHelpers test
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Jan 10, 2025
1 parent 984d63a commit 9fc9aba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 47 deletions.
4 changes: 2 additions & 2 deletions packages/ensjs/src/functions/wallet/legacyRegisterName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getNameType } from '../../utils/getNameType.js'
import {
makeLegacyRegistrationTuple,
type LegacyRegistrationParameters,
isLegacyRegistrationWithConfig,
isLegacyRegistrationWithConfigParameters,
makeLegacyRegistrationWithConfigTuple,
} from '../../utils/legacyRegisterHelpers.js'
import {
Expand Down Expand Up @@ -61,7 +61,7 @@ export const makeFunctionData = <
details: 'Only 2ld-eth name registration is supported',
})

const data = isLegacyRegistrationWithConfig(args)
const data = isLegacyRegistrationWithConfigParameters(args)
? encodeFunctionData({
abi: legacyEthRegistrarControllerRegisterWithConfigSnippet,
functionName: 'registerWithConfig',
Expand Down
63 changes: 20 additions & 43 deletions packages/ensjs/src/utils/legacyRegisterHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { type Address, type Hex } from 'viem'
import { beforeAll, describe, expect, it } from 'vitest'
import {
isLegacyRegistrationWithConfig,
isLegacyRegistrationWithConfigParameters,
makeLegacyCommitment,
makeLegacyCommitmentTuple,
makeLegacyRegistrationTuple,
type LegacyRegistrationParameters,
makeLegacyCommitmentWithConfigTuple,
makeLegacyRegistrationWithConfigTuple,
} from './legacyRegisterHelpers.js'
import { EMPTY_ADDRESS } from './consts.js'
import { randomSecret } from './registerHelpers.js'
Expand Down Expand Up @@ -42,10 +44,10 @@ beforeAll(async () => {
;[owner, address] = accounts
})

describe('isLegacyRegistrationWithConfig', () => {
describe('isLegacyRegistrationWithConfigParameters', () => {
it('return false when resolverAddress and address are undefined', () => {
expect(
isLegacyRegistrationWithConfig({
isLegacyRegistrationWithConfigParameters({
name,
owner,
duration,
Expand All @@ -56,7 +58,7 @@ describe('isLegacyRegistrationWithConfig', () => {

it('return false when resolverAddress and address are empty addresses', () => {
expect(
isLegacyRegistrationWithConfig({
isLegacyRegistrationWithConfigParameters({
name,
owner,
duration,
Expand All @@ -69,7 +71,7 @@ describe('isLegacyRegistrationWithConfig', () => {

it('return true when resolverAddress and address are defined', () => {
expect(
isLegacyRegistrationWithConfig({
isLegacyRegistrationWithConfigParameters({
name,
owner,
duration,
Expand All @@ -82,7 +84,7 @@ describe('isLegacyRegistrationWithConfig', () => {

it('return true when resolverAddress is defined and address is NOT defined', () => {
expect(
isLegacyRegistrationWithConfig({
isLegacyRegistrationWithConfigParameters({
name,
owner,
duration,
Expand All @@ -94,7 +96,7 @@ describe('isLegacyRegistrationWithConfig', () => {

it('should throw an error when address is defined and resolverAddress is NOT defined', () => {
expect(() =>
isLegacyRegistrationWithConfig({
isLegacyRegistrationWithConfigParameters({
name,
owner,
duration,
Expand All @@ -106,7 +108,7 @@ describe('isLegacyRegistrationWithConfig', () => {

it('should throw an error when address is defined and resolverAddress is empty address', () => {
expect(() =>
isLegacyRegistrationWithConfig({
isLegacyRegistrationWithConfigParameters({
name,
owner,
duration,
Expand All @@ -128,9 +130,11 @@ describe('makeLegacyCommitmentTuple', () => {
})
expect(tuple).toEqual(['test', owner, secret])
})
})

describe('makeLegacyCommitmentWithConfigTuple', () => {
it('should return args for makeCommitWithConfig if resolverAddress is defined', () => {
const tuple = makeLegacyCommitmentTuple({
const tuple = makeLegacyCommitmentWithConfigTuple({
name: 'test.eth',
owner,
duration,
Expand All @@ -145,18 +149,6 @@ describe('makeLegacyCommitmentTuple', () => {
EMPTY_ADDRESS,
])
})

it('should throw error if resolverAddress is NOT defined and address is defined', () => {
expect(() =>
makeLegacyCommitmentTuple({
name: 'test.eth',
owner,
duration,
secret,
address,
}),
).toThrowErrorMatchingInlineSnapshot(makeSnapshot(address))
})
})

describe('makeLegacyRegistrationTuple', () => {
Expand All @@ -174,34 +166,19 @@ describe('makeLegacyRegistrationTuple', () => {
secret,
])
})
})

it('should return args for register if resolverAddress and address are empty addresses', () => {
const params: LegacyRegistrationParameters = {
name,
owner,
duration,
secret,
resolverAddress: EMPTY_ADDRESS,
address: EMPTY_ADDRESS,
}
expect(makeLegacyRegistrationTuple(params)).toEqual([
'test',
owner,
31536000n,
secret,
])
})

it('should return args for register if resolverAddress and address are not undefined', () => {
const params: LegacyRegistrationParameters = {
describe('makeLegacyRegistrationWithConfigTuple', () => {
it('should return args for register if resolverAddress and address are defined', () => {
const tuple = makeLegacyRegistrationWithConfigTuple({
name: 'test.eth',
owner,
duration,
secret,
resolverAddress,
address,
}
expect(makeLegacyRegistrationTuple(params)).toEqual([
})
expect(tuple).toEqual([
'test',
owner,
31536000n,
Expand Down Expand Up @@ -254,7 +231,7 @@ describe('makeLegacyCommitment', () => {
client: publicClient,
contract: 'legacyEthRegistrarController',
}),
args: makeLegacyCommitmentTuple(params),
args: makeLegacyCommitmentWithConfigTuple(params),
})

expect(commitment).toBe(commitment2)
Expand Down
4 changes: 2 additions & 2 deletions packages/ensjs/src/utils/legacyRegisterHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type LegacyRegistrationWithConfigParameters =
address?: Address
}

export const isLegacyRegistrationWithConfig = (
export const isLegacyRegistrationWithConfigParameters = (
params: LegacyRegistrationParameters,
): params is LegacyRegistrationWithConfigParameters => {
const { resolverAddress = EMPTY_ADDRESS, address = EMPTY_ADDRESS } =
Expand Down Expand Up @@ -140,7 +140,7 @@ export const makeLegacyCommitmentFromTuple = ([label, ...others]:
export const makeLegacyCommitment = (
params: LegacyRegistrationParameters | LegacyRegistrationWithConfigParameters,
): Hex => {
const touple = isLegacyRegistrationWithConfig(params)
const touple = isLegacyRegistrationWithConfigParameters(params)
? makeLegacyCommitmentWithConfigTuple(params)
: makeLegacyCommitmentTuple(params)
return makeLegacyCommitmentFromTuple(touple)
Expand Down

0 comments on commit 9fc9aba

Please sign in to comment.