Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyluo committed Oct 15, 2024
1 parent d370575 commit d8665a4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 47 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Ens.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 19 additions & 18 deletions src/tests/Ens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
55 changes: 34 additions & 21 deletions src/tests/Resolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}},
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
},
},
},
Expand Down Expand Up @@ -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,
},
},
},
Expand All @@ -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',
);

Expand All @@ -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,
},
},
},
Expand Down
4 changes: 0 additions & 4 deletions src/tests/UnsInternal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit d8665a4

Please sign in to comment.