Skip to content

Commit cf9449f

Browse files
authored
Release v2.0.0 - Nest.js v9 (#140)
* fix deps * Add Ankr and Nodesmith provider, remove deprecated chains * add unit test for ethers.custom-rpcs * add CodeQL * add runInBand * remove @ from titles * add CodeQL badge * update CHANGELOG * update codeql * Bump to rc
1 parent 67a3446 commit cf9449f

21 files changed

+5016
-3369
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ orbs:
66
# The Node.js orb contains a set of prepackaged CircleCI configuration you can utilize
77
# Orbs reduce the amount of configuration required for common tasks.
88
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node
9-
node: circleci/[email protected].0
9+
node: circleci/[email protected].3
1010
coveralls: coveralls/[email protected]
1111

1212
jobs:
@@ -15,7 +15,7 @@ jobs:
1515
node-version:
1616
type: string
1717
docker:
18-
- image: circleci/node:<< parameters.node-version >>
18+
- image: cimg/node:<< parameters.node-version >>
1919
resource_class: small
2020
steps:
2121
- checkout
@@ -50,4 +50,4 @@ workflows:
5050
- test:
5151
matrix:
5252
parameters:
53-
node-version: ['16.13', '14.18', '12.22']
53+
node-version: ['18.12', '16.18', '14.21']

.github/workflows/codeql-analysis.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "main" ]
20+
schedule:
21+
- cron: '20 7 * * 0'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'TypeScript' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v2
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
52+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53+
# queries: security-extended,security-and-quality
54+
55+
56+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57+
# If this step fails, then you should remove it and run the build manually (see below)
58+
- name: Autobuild
59+
uses: github/codeql-action/autobuild@v2
60+
61+
# ℹ️ Command-line programs to run using the OS shell.
62+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63+
64+
# If the Autobuild fails above, remove it and uncomment the following three lines.
65+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66+
67+
# - run: |
68+
# echo "Run, Build Application using script"
69+
# ./location_of_script_within_repo/buildscript.sh
70+
71+
- name: Perform CodeQL Analysis
72+
uses: github/codeql-action/analyze@v2
73+
with:
74+
category: "/language:${{matrix.language}}"

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.14
1+
lts/hydrogen

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
# Changelog
22

