From 447e1e9b1b8663cff72d032b670a6407cb5372e7 Mon Sep 17 00:00:00 2001 From: tate Date: Tue, 5 Dec 2023 13:38:44 +1100 Subject: [PATCH] fix: generateRecordCallArray inconsistent with setAbiRecord --- .../ensjs/src/utils/generateRecordCallArray.test.ts | 12 ++++++++++-- packages/ensjs/src/utils/generateRecordCallArray.ts | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/ensjs/src/utils/generateRecordCallArray.test.ts b/packages/ensjs/src/utils/generateRecordCallArray.test.ts index c96142ff..5dd3cd54 100644 --- a/packages/ensjs/src/utils/generateRecordCallArray.test.ts +++ b/packages/ensjs/src/utils/generateRecordCallArray.test.ts @@ -44,11 +44,11 @@ it('adds contentHash call when contentHash is defined', () => { ] `) }) -it('adds abi call when abi is defined', () => { +it('adds abi call when abi is null', () => { expect( generateRecordCallArray({ namehash: namehash('test.eth'), - abi: { contentType: 0, encodedData: '0x' }, + abi: null, }), ).toMatchInlineSnapshot(` [ @@ -56,6 +56,14 @@ it('adds abi call when abi is defined', () => { ] `) }) +it('does not add abi call when abi is undefined', () => { + expect( + generateRecordCallArray({ + namehash: namehash('test.eth'), + abi: undefined, + }), + ).toMatchInlineSnapshot(`[]`) +}) it('adds text calls when texts array is defined and not empty', () => { expect( generateRecordCallArray({ diff --git a/packages/ensjs/src/utils/generateRecordCallArray.ts b/packages/ensjs/src/utils/generateRecordCallArray.ts index 7a627ddd..5d68622a 100644 --- a/packages/ensjs/src/utils/generateRecordCallArray.ts +++ b/packages/ensjs/src/utils/generateRecordCallArray.ts @@ -1,5 +1,6 @@ import { type Hex } from 'viem' import type { Prettify } from '../types.js' +import type { EncodedAbi } from './encoders/encodeAbi.js' import { encodeClearRecords } from './encoders/encodeClearRecords.js' import { encodeSetAbi, @@ -25,7 +26,7 @@ export type RecordOptions = Prettify<{ /** Array of coin records */ coins?: Omit[] /** ABI value */ - abi?: Omit + abi?: EncodedAbi | null }> export const generateRecordCallArray = ({ @@ -47,8 +48,9 @@ export const generateRecordCallArray = ({ if (data) calls.push(data) } - if (abi) { - const data = encodeSetAbi({ namehash, ...abi } as EncodeSetAbiParameters) + if (abi !== undefined) { + const abi_ = abi ?? { contentType: 0, encodedData: null } + const data = encodeSetAbi({ namehash, ...abi_ } as EncodeSetAbiParameters) if (data) calls.push(data) }