From 2b5d7801434642fcf485b6f16f6142ecf83f8bb5 Mon Sep 17 00:00:00 2001 From: DChan0319 Date: Thu, 28 Sep 2023 15:12:47 -0700 Subject: [PATCH] [DT-902] fix: Unit testing and small updates --- src/Ens.ts | 6 ++++++ src/Resolution.ts | 38 +++++++++++++++++++++----------------- src/tests/Ens.test.ts | 4 +++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Ens.ts b/src/Ens.ts index e893df00..85c5badf 100644 --- a/src/Ens.ts +++ b/src/Ens.ts @@ -178,6 +178,8 @@ export default class Ens extends NamingService { ): Promise> { throw new ResolutionError(ResolutionErrorCode.UnsupportedMethod, { methodName: 'records', + domain, + method: this.serviceName(), }); } @@ -185,6 +187,8 @@ export default class Ens extends NamingService { async dns(domain: string, types: DnsRecordType[]): Promise { throw new ResolutionError(ResolutionErrorCode.UnsupportedMethod, { methodName: 'dns', + method: this.serviceName(), + domain, }); } @@ -323,6 +327,8 @@ export default class Ens extends NamingService { ): Promise { throw new ResolutionError(ResolutionErrorCode.UnsupportedMethod, { methodName: 'getAddress', + domain, + method: this.serviceName(), }); } diff --git a/src/Resolution.ts b/src/Resolution.ts index 7ef30d01..f9efa195 100644 --- a/src/Resolution.ts +++ b/src/Resolution.ts @@ -569,12 +569,15 @@ export default class Resolution { try { return await this.record(domain, 'gundb.username.value'); } catch (err) { - throw new ResolutionError(ResolutionErrorCode.RecordNotFound, { - domain, - method: err.method, - methodName: 'chatId', - recordName: err.recordName, - }); + if (err.code === ResolutionErrorCode.RecordNotFound) { + throw new ResolutionError(ResolutionErrorCode.RecordNotFound, { + domain, + method: err.method, + methodName: 'chatId', + recordName: err.recordName, + }); + } + throw err; } } @@ -588,12 +591,15 @@ export default class Resolution { try { return await this.record(domain, 'gundb.public_key.value'); } catch (err) { - throw new ResolutionError(ResolutionErrorCode.RecordNotFound, { - domain, - method: err.method, - methodName: 'chatPk', - recordName: err.recordName, - }); + if (err.code === ResolutionErrorCode.RecordNotFound) { + throw new ResolutionError(ResolutionErrorCode.RecordNotFound, { + domain, + method: err.method, + methodName: 'chatPk', + recordName: err.recordName, + }); + } + throw err; } } @@ -954,10 +960,8 @@ export default class Resolution { const ensDomains = domains.filter((domain) => domain.match(/^([^\s\\.]+\.)+(eth|luxe|xyz|kred)+$/), ); - const unsDomains = domains.filter( - (domain) => - !domain.endsWith('.zil') && - !domain.match(/^([^\s\\.]+\.)+(eth|luxe|xyz|kred)+$/), + const nonEnsDomains = domains.filter( + (domain) => !domain.match(/^([^\s\\.]+\.)+(eth|luxe|xyz|kred)+$/), ); // Here, we call both UNS and ZNS methods and merge the results. // If any of the calls fails, this method will fail as well as we aren't interested in partial results. @@ -966,7 +970,7 @@ export default class Resolution { // migrated to UNS), the ZNS call result will be ignored and an error, if there's one, won't be thrown. const unsPromise = - this.serviceMap.UNS.usedServices[0].locations(unsDomains); + this.serviceMap.UNS.usedServices[0].locations(nonEnsDomains); // Fetch UNS locations first. If we see that there are no .zil domains with absent locations, we can return early. const unsLocations = await unsPromise; if (zilDomains.length) { diff --git a/src/tests/Ens.test.ts b/src/tests/Ens.test.ts index 640f4330..831ed826 100644 --- a/src/tests/Ens.test.ts +++ b/src/tests/Ens.test.ts @@ -331,7 +331,9 @@ describe('ENS', () => { }); const ipfsHash = await resolution.ipfsHash('monkybrain.eth'); expectSpyToBeCalled(eyes); - expect(ipfsHash).toBe('QmXSBLw6VMegqkCHSDBPg7xzfLhUyuRBzTb927KVzKC1vq'); + expect(ipfsHash).toBe( + 'ipfs://QmXSBLw6VMegqkCHSDBPg7xzfLhUyuRBzTb927KVzKC1vq', + ); }); // todo(johny) find some domains with url property set