Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DT-902] fix: Unit testing and small updates
Browse files Browse the repository at this point in the history
DChan0319 committed Sep 28, 2023
1 parent 6a258b0 commit 2b5d780
Showing 3 changed files with 30 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/Ens.ts
Original file line number Diff line number Diff line change
@@ -178,13 +178,17 @@ export default class Ens extends NamingService {
): Promise<Record<string, string>> {
throw new ResolutionError(ResolutionErrorCode.UnsupportedMethod, {
methodName: 'records',
domain,
method: this.serviceName(),
});
}

// TODO: Need to understand how ENS supports DNS @see https://docs.ens.domains/contract-api-reference/dns-registrar#retrieving-the-dns-text-record
async dns(domain: string, types: DnsRecordType[]): Promise<DnsRecord[]> {
throw new ResolutionError(ResolutionErrorCode.UnsupportedMethod, {
methodName: 'dns',
method: this.serviceName(),
domain,
});
}

@@ -323,6 +327,8 @@ export default class Ens extends NamingService {
): Promise<string> {
throw new ResolutionError(ResolutionErrorCode.UnsupportedMethod, {
methodName: 'getAddress',
domain,
method: this.serviceName(),
});
}

38 changes: 21 additions & 17 deletions src/Resolution.ts
Original file line number Diff line number Diff line change
@@ -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) {
4 changes: 3 additions & 1 deletion src/tests/Ens.test.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2b5d780

Please sign in to comment.