Skip to content

Commit

Permalink
fix: generateRecordCallArray inconsistent with setAbiRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Dec 5, 2023
1 parent 08639f2 commit 447e1e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/ensjs/src/utils/generateRecordCallArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,26 @@ 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(`
[
"0x623195b0eb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
]
`)
})
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({
Expand Down
8 changes: 5 additions & 3 deletions packages/ensjs/src/utils/generateRecordCallArray.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,7 +26,7 @@ export type RecordOptions = Prettify<{
/** Array of coin records */
coins?: Omit<EncodeSetAddrParameters, 'namehash'>[]
/** ABI value */
abi?: Omit<EncodeSetAbiParameters, 'namehash'>
abi?: EncodedAbi | null
}>

export const generateRecordCallArray = ({
Expand All @@ -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)
}

Expand Down

0 comments on commit 447e1e9

Please sign in to comment.