Skip to content

Commit

Permalink
resolver address error
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Mar 15, 2024
1 parent ab2de56 commit aa262fe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/ensjs/src/errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ export class UnknownContentTypeError extends BaseError {
super(`Unknown content type: ${contentType}`)
}
}

export class ResolverAddressRequiredError extends BaseError {
override name = 'ResolverAddressRequiredError'

constructor() {
super('Resolver address is required when data is supplied')
}
}
25 changes: 25 additions & 0 deletions packages/ensjs/src/utils/registerHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('makeCommitmentTuple()', () => {
duration: 31536000,
secret: '0xsecret',
reverseRecord: true,
resolverAddress: '0xresolverAddress',
})
expect(tuple[5]).toMatchInlineSnapshot(`
[
Expand All @@ -100,6 +101,7 @@ describe('makeCommitmentTuple()', () => {
{ coin: 'ETH', value: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' },
],
},
resolverAddress: '0xresolverAddress',
secret: '0xsecret',
reverseRecord: true,
})
Expand All @@ -110,6 +112,29 @@ describe('makeCommitmentTuple()', () => {
`)
expect(tuple[6]).toBe(true)
})
it('throws when records are supplied without a resolver address', () => {
expect(() =>
makeCommitmentTuple({
name: 'test.eth',
owner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
duration: 31536000,
records: {
coins: [
{
coin: 'ETH',
value: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
},
],
},
secret: '0xsecret',
reverseRecord: true,
}),
).toThrowErrorMatchingInlineSnapshot(`
[ResolverAddressRequiredError: Resolver address is required when data is supplied
Version: @ensdomains/[email protected]]
`)
})
})

describe('makeRegistrationTuple()', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/ensjs/src/utils/registerHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
type Address,
type Hex,
} from 'viem'
import { CampaignReferenceTooLargeError } from '../errors/utils.js'
import {
CampaignReferenceTooLargeError,
ResolverAddressRequiredError,
} from '../errors/utils.js'
import { EMPTY_ADDRESS } from './consts.js'
import { encodeFuses, type EncodeChildFusesInputObject } from './fuses.js'
import {
Expand Down Expand Up @@ -121,6 +124,9 @@ export const makeCommitmentTuple = ({
? generateRecordCallArray({ namehash: hash, coins, ...records })
: []

if (data.length > 0 && resolverAddress === EMPTY_ADDRESS)
throw new ResolverAddressRequiredError()

return [
labelHash,
owner,
Expand Down

0 comments on commit aa262fe

Please sign in to comment.