From 8dba5b44f4a5097ce1d82d5033eee00bef681fa0 Mon Sep 17 00:00:00 2001 From: tate Date: Thu, 30 Mar 2023 11:06:41 +1100 Subject: [PATCH] fix: allow empty address records to be set --- .../ensjs/src/utils/recordHelpers.test.ts | 19 +++++++++++++++++++ packages/ensjs/src/utils/recordHelpers.ts | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 packages/ensjs/src/utils/recordHelpers.test.ts diff --git a/packages/ensjs/src/utils/recordHelpers.test.ts b/packages/ensjs/src/utils/recordHelpers.test.ts new file mode 100644 index 00000000..9f1b6930 --- /dev/null +++ b/packages/ensjs/src/utils/recordHelpers.test.ts @@ -0,0 +1,19 @@ +import { PublicResolver__factory } from '../generated' +import { namehash } from './normalise' +import { generateSetAddr } from './recordHelpers' + +describe('generateSetAddr()', () => { + it('should allow empty string as address', () => { + expect(() => + generateSetAddr( + namehash('test'), + 'BNB', + '', + PublicResolver__factory.connect( + '0x0000000000000000000000000000000000000000', + undefined as any, + ), + ), + ).not.toThrowError() + }) +}) diff --git a/packages/ensjs/src/utils/recordHelpers.ts b/packages/ensjs/src/utils/recordHelpers.ts index 2a86a1ac..34a8cbbf 100644 --- a/packages/ensjs/src/utils/recordHelpers.ts +++ b/packages/ensjs/src/utils/recordHelpers.ts @@ -38,7 +38,8 @@ export const generateSetAddr = ( coinTypeInstance = formatsByName[coinType.toUpperCase()] } const inputCoinType = coinTypeInstance.coinType - const encodedAddress = coinTypeInstance.decoder(address) + const encodedAddress = + address !== '' ? coinTypeInstance.decoder(address) : '0x' return resolver?.interface.encodeFunctionData( 'setAddr(bytes32,uint256,bytes)', [namehash, inputCoinType, encodedAddress],