From aa262fe234d5a4b09c6f62d255b35248912e3d99 Mon Sep 17 00:00:00 2001 From: tate Date: Fri, 15 Mar 2024 11:20:02 +0000 Subject: [PATCH] resolver address error --- packages/ensjs/src/errors/utils.ts | 8 ++++++ .../ensjs/src/utils/registerHelpers.test.ts | 25 +++++++++++++++++++ packages/ensjs/src/utils/registerHelpers.ts | 8 +++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/ensjs/src/errors/utils.ts b/packages/ensjs/src/errors/utils.ts index 6f28eaf9..f8255a02 100644 --- a/packages/ensjs/src/errors/utils.ts +++ b/packages/ensjs/src/errors/utils.ts @@ -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') + } +} diff --git a/packages/ensjs/src/utils/registerHelpers.test.ts b/packages/ensjs/src/utils/registerHelpers.test.ts index 924fdf58..dca7b7be 100644 --- a/packages/ensjs/src/utils/registerHelpers.test.ts +++ b/packages/ensjs/src/utils/registerHelpers.test.ts @@ -82,6 +82,7 @@ describe('makeCommitmentTuple()', () => { duration: 31536000, secret: '0xsecret', reverseRecord: true, + resolverAddress: '0xresolverAddress', }) expect(tuple[5]).toMatchInlineSnapshot(` [ @@ -100,6 +101,7 @@ describe('makeCommitmentTuple()', () => { { coin: 'ETH', value: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' }, ], }, + resolverAddress: '0xresolverAddress', secret: '0xsecret', reverseRecord: true, }) @@ -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/ensjs@1.0.0-mock.0] + `) + }) }) describe('makeRegistrationTuple()', () => { diff --git a/packages/ensjs/src/utils/registerHelpers.ts b/packages/ensjs/src/utils/registerHelpers.ts index 31a764ed..dd8202f7 100644 --- a/packages/ensjs/src/utils/registerHelpers.ts +++ b/packages/ensjs/src/utils/registerHelpers.ts @@ -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 { @@ -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,