diff --git a/src/Ens.ts b/src/Ens.ts index 48fc53fb..e8415b4c 100644 --- a/src/Ens.ts +++ b/src/Ens.ts @@ -21,12 +21,7 @@ import { isNullAddress, } from './utils'; import FetchProvider from './FetchProvider'; -import { - eip137Childhash, - eip137Namehash, - labelNameHash, - getParentDomain, -} from './utils/namehash'; +import {eip137Childhash, eip137Namehash, labelNameHash} from './utils/namehash'; import {NamingService} from './NamingService'; import ConfigurationError, { ConfigurationErrorCode, diff --git a/src/tests/Ens.test.ts b/src/tests/Ens.test.ts index 70fcb5b0..a758c5eb 100644 --- a/src/tests/Ens.test.ts +++ b/src/tests/Ens.test.ts @@ -11,8 +11,6 @@ import { skipItInLive, } from './helpers'; import Ens from '../Ens'; -import FetchProvider from '../FetchProvider'; -import EnsNetworkMap from 'ethereum-ens-network-map'; let resolution: Resolution; let ens: Ens; @@ -34,7 +32,6 @@ beforeEach(() => { ens = resolution.serviceMap[NamingServiceName.ENS].native as Ens; }); -// Test only on testnet? ttl? describe('ENS', () => { it('allows ens network specified as string', async () => { expect(ens.url).toBe( @@ -44,6 +41,7 @@ describe('ENS', () => { }); it('resolves .eth name using blockchain', async () => { + nock.enableNetConnect(); expect(ens.url).toBe( getProtocolLinkFromEnv(ProviderProtocol.http, NamingServiceName.ENS), ); @@ -137,7 +135,7 @@ describe('ENS', () => { it('resolves name with resolver but without an owner', async () => { const eyes = mockAsyncMethods(ens, { resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8', - callMethod: '0x76a9144620b70031f0e9437e374a2100934fba4911046088ac', + callMethod: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD', }); const doge = await resolution.addr('testthing.eth', 'DOGE'); expectSpyToBeCalled(eyes); @@ -167,103 +165,6 @@ describe('ENS', () => { ); }); - it('checks custom network config without url or provider', async () => { - expect( - () => - new Resolution({ - sourceConfig: { - ens: { - network: 'custom', - registryAddress: '0x314159265dd8dbb310642f98f50c066173c1259b', - }, - }, - }), - ).toThrowError( - 'Missing configuration in Resolution ENS. Please specify url or provider when using a custom network', - ); - }); - - it('checks custom network config without with url', async () => { - const resolution = new Resolution({ - sourceConfig: { - ens: { - network: 'custom', - registryAddress: '0x314159265dd8dbb310642f98f50c066173c1259b', - url: getProtocolLinkFromEnv( - ProviderProtocol.http, - NamingServiceName.ENS, - ), - }, - }, - }); - const ens = resolution.serviceMap[NamingServiceName.ENS].native as Ens; - expect(ens.network).toBeUndefined(); - expect(await ens.registryAddress('test.ens')).toBe( - '0x314159265dd8dbb310642f98f50c066173c1259b', - ); - expect(ens.url).toBe( - getProtocolLinkFromEnv(ProviderProtocol.http, NamingServiceName.ENS), - ); - }); - - it('checks custom network config without with provider', async () => { - const provider = new FetchProvider( - NamingServiceName.ENS, - getProtocolLinkFromEnv(ProviderProtocol.http, NamingServiceName.ENS), - ); - const resolution = new Resolution({ - sourceConfig: { - ens: { - network: 'custom', - registryAddress: '0x314159265dd8dbb310642f98f50c066173c1259b', - url: getProtocolLinkFromEnv( - ProviderProtocol.http, - NamingServiceName.ENS, - ), - provider: new FetchProvider( - NamingServiceName.ENS, - getProtocolLinkFromEnv( - ProviderProtocol.http, - NamingServiceName.ENS, - ), - ), - }, - }, - }); - const ens = resolution.serviceMap[NamingServiceName.ENS].native as Ens; - expect(ens.network).toBeUndefined(); - expect(await ens.registryAddress('test.ens')).toBe( - '0x314159265dd8dbb310642f98f50c066173c1259b', - ); - expect(ens.provider).toMatchObject(provider); - }); - - it('resolve record with custom network', async () => { - const networkId = 5; - const resolution = new Resolution({ - sourceConfig: { - ens: { - network: 'custom', - url: getProtocolLinkFromEnv( - ProviderProtocol.http, - NamingServiceName.ENS, - ), - registryAddress: EnsNetworkMap[networkId], - }, - }, - }); - const eyes = mockAsyncMethods( - resolution.serviceMap[NamingServiceName.ENS].native, - { - resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8', - callMethod: '0x76a9144620b70031f0e9437e374a2100934fba4911046088ac', - }, - ); - const doge = await resolution.addr('testthing.eth', 'DOGE'); - expectSpyToBeCalled(eyes); - expect(doge).toBe('DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD'); - }); - it('checks normalizeSource ens (object) #13', async () => { expect( () => @@ -280,7 +181,7 @@ describe('ENS', () => { it('checks ens multicoin support #1', async () => { const eyes = mockAsyncMethods(ens, { resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8', - callMethod: '0x76a9144620b70031f0e9437e374a2100934fba4911046088ac', + callMethod: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD', }); const doge = await resolution.addr('testthing.eth', 'DOGE'); expectSpyToBeCalled(eyes); @@ -290,7 +191,7 @@ describe('ENS', () => { it('checks ens multicoin support #2', async () => { const eyes = mockAsyncMethods(ens, { resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8', - callMethod: '0xa914e8604d28ef5d2a7caafe8741e5dd4816b7cb19ea87', + callMethod: 'MV5rN5EcX1imDS2gEh5jPJXeiW5QN8YrK3', }); const ltc = await resolution.addr('testthing.eth', 'LTC'); expectSpyToBeCalled(eyes); @@ -304,7 +205,7 @@ describe('ENS', () => { }); 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 () => { @@ -314,7 +215,7 @@ describe('ENS', () => { }); 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 () => { @@ -324,14 +225,13 @@ describe('ENS', () => { }); 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: - '0x05444b4e9c06f24296074f7bc48f92a97916c6dc5ea9000000000000000000', + callMethod: 'X7qvLs7gSnNoKvZzNWUT2e8st17QPY64PPe7zriLNuJszeg', }); const xrp = await resolution.addr('testthing.eth', 'xrp'); expectSpyToBeCalled(eyes); @@ -341,7 +241,7 @@ describe('ENS', () => { it('checks ens multicoin support #7', async () => { const eyes = mockAsyncMethods(ens, { resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8', - callMethod: '0x76a91476a04053bda0a88bda5177b86a15c3b29f55987388ac', + callMethod: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a', }); const bch = await resolution.addr('testthing.eth', 'bch'); expectSpyToBeCalled(eyes); @@ -352,7 +252,7 @@ describe('ENS', () => { const eyes = mockAsyncMethods(ens, { resolver: '0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8', callMethod: - '0x5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6', + 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx', }); const btc = await resolution.addr('testthing.eth', 'BTC'); expectSpyToBeCalled(eyes); @@ -410,38 +310,6 @@ describe('ENS', () => { '0x787192fc5378cc32aa956ddfdedbf26b24e8d78e40109add0eea2c1a012c3dec', ); }); - - describe('.domain invalid format', () => { - it('starts with -', async () => { - expect(await resolution.isSupportedDomain('-hello.eth')).toEqual( - false, - ); - await expectResolutionErrorCode( - () => resolution.namehash('-hello.eth', NamingServiceName.ENS), - ResolutionErrorCode.UnsupportedDomain, - ); - }); - - it('ends with -', async () => { - expect(await resolution.isSupportedDomain('hello-.eth')).toEqual( - false, - ); - await expectResolutionErrorCode( - () => resolution.namehash('hello-.eth', NamingServiceName.ENS), - ResolutionErrorCode.UnsupportedDomain, - ); - }); - - it('starts and ends with -', async () => { - expect(await resolution.isSupportedDomain('-hello-.eth')).toEqual( - false, - ); - await expectResolutionErrorCode( - () => resolution.namehash('-hello-.eth', NamingServiceName.ENS), - ResolutionErrorCode.UnsupportedDomain, - ); - }); - }); }); });