Skip to content

Commit abd087f

Browse files
fix tests failing due to real RPC calls
1 parent 0e7b0a9 commit abd087f

File tree

7 files changed

+102
-85
lines changed

7 files changed

+102
-85
lines changed

.eslintrc.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

eslint.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const { fixupPluginRules } = require('@eslint/compat')
22
const { FlatCompat } = require('@eslint/eslintrc')
33
const js = require('@eslint/js')
4-
const typescriptEslintEslintPlugin = require('@typescript-eslint/eslint-plugin')
54
const tsParser = require('@typescript-eslint/parser')
65
const _import = require('eslint-plugin-import')
6+
const prettier = require('eslint-plugin-prettier')
7+
const prettierConfig = require('eslint-config-prettier')
78
const globals = require('globals')
89

910
const compat = new FlatCompat({
@@ -14,13 +15,14 @@ const compat = new FlatCompat({
1415

1516
module.exports = [
1617
{
17-
ignores: ['**/eslint.config.js'],
18+
ignores: ['**/eslint.config.js', '**/dist/**', '**/node_modules/**'],
1819
},
19-
...compat.extends('plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'),
20+
...compat.extends('plugin:@typescript-eslint/recommended'),
21+
prettierConfig,
2022
{
2123
plugins: {
22-
'@typescript-eslint': typescriptEslintEslintPlugin,
2324
import: fixupPluginRules(_import),
25+
prettier: fixupPluginRules(prettier),
2426
},
2527

2628
languageOptions: {
@@ -30,7 +32,7 @@ module.exports = [
3032
},
3133

3234
parser: tsParser,
33-
ecmaVersion: 5,
35+
ecmaVersion: 'latest',
3436
sourceType: 'module',
3537

3638
parserOptions: {
@@ -43,14 +45,14 @@ module.exports = [
4345
'@typescript-eslint/explicit-function-return-type': 'off',
4446
'@typescript-eslint/explicit-module-boundary-types': 'off',
4547
'@typescript-eslint/no-explicit-any': 'off',
48+
'prettier/prettier': 'error',
4649

4750
'import/order': [
4851
'error',
4952
{
5053
alphabetize: {
5154
order: 'asc',
5255
},
53-
5456
groups: [
5557
['builtin', 'external'],
5658
['internal', 'parent', 'sibling', 'index'],

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"format": "prettier --write \"src/**/*.ts\"",
1717
"lint": "eslint \"{src,apps,libs,test,__tests__}/**/*.ts\" --fix",
1818
"lint:ci": "eslint \"{src,apps,libs,test,__tests__}/**/*.ts\"",
19-
"test": "tap test/*.spec.ts",
19+
"test": "tap --passes test/*.spec.ts",
2020
"test:cov": "tap test/*.spec.ts --coverage-report=text-summary --coverage-report=lcovonly --allow-incomplete-coverage",
2121
"prepublishOnly": "npm run lint:ci && npm run test"
2222
},
@@ -67,11 +67,11 @@
6767
},
6868
"peerDependencies": {
6969
"@nestjs/common": "^10.2.7",
70-
"ethers": "^6.8.0"
70+
"ethers": "^6.15.0"
7171
},
7272
"tap": {
7373
"diag": true,
74-
"bail": false,
74+
"bail": true,
7575
"comments": true,
7676
"timeout": 40000
7777
}

test/ethers.contract.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import t from 'tap'
55
import * as ABI from './utils/ABI.json'
66
import { appRequest } from './utils/appRequest'
77
import { ETHERS_ADDRESS, ETHERS_PRIVATE_KEY } from './utils/constants'
8+
import { nockAllRPCRequests } from './utils/mockResponses'
89
import { platforms } from './utils/platforms'
910
import { EthersContract, EthersModule, EthersSigner, InjectContractProvider, InjectSignerProvider } from '../src'
1011

1112
t.test('EthersContract', (t) => {
12-
t.beforeEach(() => nock.cleanAll())
13+
t.beforeEach(() => {
14+
nock.cleanAll()
15+
nockAllRPCRequests()
16+
})
1317

1418
t.before(() => {
1519
if (!nock.isActive()) {
@@ -37,7 +41,7 @@ t.test('EthersContract', (t) => {
3741
async someMethod(): Promise<string> {
3842
const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI)
3943

40-
if (!contract?.runner) {
44+
if (!(await contract?.runner?.provider?.getNetwork())) {
4145
throw new Error('No provider injected')
4246
}
4347

@@ -84,7 +88,7 @@ t.test('EthersContract', (t) => {
8488
const wallet = this.signer.createWallet(ETHERS_PRIVATE_KEY)
8589
const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI, wallet)
8690

87-
if (!contract?.runner) {
91+
if (!(await contract?.runner?.provider?.getNetwork())) {
8892
throw new Error('No provider injected')
8993
}
9094

@@ -133,7 +137,7 @@ t.test('EthersContract', (t) => {
133137
async someMethod(): Promise<string> {
134138
const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI)
135139

136-
if (!contract?.runner) {
140+
if (!(await contract?.runner?.provider?.getNetwork())) {
137141
throw new Error('No provider injected')
138142
}
139143

@@ -188,7 +192,7 @@ t.test('EthersContract', (t) => {
188192
const wallet = this.signer.createWallet(ETHERS_PRIVATE_KEY)
189193
const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI, wallet)
190194

191-
if (!contract?.runner) {
195+
if (!(await contract?.runner?.provider?.getNetwork())) {
192196
throw new Error('No provider injected')
193197
}
194198

test/ethers.module.spec.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { NestFactory } from '@nestjs/core'
33
import {
44
AbstractProvider,
55
AlchemyProvider,
6-
encodeBase64,
76
EtherscanProvider,
87
FallbackProvider,
98
FeeData,
109
JsonRpcProvider,
1110
Network,
1211
PocketProvider,
13-
toUtf8Bytes,
1412
} from 'ethers'
1513
import * as nock from 'nock'
1614
import t from 'tap'
@@ -40,7 +38,13 @@ import {
4038
POLYGON_TESTNET_GASSTATION_URL,
4139
TESTNET_BSCPOCKET_URL,
4240
} from './utils/constants'
43-
import { GAS_STATION_RESPONSE, generateMethodQuery, matchResponses, RPC_RESPONSES } from './utils/mockResponses'
41+
import {
42+
GAS_STATION_RESPONSE,
43+
generateMethodQuery,
44+
matchResponses,
45+
nockAllRPCRequests,
46+
RPC_RESPONSES,
47+
} from './utils/mockResponses'
4448
import { platforms } from './utils/platforms'
4549
import {
4650
BINANCE_NETWORK,
@@ -73,6 +77,8 @@ t.test('Ethers Module Initialization', (t) => {
7377
t.test(PlatformAdapter.name, (t) => {
7478
t.test('forRoot', (t) => {
7579
t.test('should compile without options', async (t) => {
80+
nockAllRPCRequests()
81+
7682
@Controller('/')
7783
class TestController {
7884
constructor(
@@ -140,10 +146,7 @@ t.test('Ethers Module Initialization', (t) => {
140146
nock(GOERLI_POCKET_URL)
141147
.persist()
142148
.post(`/${GOERLI_POKT_API_KEY.applicationId}`)
143-
.matchHeader(
144-
'authorization',
145-
'Basic ' + encodeBase64(toUtf8Bytes(`:${GOERLI_POKT_API_KEY.applicationSecretKey}`)),
146-
)
149+
.basicAuth({ user: '', pass: GOERLI_POKT_API_KEY.applicationSecretKey })
147150
.reply(200, matchResponses)
148151

149152
@Controller('/')
@@ -287,10 +290,7 @@ t.test('Ethers Module Initialization', (t) => {
287290
nock(BSC_POCKET_URL)
288291
.persist()
289292
.post(`/${GOERLI_POKT_API_KEY.applicationId}`)
290-
.matchHeader(
291-
'authorization',
292-
'Basic ' + encodeBase64(toUtf8Bytes(`:${GOERLI_POKT_API_KEY.applicationSecretKey}`)),
293-
)
293+
.basicAuth({ user: '', pass: GOERLI_POKT_API_KEY.applicationSecretKey })
294294
.reply(200, matchResponses)
295295

296296
@Controller('/')
@@ -326,6 +326,7 @@ t.test('Ethers Module Initialization', (t) => {
326326
})
327327

328328
t.test('should compile with network option as number', async (t) => {
329+
nockAllRPCRequests()
329330
@Controller('/')
330331
class TestController {
331332
constructor(
@@ -356,6 +357,7 @@ t.test('Ethers Module Initialization', (t) => {
356357
})
357358

358359
t.test('should compile with network option as string', async (t) => {
360+
nockAllRPCRequests()
359361
@Controller('/')
360362
class TestController {
361363
constructor(
@@ -1110,6 +1112,8 @@ t.test('Ethers Module Initialization', (t) => {
11101112
})
11111113

11121114
t.test('should compile with network option as number', async (t) => {
1115+
nockAllRPCRequests()
1116+
11131117
@Controller('/')
11141118
class TestController {
11151119
constructor(
@@ -1155,6 +1159,7 @@ t.test('Ethers Module Initialization', (t) => {
11551159
})
11561160

11571161
t.test('should compile with network option as string', async (t) => {
1162+
nockAllRPCRequests()
11581163
@Controller('/')
11591164
class TestController {
11601165
constructor(

0 commit comments

Comments
 (0)