From d8665a49a6f5d8295d5af988f3392b9723e8519f Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 15 Oct 2024 17:16:31 -0400 Subject: [PATCH] fix: test --- package.json | 3 +- src/Ens.ts | 4 +-- src/tests/Ens.test.ts | 37 +++++++++++------------ src/tests/Resolution.test.ts | 55 ++++++++++++++++++++++------------- src/tests/UnsInternal.test.ts | 4 --- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 74e16067..9d2631f6 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ }, "homepage": "https://github.com/unstoppabledomains/resolution.git#readme", "devDependencies": { - "@ethersproject/providers": "^5.4.5", "@types/bn.js": "^4.11.6", "@types/crypto-js": "^4.1.1", "@types/elliptic": "^6.4.13", @@ -76,6 +75,7 @@ "eslint": "^7.7.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-jest": "^24.1.0", + "ethers": "^6.13.4", "husky": "^6.0.0", "jest": "^27.0.4", "lint-staged": "11.0.0", @@ -104,7 +104,6 @@ "cross-fetch": "4.0.0", "crypto-js": "^4.1.1", "elliptic": "^6.5.4", - "ethereum-ens-network-map": "^1.0.2", "js-sha256": "^0.9.0", "js-sha3": "^0.8.0" }, diff --git a/src/Ens.ts b/src/Ens.ts index 31fdd22d..e4fbe164 100644 --- a/src/Ens.ts +++ b/src/Ens.ts @@ -1,7 +1,6 @@ import * as contentHash from 'content-hash'; import bip44Constants from 'bip44-constants'; import {formatsByCoinType} from '@ensdomains/address-encoder'; -import EnsNetworkMap from 'ethereum-ens-network-map'; import {default as ensInterface} from './contracts/ens/ens'; import {default as resolverInterface} from './contracts/ens/resolver'; import {default as nameWrapperInterface} from './contracts/ens/nameWrapper'; @@ -59,7 +58,8 @@ export default class Ens extends NamingService { this.proxyServiceApiKey = finalSource['proxyServiceApiKey']; const registryAddress = - finalSource['registryAddress'] || EnsNetworkMap[this.network]; + finalSource['registryAddress'] || + ensConfig.networks[this.network].contracts.ENSRegistry.address; this.registryContract = new EthereumContract( ensInterface, registryAddress, diff --git a/src/tests/Ens.test.ts b/src/tests/Ens.test.ts index d033f518..9de492a2 100644 --- a/src/tests/Ens.test.ts +++ b/src/tests/Ens.test.ts @@ -13,27 +13,28 @@ import { import Ens from '../Ens'; import {EthereumNetworks} from '../utils'; -let resolution: Resolution; -let ens: Ens; - -beforeEach(() => { - nock.cleanAll(); - jest.restoreAllMocks(); - resolution = new Resolution({ - sourceConfig: { - ens: { - url: getProtocolLinkFromEnv( - ProviderProtocol.http, - NamingServiceName.ENS, - ), - network: ETH_L1_TESTNET_NAME, +describe('ENS', () => { + let resolution: Resolution; + let ens: Ens; + + beforeEach(() => { + nock.cleanAll(); + jest.restoreAllMocks(); + + resolution = new Resolution({ + sourceConfig: { + ens: { + url: getProtocolLinkFromEnv( + ProviderProtocol.http, + NamingServiceName.ENS, + ), + network: ETH_L1_TESTNET_NAME, + }, }, - }, + }); + ens = resolution.serviceMap[NamingServiceName.ENS].native as Ens; }); - ens = resolution.serviceMap[NamingServiceName.ENS].native as Ens; -}); -describe('ENS', () => { it('allows ens network specified as string', async () => { expect(ens.url).toBe( getProtocolLinkFromEnv(ProviderProtocol.http, NamingServiceName.ENS), diff --git a/src/tests/Resolution.test.ts b/src/tests/Resolution.test.ts index d907c059..e3aedb47 100644 --- a/src/tests/Resolution.test.ts +++ b/src/tests/Resolution.test.ts @@ -12,7 +12,7 @@ import { NamingServiceName, Web3Version1Provider, } from '../types/publicTypes'; -import {JsonRpcProvider, InfuraProvider} from '@ethersproject/providers'; +import {ethers} from 'ethers'; import Web3HttpProvider from 'web3-providers-http'; import Web3WsProvider from 'web3-providers-ws'; import { @@ -291,7 +291,11 @@ describe('Resolution', () => { const l2Url = getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL2'); const l2Provider = new FetchProvider(UnsLocation.Layer2, l2Url); const spy = mockAsyncMethod(provider, 'request', '1'); - const spyTwo = mockAsyncMethod(l2Provider, 'request', '80001'); + const spyTwo = mockAsyncMethod( + l2Provider, + 'request', + EthereumNetworks[POL_L2_TESTNET_NAME], + ); const resolution = await Resolution.autoNetwork({ uns: { locations: {Layer1: {provider}, Layer2: {provider: l2Provider}}, @@ -533,9 +537,9 @@ describe('Resolution', () => { }); describe('.ServiceName', () => { - it('checks ens service name', () => { - const serviceName = findNamingServiceName('domain.eth'); - expect(serviceName).toBe('ENS'); + it('checks ens service name', async () => { + const serviceName = await findNamingServiceName('domain.eth'); + expect(serviceName).toBe(NamingServiceName.ENS); }); it('should resolve gundb chat id', async () => { @@ -966,21 +970,24 @@ describe('Resolution', () => { }); it('should work for ethers jsonrpc provider', async () => { - const l1Provider = new JsonRpcProvider( + const l1Provider = new ethers.JsonRpcProvider( getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL1'), ETH_L1_TESTNET_NAME, ); - const l2Provider = new JsonRpcProvider( + const l2Provider = new ethers.JsonRpcProvider( getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL2'), - POL_L2_TESTNET_NAME, + 'matic-amoy', ); const resolution = Resolution.fromEthersProvider({ uns: { locations: { - Layer1: {network: ETH_L1_TESTNET_NAME, provider: l1Provider}, + Layer1: { + network: ETH_L1_TESTNET_NAME, + provider: l1Provider as any, + }, Layer2: { network: POL_L2_TESTNET_NAME, - provider: l2Provider, + provider: l2Provider as any, }, }, }, @@ -1050,21 +1057,24 @@ describe('Resolution', () => { }); it('should work for ethers jsonrpc provider', async () => { - const l1Provider = new JsonRpcProvider( + const l1Provider = new ethers.JsonRpcProvider( getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL1'), ETH_L1_TESTNET_NAME, ); - const l2Provider = new JsonRpcProvider( + const l2Provider = new ethers.JsonRpcProvider( getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL2'), - POL_L2_TESTNET_NAME, + 'matic-amoy', ); const resolution = Resolution.fromEthersProvider({ uns: { locations: { - Layer1: {network: ETH_L1_TESTNET_NAME, provider: l1Provider}, + Layer1: { + network: ETH_L1_TESTNET_NAME, + provider: l1Provider as any, + }, Layer2: { network: POL_L2_TESTNET_NAME, - provider: l2Provider, + provider: l2Provider as any, }, }, }, @@ -1084,12 +1094,12 @@ describe('Resolution', () => { }); it('should work with ethers default provider', async () => { - const l1Provider = new InfuraProvider( - ETH_L1_TESTNET_NAME, + const l1Provider = new ethers.InfuraProvider( + 'matic-amoy', '213fff28936343858ca9c5115eff1419', ); - const l2Provider = new InfuraProvider( - POL_L2_TESTNET_NAME, + const l2Provider = new ethers.InfuraProvider( + 'matic-amoy', 'a32aa2ace9704ee9a1a9906418bcabe5', ); @@ -1099,10 +1109,13 @@ describe('Resolution', () => { const resolution = Resolution.fromEthersProvider({ uns: { locations: { - Layer1: {network: ETH_L1_TESTNET_NAME, provider: l1Provider}, + Layer1: { + network: ETH_L1_TESTNET_NAME, + provider: l1Provider as any, + }, Layer2: { network: POL_L2_TESTNET_NAME, - provider: l2Provider, + provider: l2Provider as any, }, }, }, diff --git a/src/tests/UnsInternal.test.ts b/src/tests/UnsInternal.test.ts index a3438cf6..01b3749a 100644 --- a/src/tests/UnsInternal.test.ts +++ b/src/tests/UnsInternal.test.ts @@ -313,10 +313,6 @@ describe('UnsInternal', () => { }); it('should return true for tld exists', async () => { - console.log( - 'heyhey', - getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL1'), - ); mockAPICalls( 'uns_domain_exists_test', getProtocolLinkFromEnv(ProviderProtocol.http, 'UNSL1'),