Skip to content

Commit 2157c96

Browse files
wa0x6eChaituVR
andauthored
fix: handle error when the ens is not valid (#1041)
* fix: handle error when the ens is not valid * v0.12.3 --------- Co-authored-by: Chaitanya <[email protected]>
1 parent 04b881d commit 2157c96

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.12.2",
3+
"version": "0.12.3",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/utils.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
validateSchema,
66
getScores,
77
getVp,
8-
getFormattedAddress
8+
getFormattedAddress,
9+
getEnsOwner,
10+
getEnsTextRecord
911
} from './utils';
1012

1113
vi.mock('cross-fetch', async () => {
@@ -611,4 +613,18 @@ describe('utils', () => {
611613
expect(result).not.toBe(true);
612614
});
613615
});
616+
617+
describe('getEnsOwner', () => {
618+
test('should return null when the ENS is not valid', () => {
619+
// special hidden characters after the k
620+
expect(getEnsOwner('elonmusk‍‍.eth')).resolves.toBe(null);
621+
});
622+
});
623+
624+
describe('getEnsTextRecord', () => {
625+
test('should return null when the ENS is not valid', () => {
626+
// special hidden characters after the k
627+
expect(getEnsTextRecord('elonmusk‍‍.eth')).resolves.toBe(null);
628+
});
629+
});
614630
});

src/utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ export async function getEnsTextRecord(
544544
...multicallOptions
545545
} = options;
546546

547-
const ensHash = namehash(ensNormalize(ens));
547+
let ensHash: string;
548+
549+
try {
550+
ensHash = namehash(ensNormalize(ens));
551+
} catch (e: any) {
552+
return null;
553+
}
554+
548555
const provider = getProvider(network, { broviderUrl });
549556

550557
const calls = [
@@ -592,9 +599,17 @@ export async function getEnsOwner(
592599
['function owner(bytes32) view returns (address)'],
593600
provider
594601
);
602+
603+
let ensHash: string;
604+
605+
try {
606+
ensHash = namehash(ensNormalize(ens));
607+
} catch (e: any) {
608+
return null;
609+
}
610+
595611
const ensNameWrapper =
596612
options.ensNameWrapper || networks[network].ensNameWrapper;
597-
const ensHash = namehash(ensNormalize(ens));
598613
let owner = await ensRegistry.owner(ensHash);
599614
// If owner is the ENSNameWrapper contract, resolve the owner of the name
600615
if (owner === ensNameWrapper) {

0 commit comments

Comments
 (0)