Skip to content

Commit

Permalink
Merge pull request #116 from ensdomains/fet896-update-ensjs-for-pcc-b…
Browse files Browse the repository at this point in the history
…urned

add abi support to setRecords
  • Loading branch information
storywithoutend authored Feb 27, 2023
2 parents 8e1b6dd + 9443349 commit 17f8cd1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/ensjs/src/functions/setRecords.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { toUtf8String } from 'ethers/lib/utils'
import { ENS } from '..'
import setup from '../tests/setup'
import { hexEncodeName } from '../utils/hexEncodedName'
import { namehash } from '../utils/normalise'

const dummyABI = [
{
type: 'function',
name: 'supportsInterface',
constant: true,
stateMutability: 'view',
payable: false,
inputs: [
{
type: 'bytes4',
},
],
outputs: [
{
type: 'bool',
},
],
},
]

let ensInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']

Expand All @@ -25,6 +46,9 @@ describe('setRecords', () => {
},
],
texts: [{ key: 'foo', value: 'bar' }],
abi: {
data: dummyABI,
},
},
addressOrIndex: 1,
})
Expand Down Expand Up @@ -60,5 +84,17 @@ describe('setRecords', () => {
expect(resultAddr).toBe(
'0x42D63ae25990889E35F215bC95884039Ba354115'.toLowerCase(),
)

const encodedABI = await universalResolver['resolve(bytes,bytes)'](
hexEncodeName('test123.eth'),
publicResolver.interface.encodeFunctionData('ABI', [
namehash('test123.eth'),
'0x01',
]),
)
const [contentType, resultABI] =
publicResolver.interface.decodeFunctionResult('ABI', encodedABI[0])
expect(contentType.toNumber()).toBe(1)
expect(toUtf8String(resultABI)).toBe(JSON.stringify(dummyABI))
})
})
9 changes: 9 additions & 0 deletions packages/ensjs/src/utils/recordHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export const generateRecordCallArray = (
if (data) calls.push(data)
}

if (records.abi) {
const data = generateSingleRecordCall(
namehash,
resolver,
'abi',
)(records.abi)
if (data) calls.push(data)
}

if (records.texts && records.texts.length > 0) {
records.texts
.map(generateSingleRecordCall(namehash, resolver, 'text'))
Expand Down

0 comments on commit 17f8cd1

Please sign in to comment.