Skip to content

Commit

Permalink
[DT-902] fix: Unit testing and small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DChan0319 committed Sep 28, 2023
1 parent 6a258b0 commit 8a71fea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
38 changes: 21 additions & 17 deletions src/Resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/tests/Ens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a71fea

Please sign in to comment.