Skip to content

Commit

Permalink
[DT-902] chore: resolve PR comments & revise unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DChan0319 committed Sep 29, 2023
1 parent 2b5d780 commit 1df7ff2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ token.EVM.ETH.USDC.address
crypto.USDC.address
token.EVM.ETH.address
```

`getAddress(domain, 'ETH', 'USDC')` will lookup records in the following order:
// Not supported with ENS

```
1. token.EVM.ETH.USDC.address
2. crypto.USDC.address
3. crypto.USDC.version.ERC20.address
4. token.EVM.ETH.address
5. token.EVM.address
```

## Error Handling

When resolution encounters an error it returns the error code instead of
Expand Down
25 changes: 17 additions & 8 deletions src/Ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ export default class Ens extends NamingService {
resolverContract,
nodeHash,
);
const fetchedAddress = await this.addr(domainName, BlockchainType.ETH);

const fetchedAddress = await this.resolverCallToAddr(
resolverContract,
domainName,
);
if (fetchedAddress?.toLowerCase() !== originalAddress.toLowerCase()) {
return null;
}
Expand Down Expand Up @@ -352,6 +356,18 @@ export default class Ens extends NamingService {
return await this.callMethod(reverseRegistrarContract, 'node', [address]);
}

/**
* This was done to make automated tests more configurable
*/
private async resolverCallToAddr(
resolverContract: EthereumContract,
domainName: string,
): Promise<string> {
return await this.callMethod(resolverContract, 'addr', [
this.namehash(domainName),
]);
}

// @see: https://docs.ens.domains/ens-improvement-proposals/ensip-5-text-records#service-keys
async twitter(domain: string): Promise<string> {
try {
Expand Down Expand Up @@ -410,13 +426,6 @@ export default class Ens extends NamingService {
},
);

const isWrappedDomain = await this.determineIsWrappedDomain(
this.namehash(domain),
);
if (isWrappedDomain) {
return await this.getAddressForWrappedDomain(domain);
}

if (!resolver) {
const owner = await this.owner(domain);
if (isNullAddress(owner)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export default class Resolution {
throw new ResolutionError(ResolutionErrorCode.RecordNotFound, {
domain,
method: err.method,
methodName: 'chatPk',
methodName: 'chatId',
recordName: err.recordName,
});
}
Expand Down
34 changes: 14 additions & 20 deletions src/tests/Ens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ describe('ENS', () => {
expect(ens.network).toEqual(5);

const eyes = mockAsyncMethods(ens, {
determineIsWrappedDomain: false,
resolver: '0x5FfC014343cd971B7eb70732021E26C35B744cc4',
fetchAddress: '0xa59C818Ddb801f1253edEbf0Cf08c9E481EA2fE5',
});
Expand All @@ -68,7 +67,7 @@ describe('ENS', () => {
reverseRegistrarCallToNode:
'0x4da70a332a7a98a58486f551a455b1398ce309d9bd3a4f0800da4eec299829a4',
callMethod: '0xDa1756Bb923Af5d1a05E277CB1E54f1D0A127890',
addr: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C',
resolverCallToAddr: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C',
resolverCallToName: 'adrian.argent.xyz',
});
const result = await ens?.reverseOf(
Expand All @@ -93,7 +92,6 @@ describe('ENS', () => {

it('resolves .xyz name using ENS blockchain', async () => {
const eyes = mockAsyncMethods(ens, {
determineIsWrappedDomain: false,
resolver: '0xDa1756Bb923Af5d1a05E277CB1E54f1D0A127890',
fetchAddress: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C',
});
Expand All @@ -105,7 +103,6 @@ describe('ENS', () => {

it('resolves .luxe name using ENS blockchain', async () => {
const eyes = mockAsyncMethods(ens, {
determineIsWrappedDomain: false,
resolver: '0xBD5F5ec7ed5f19b53726344540296C02584A5237',
fetchAddress: '0xf3dE750A73C11a6a2863761E930BF5fE979d5663',
});
Expand All @@ -117,9 +114,8 @@ describe('ENS', () => {

it('resolves .kred name using ENS blockchain', async () => {
const eyes = mockAsyncMethods(ens, {
determineIsWrappedDomain: false,
resolver: '0x96184444629F3489c4dE199871E6F99568229d8f',
callMethod: '0x96184444629F3489c4dE199871E6F99568229d8f',
fetchAddress: '0x96184444629F3489c4dE199871E6F99568229d8f',
});
const result = await resolution.addr('brantly.kred', 'ETH');
expectSpyToBeCalled(eyes);
Expand All @@ -128,7 +124,6 @@ describe('ENS', () => {

it('resolves .luxe name using ENS blockchain with thrown error', async () => {
const spies = mockAsyncMethods(ens, {
determineIsWrappedDomain: false,
resolver: undefined,
owner: undefined,
});
Expand All @@ -143,7 +138,7 @@ describe('ENS', () => {
it('resolves name with resolver but without an owner', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD',
fetchAddress: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD',
});
const doge = await resolution.addr('testthing.eth', 'DOGE');
expectSpyToBeCalled(eyes);
Expand Down Expand Up @@ -189,7 +184,7 @@ describe('ENS', () => {
it('checks ens multicoin support #1', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD',
fetchAddress: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD',
});
const doge = await resolution.addr('testthing.eth', 'DOGE');
expectSpyToBeCalled(eyes);
Expand All @@ -199,7 +194,7 @@ describe('ENS', () => {
it('checks ens multicoin support #2', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: 'MV5rN5EcX1imDS2gEh5jPJXeiW5QN8YrK3',
fetchAddress: 'MV5rN5EcX1imDS2gEh5jPJXeiW5QN8YrK3',
});
const ltc = await resolution.addr('testthing.eth', 'LTC');
expectSpyToBeCalled(eyes);
Expand All @@ -209,37 +204,37 @@ describe('ENS', () => {
it('checks ens multicoin support #3', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: '0x314159265dd8dbb310642f98f50c066173c1259b',
fetchAddress: '0x314159265dD8dbb310642f98f50C066173C1259b',
});
const eth = await resolution.addr('testthing.eth', 'ETH');
expectSpyToBeCalled(eyes);
expect(eth).toBe('0x314159265dd8dbb310642f98f50c066173c1259b');
expect(eth).toBe('0x314159265dD8dbb310642f98f50C066173C1259b');
});

it('checks ens multicoin support #4', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: '0x314159265dd8dbb310642f98f50c066173c1259b',
fetchAddress: '0x314159265dD8dbb310642f98f50C066173C1259b',
});
const etc = await resolution.addr('testthing.eth', 'etc');
expectSpyToBeCalled(eyes);
expect(etc).toBe('0x314159265dd8dbb310642f98f50c066173c1259b');
expect(etc).toBe('0x314159265dD8dbb310642f98f50C066173C1259b');
});

it('checks ens multicoin support #5', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: '0x314159265dd8dbb310642f98f50c066173c1259b',
fetchAddress: '0x314159265dD8DbB310642F98f50C066173c1259B',
});
const rsk = await resolution.addr('testthing.eth', 'rsk');
expectSpyToBeCalled(eyes);
expect(rsk).toBe('0x314159265dd8dbb310642f98f50c066173c1259b');
expect(rsk).toBe('0x314159265dD8DbB310642F98f50C066173c1259B');
});

it('checks ens multicoin support #6', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: 'X7qvLs7gSnNoKvZzNWUT2e8st17QPY64PPe7zriLNuJszeg',
fetchAddress: 'X7qvLs7gSnNoKvZzNWUT2e8st17QPY64PPe7zriLNuJszeg',
});
const xrp = await resolution.addr('testthing.eth', 'xrp');
expectSpyToBeCalled(eyes);
Expand All @@ -249,7 +244,7 @@ describe('ENS', () => {
it('checks ens multicoin support #7', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a',
fetchAddress: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a',
});
const bch = await resolution.addr('testthing.eth', 'bch');
expectSpyToBeCalled(eyes);
Expand All @@ -259,7 +254,7 @@ describe('ENS', () => {
it('checks ens multicoin support #8', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
callMethod:
fetchAddress:
'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx',
});
const btc = await resolution.addr('testthing.eth', 'BTC');
Expand All @@ -272,7 +267,6 @@ describe('ENS', () => {
it('checks UnsupportedCurrency error', async () => {
const eyes = mockAsyncMethods(ens, {
resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8',
determineIsWrappedDomain: false,
});
await expectResolutionErrorCode(
resolution.addr('testthing.eth', 'UNREALTICKER'),
Expand Down

0 comments on commit 1df7ff2

Please sign in to comment.