From 1709b302d512c84c0b4ff09f319fdbcdc75c484a Mon Sep 17 00:00:00 2001 From: Ryan Le Date: Wed, 10 Nov 2021 08:17:05 -0800 Subject: [PATCH] Uns#owner no longer throws if resolution is null (#192) --- src/Uns.ts | 9 ++++++++- src/tests/Uns.test.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Uns.ts b/src/Uns.ts index 40cfda7b..aa750738 100644 --- a/src/Uns.ts +++ b/src/Uns.ts @@ -166,7 +166,14 @@ export default class Uns extends NamingService { } async owner(domain: string): Promise { - return (await this.getVerifiedData(domain)).owner; + const tokenId = this.namehash(domain); + const data = await this.get(tokenId, []); + if (isNullAddress(data.owner)) { + throw new ResolutionError(ResolutionErrorCode.UnregisteredDomain, { + domain, + }); + } + return data.owner; } async resolver(domain: string): Promise { diff --git a/src/tests/Uns.test.ts b/src/tests/Uns.test.ts index 14ca7351..02570d8a 100644 --- a/src/tests/Uns.test.ts +++ b/src/tests/Uns.test.ts @@ -1117,6 +1117,21 @@ describe('UNS', () => { }); }); + describe('#owner', () => { + it('should not throw when resolver is null', async () => { + const spies = mockAsyncMethods(uns, { + get: { + owner: '0x58cA45E932a88b2E7D0130712B3AA9fB7c5781e2', + resolver: null, + records: {}, + }, + }); + const owner = await uns.owner(CryptoDomainLayerOneWithNoResolver); + expectSpyToBeCalled(spies); + expect(owner).toBe('0x58cA45E932a88b2E7D0130712B3AA9fB7c5781e2'); + }); + }); + describe('.isAvailable', () => { it('should return false', async () => { const spies = mockAsyncMethods(uns.unsl1.readerContract, {