Skip to content

Commit

Permalink
Merge pull request #130 from ensdomains/fix/empty-contenthash-set
Browse files Browse the repository at this point in the history
fix: allow setting empty contenthash
  • Loading branch information
LeonmanRolls authored Apr 12, 2023
2 parents 6a6e4cb + 7a7b633 commit 9e53c56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion packages/ensjs/src/utils/recordHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PublicResolver__factory } from '../generated'
import { namehash } from './normalise'
import { generateSetAddr } from './recordHelpers'
import { generateRecordCallArray, generateSetAddr } from './recordHelpers'

describe('generateSetAddr()', () => {
it('should allow empty string as address', () => {
Expand All @@ -17,3 +17,20 @@ describe('generateSetAddr()', () => {
).not.toThrowError()
})
})

describe('generateRecordCallArray()', () => {
it('should allow empty string as contenthash', () => {
expect(
generateRecordCallArray(
namehash('test'),
{ contentHash: '' },
PublicResolver__factory.connect(
'0x0000000000000000000000000000000000000000',
undefined as any,
),
),
).toEqual([
'0x304e6ade04f740db81dc36c853ab4205bddd785f46e79ccedca351fc6dfcbd8cc9a33dd600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000',
])
})
})
4 changes: 3 additions & 1 deletion packages/ensjs/src/utils/recordHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export function generateSingleRecordCall<T extends RecordTypes>(
const encoded = encodeContenthash(record)
if (encoded.error) throw new Error(encoded.error)
_contentHash = encoded.encoded as string
} else {
_contentHash = '0x'
}
return resolver.interface.encodeFunctionData('setContenthash', [
namehash,
Expand Down Expand Up @@ -150,7 +152,7 @@ export const generateRecordCallArray = (
)
}

if (records.contentHash) {
if (typeof records.contentHash === 'string') {
const data = generateSingleRecordCall(
namehash,
resolver,
Expand Down

0 comments on commit 9e53c56

Please sign in to comment.