3+
## 2.0.0
4+
Published by **[blockcoders](https://github.com/blockcoders)** on **2023/01/07**
5+
- [#140](https://github.com/blockcoders/nestjs-ethers/pull/140) Release v2.0.0 - Nest.js v9
6+
- [#142](https://github.com/blockcoders/nestjs-ethers/pull/142) Update README.md by [@copocaneta](https://github.com/copocaneta)
7+
8+
### BREAKING CHANGE
9+
- Dropped support for node < 14
10+
- Upgrade @nestjs/* from 8.x to 9.x
11+
- Remove deprecated ethereum chains (ropsten, rinkeby and kovan).
12+
- Add new RPC providers Moralis and Ankr.
13+
- Ethers.js is not longer part of the index.ts export.
14+
- @ethersproject/* is now part of peerDependencies.
15+
316
## 1.0.3
417
Published by **[blockcoders](https://github.com/blockcoders)** on **2022/05/08**
5-
- [#140](https://github.com/blockcoders/nestjs-ethers/pull/140) Update dependencies
18+
- [#141](https://github.com/blockcoders/nestjs-ethers/pull/141) Update dependencies
619
- [#139](https://github.com/blockcoders/nestjs-ethers/pull/139) Fix: Function name createWalletFromEncryptedJson by [@GustavoRSSilva](https://github.com/GustavoRSSilva)
720
- [#138](https://github.com/blockcoders/nestjs-ethers/pull/138) Fix: README injected variable ethersContract by [@GustavoRSSilva](https://github.com/GustavoRSSilva)
821

README.md

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ NestJS-Ethers
44
[![npm](https://img.shields.io/npm/v/nestjs-ethers)](https://www.npmjs.com/package/nestjs-ethers)
55
[![CircleCI](https://circleci.com/gh/blockcoders/nestjs-ethers/tree/main.svg?style=svg)](https://circleci.com/gh/blockcoders/nestjs-ethers/tree/main)
66
[![Coverage Status](https://coveralls.io/repos/github/blockcoders/nestjs-ethers/badge.svg?branch=main)](https://coveralls.io/github/blockcoders/nestjs-ethers?branch=main)
7-
[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/nestjs-ethers)](https://snyk.io/test/github/blockcoders/nestjs-ethers)
7+
[![vulnerabilities](https://badgen.net/snyk/blockcoders/nestjs-ethers)](https://snyk.io/test/github/blockcoders/nestjs-ethers)
8+
[![CodeQL](https://github.com/blockcoders/nestjs-ethers/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/blockcoders/nestjs-ethers/actions/workflows/codeql-analysis.yml)
89
[![supported platforms](https://img.shields.io/badge/platforms-Express%20%26%20Fastify-green)](https://img.shields.io/badge/platforms-Express%20%26%20Fastify-green)
910

1011

@@ -61,6 +62,12 @@ interface EthersModuleOptions {
6162
* @see {@link https://etherscan.io}
6263
*/
6364
etherscan?: string;
65+
66+
/**
67+
* Optional parameter for Bscscan API Token
68+
* @see {@link https://bscscan.com/}
69+
*/
70+
bscscan?: string;
6471

6572
/**
6673
* Optional parameter for use Cloudflare Provider
@@ -83,10 +90,18 @@ interface EthersModuleOptions {
8390
pocket?: PocketProviderOptions | string;
8491

8592
/**
86-
* Optional parameter for Bscscan API Token
87-
* @see {@link https://https://bscscan.com/}
93+
* Optional parameter for Moralis API Token
94+
* or MoralisProviderOptions(apiKey, region)
95+
* @see {@link https://moralis.io/}
8896
*/
89-
bscscan?: string;
97+
moralis?: MoralisProviderOptions | string;
98+
99+
/**
100+
* Optional parameter for Ankr API Token
101+
* or AnkrProviderOptions(apiKey, projectSecret)
102+
* @see {@link https://www.ankr.com/}
103+
*/
104+
ankr?: AnkrProviderOptions | string;
90105

91106
/**
92107
* Optional parameter for a custom StaticJsonRpcProvider
@@ -116,6 +131,12 @@ interface EthersModuleOptions {
116131
* EthersModule will use the FallbackProvider to send multiple requests simultaneously.
117132
*/
118133
useDefaultProvider?: boolean;
134+
135+
/**
136+
* Optional parameter if this option is true, EthersModule will disable
137+
* the console.log in the ethers.js library.
138+
*/
139+
disableEthersLogger?: boolean
119140

120141
/**
121142
* Optional parameter to associate a token name to EthersProvider,
@@ -834,7 +855,7 @@ class ConfigModule {}
834855
class TestModule {}
835856
```
836857

837-
## Testing a class that uses @InjectEthersProvider
858+
## Testing a class that uses InjectEthersProvider
838859

839860
This package exposes a getEthersToken(token?: string) function that returns a prepared injection token based on the provided context.
840861
Using this token, you can easily provide a mock implementation of the `BaseProvider` using any of the standard custom provider techniques, including useClass, useValue, and useFactory.
@@ -851,6 +872,40 @@ Using this token, you can easily provide a mock implementation of the `BaseProvi
851872
}).compile();
852873
```
853874

875+
## Testing a class that uses InjectContractProvider
876+
877+
This package exposes a getContractToken(token?: string) function that returns a prepared injection token based on the contract provided context.
878+
Using this token, you can easily provide a mock implementation of the `ethers.Contract` using any of the standard custom provider techniques, including useClass, useValue, and useFactory.
879+
880+
```ts
881+
const module: TestingModule = await Test.createTestingModule({
882+
providers: [
883+
MyService,
884+
{
885+
provide: getContractToken(MyService.name),
886+
useValue: mockContractProvider,
887+
},
888+
],
889+
}).compile();
890+
```
891+
892+
## Testing a class that uses InjectSignerProvider
893+
894+
This package exposes a getSignerToken(token?: string) function that returns a prepared injection token based on the signer provided context.
895+
Using this token, you can easily provide a mock implementation of the `ethers.Signer` using any of the standard custom provider techniques, including useClass, useValue, and useFactory.
896+
897+
```ts
898+
const module: TestingModule = await Test.createTestingModule({
899+
providers: [
900+
MyService,
901+
{
902+
provide: getSignerToken(MyService.name),
903+
useValue: mockSignerProvider,
904+
},
905+
],
906+
}).compile();
907+
```
908+
854909
## Migration
855910

856911
### v1

__tests__/ethers.contract.spec.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1+
import { Contract } from '@ethersproject/contracts'
12
import { Module, Controller, Get, Injectable } from '@nestjs/common'
23
import { NestFactory } from '@nestjs/core'
34
import * as nock from 'nock'
45
import * as request from 'supertest'
5-
import {
6-
EthersModule,
7-
EthersContract,
8-
Contract,
9-
EthersSigner,
10-
InjectContractProvider,
11-
InjectSignerProvider,
12-
} from '../src'
6+
import { EthersModule, EthersContract, EthersSigner, InjectContractProvider, InjectSignerProvider } from '../src'
137
import * as ABI from './utils/ABI.json'
14-
import { ETHERS_ADDRESS, ETHERS_PRIVATE_KEY } from './utils/constants'
8+
import { ETHERS_ADDRESS, ETHERS_PRIVATE_KEY, NEST_APP_OPTIONS } from './utils/constants'
159
import { extraWait } from './utils/extraWait'
1610
import { platforms } from './utils/platforms'
1711

@@ -70,7 +64,7 @@ describe('EthersContract', () => {
7064
})
7165
class TestModule {}
7266

73-
const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
67+
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
7468
const server = app.getHttpServer()
7569

7670
await app.init()
@@ -128,7 +122,7 @@ describe('EthersContract', () => {
128122
})
129123
class TestModule {}
130124

131-
const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
125+
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
132126
const server = app.getHttpServer()
133127

134128
await app.init()
@@ -189,7 +183,7 @@ describe('EthersContract', () => {
189183
})
190184
class TestModule {}
191185

192-
const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
186+
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
193187
const server = app.getHttpServer()
194188

195189
await app.init()
@@ -255,7 +249,7 @@ describe('EthersContract', () => {
255249
})
256250
class TestModule {}
257251

258-
const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
252+
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
259253
const server = app.getHttpServer()
260254

261255
await app.init()

0 commit comments

Comments
 (0)