From 1df7ff2d4303e174a92a6c6f654ad883e3e2fbc3 Mon Sep 17 00:00:00 2001 From: DChan0319 Date: Fri, 29 Sep 2023 10:08:59 -0700 Subject: [PATCH] [DT-902] chore: resolve PR comments & revise unit tests --- README.md | 12 ++++++++++++ src/Ens.ts | 25 +++++++++++++++++-------- src/Resolution.ts | 2 +- src/tests/Ens.test.ts | 34 ++++++++++++++-------------------- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b3915d7c..f6e137db 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Ens.ts b/src/Ens.ts index 85c5badf..4262e589 100644 --- a/src/Ens.ts +++ b/src/Ens.ts @@ -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; } @@ -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 { + 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 { try { @@ -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)) { diff --git a/src/Resolution.ts b/src/Resolution.ts index f9efa195..160dd1f5 100644 --- a/src/Resolution.ts +++ b/src/Resolution.ts @@ -595,7 +595,7 @@ export default class Resolution { throw new ResolutionError(ResolutionErrorCode.RecordNotFound, { domain, method: err.method, - methodName: 'chatPk', + methodName: 'chatId', recordName: err.recordName, }); } diff --git a/src/tests/Ens.test.ts b/src/tests/Ens.test.ts index 831ed826..1cf6f9c1 100644 --- a/src/tests/Ens.test.ts +++ b/src/tests/Ens.test.ts @@ -46,7 +46,6 @@ describe('ENS', () => { expect(ens.network).toEqual(5); const eyes = mockAsyncMethods(ens, { - determineIsWrappedDomain: false, resolver: '0x5FfC014343cd971B7eb70732021E26C35B744cc4', fetchAddress: '0xa59C818Ddb801f1253edEbf0Cf08c9E481EA2fE5', }); @@ -68,7 +67,7 @@ describe('ENS', () => { reverseRegistrarCallToNode: '0x4da70a332a7a98a58486f551a455b1398ce309d9bd3a4f0800da4eec299829a4', callMethod: '0xDa1756Bb923Af5d1a05E277CB1E54f1D0A127890', - addr: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C', + resolverCallToAddr: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C', resolverCallToName: 'adrian.argent.xyz', }); const result = await ens?.reverseOf( @@ -93,7 +92,6 @@ describe('ENS', () => { it('resolves .xyz name using ENS blockchain', async () => { const eyes = mockAsyncMethods(ens, { - determineIsWrappedDomain: false, resolver: '0xDa1756Bb923Af5d1a05E277CB1E54f1D0A127890', fetchAddress: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C', }); @@ -105,7 +103,6 @@ describe('ENS', () => { it('resolves .luxe name using ENS blockchain', async () => { const eyes = mockAsyncMethods(ens, { - determineIsWrappedDomain: false, resolver: '0xBD5F5ec7ed5f19b53726344540296C02584A5237', fetchAddress: '0xf3dE750A73C11a6a2863761E930BF5fE979d5663', }); @@ -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); @@ -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, }); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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'); @@ -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'),