Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle error when the ens is not valid #1041

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
validateSchema,
getScores,
getVp,
getFormattedAddress
getFormattedAddress,
getEnsOwner,
getEnsTextRecord
} from './utils';

vi.mock('cross-fetch', async () => {
Expand Down Expand Up @@ -611,4 +613,18 @@ describe('utils', () => {
expect(result).not.toBe(true);
});
});

describe('getEnsOwner', () => {
test('should return null when the ENS is not valid', () => {
// special hidden characters after the k
expect(getEnsOwner('elonmusk‍‍.eth')).resolves.toBe(null);
});
});

describe('getEnsTextRecord', () => {
test('should return null when the ENS is not valid', () => {
// special hidden characters after the k
expect(getEnsTextRecord('elonmusk‍‍.eth')).resolves.toBe(null);
});
});
});
19 changes: 17 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,14 @@ export async function getEnsTextRecord(
...multicallOptions
} = options;

const ensHash = namehash(ensNormalize(ens));
let ensHash: string;

try {
ensHash = namehash(ensNormalize(ens));
} catch (e: any) {
return null;
}

const provider = getProvider(network, { broviderUrl });

const calls = [
Expand Down Expand Up @@ -592,9 +599,17 @@ export async function getEnsOwner(
['function owner(bytes32) view returns (address)'],
provider
);

let ensHash: string;

try {
ensHash = namehash(ensNormalize(ens));
} catch (e: any) {
return null;
}

const ensNameWrapper =
options.ensNameWrapper || networks[network].ensNameWrapper;
const ensHash = namehash(ensNormalize(ens));
let owner = await ensRegistry.owner(ensHash);
// If owner is the ENSNameWrapper contract, resolve the owner of the name
if (owner === ensNameWrapper) {
Expand Down
Loading