Skip to content

Commit

Permalink
Release v2.0.0 - Nest.js v9 (#140)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
0xslipk authored Jan 7, 2023
1 parent 67a3446 commit cf9449f
Show file tree
Hide file tree
Showing 21 changed files with 5,016 additions and 3,369 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ orbs:
# The Node.js orb contains a set of prepackaged CircleCI configuration you can utilize
# Orbs reduce the amount of configuration required for common tasks.
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node
node: circleci/[email protected].0
node: circleci/[email protected].3
coveralls: coveralls/[email protected]

jobs:
Expand All @@ -15,7 +15,7 @@ jobs:
node-version:
type: string
docker:
- image: circleci/node:<< parameters.node-version >>
- image: cimg/node:<< parameters.node-version >>
resource_class: small
steps:
- checkout
Expand Down Expand Up @@ -50,4 +50,4 @@ workflows:
- test:
matrix:
parameters:
node-version: ['16.13', '14.18', '12.22']
node-version: ['18.12', '16.18', '14.21']
74 changes: 74 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '20 7 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'TypeScript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# 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
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.14
lts/hydrogen
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# Changelog

## 2.0.0
Published by **[blockcoders](https://github.com/blockcoders)** on **2023/01/07**
- [#140](https://github.com/blockcoders/nestjs-ethers/pull/140) Release v2.0.0 - Nest.js v9
- [#142](https://github.com/blockcoders/nestjs-ethers/pull/142) Update README.md by [@copocaneta](https://github.com/copocaneta)

### BREAKING CHANGE
- Dropped support for node < 14
- Upgrade @nestjs/* from 8.x to 9.x
- Remove deprecated ethereum chains (ropsten, rinkeby and kovan).
- Add new RPC providers Moralis and Ankr.
- Ethers.js is not longer part of the index.ts export.
- @ethersproject/* is now part of peerDependencies.

## 1.0.3
Published by **[blockcoders](https://github.com/blockcoders)** on **2022/05/08**
- [#140](https://github.com/blockcoders/nestjs-ethers/pull/140) Update dependencies
- [#141](https://github.com/blockcoders/nestjs-ethers/pull/141) Update dependencies
- [#139](https://github.com/blockcoders/nestjs-ethers/pull/139) Fix: Function name createWalletFromEncryptedJson by [@GustavoRSSilva](https://github.com/GustavoRSSilva)
- [#138](https://github.com/blockcoders/nestjs-ethers/pull/138) Fix: README injected variable ethersContract by [@GustavoRSSilva](https://github.com/GustavoRSSilva)

Expand Down
65 changes: 60 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ NestJS-Ethers
[![npm](https://img.shields.io/npm/v/nestjs-ethers)](https://www.npmjs.com/package/nestjs-ethers)
[![CircleCI](https://circleci.com/gh/blockcoders/nestjs-ethers/tree/main.svg?style=svg)](https://circleci.com/gh/blockcoders/nestjs-ethers/tree/main)
[![Coverage Status](https://coveralls.io/repos/github/blockcoders/nestjs-ethers/badge.svg?branch=main)](https://coveralls.io/github/blockcoders/nestjs-ethers?branch=main)
[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/nestjs-ethers)](https://snyk.io/test/github/blockcoders/nestjs-ethers)
[![vulnerabilities](https://badgen.net/snyk/blockcoders/nestjs-ethers)](https://snyk.io/test/github/blockcoders/nestjs-ethers)
[![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)
[![supported platforms](https://img.shields.io/badge/platforms-Express%20%26%20Fastify-green)](https://img.shields.io/badge/platforms-Express%20%26%20Fastify-green)


Expand Down Expand Up @@ -61,6 +62,12 @@ interface EthersModuleOptions {
* @see {@link https://etherscan.io}
*/
etherscan?: string;

/**
* Optional parameter for Bscscan API Token
* @see {@link https://bscscan.com/}
*/
bscscan?: string;

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

/**
* Optional parameter for Bscscan API Token
* @see {@link https://https://bscscan.com/}
* Optional parameter for Moralis API Token
* or MoralisProviderOptions(apiKey, region)
* @see {@link https://moralis.io/}
*/
bscscan?: string;
moralis?: MoralisProviderOptions | string;

/**
* Optional parameter for Ankr API Token
* or AnkrProviderOptions(apiKey, projectSecret)
* @see {@link https://www.ankr.com/}
*/
ankr?: AnkrProviderOptions | string;

/**
* Optional parameter for a custom StaticJsonRpcProvider
Expand Down Expand Up @@ -116,6 +131,12 @@ interface EthersModuleOptions {
* EthersModule will use the FallbackProvider to send multiple requests simultaneously.
*/
useDefaultProvider?: boolean;

/**
* Optional parameter if this option is true, EthersModule will disable
* the console.log in the ethers.js library.
*/
disableEthersLogger?: boolean

/**
* Optional parameter to associate a token name to EthersProvider,
Expand Down Expand Up @@ -834,7 +855,7 @@ class ConfigModule {}
class TestModule {}
```

## Testing a class that uses @InjectEthersProvider
## Testing a class that uses InjectEthersProvider

This package exposes a getEthersToken(token?: string) function that returns a prepared injection token based on the provided context.
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.
Expand All @@ -851,6 +872,40 @@ Using this token, you can easily provide a mock implementation of the `BaseProvi
}).compile();
```

## Testing a class that uses InjectContractProvider

This package exposes a getContractToken(token?: string) function that returns a prepared injection token based on the contract provided context.
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.

```ts
const module: TestingModule = await Test.createTestingModule({
providers: [
MyService,
{
provide: getContractToken(MyService.name),
useValue: mockContractProvider,
},
],
}).compile();
```

## Testing a class that uses InjectSignerProvider

This package exposes a getSignerToken(token?: string) function that returns a prepared injection token based on the signer provided context.
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.

```ts
const module: TestingModule = await Test.createTestingModule({
providers: [
MyService,
{
provide: getSignerToken(MyService.name),
useValue: mockSignerProvider,
},
],
}).compile();
```

## Migration

### v1
Expand Down
20 changes: 7 additions & 13 deletions __tests__/ethers.contract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Contract } from '@ethersproject/contracts'
import { Module, Controller, Get, Injectable } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import * as nock from 'nock'
import * as request from 'supertest'
import {
EthersModule,
EthersContract,
Contract,
EthersSigner,
InjectContractProvider,
InjectSignerProvider,
} from '../src'
import { EthersModule, EthersContract, EthersSigner, InjectContractProvider, InjectSignerProvider } from '../src'
import * as ABI from './utils/ABI.json'
import { ETHERS_ADDRESS, ETHERS_PRIVATE_KEY } from './utils/constants'
import { ETHERS_ADDRESS, ETHERS_PRIVATE_KEY, NEST_APP_OPTIONS } from './utils/constants'
import { extraWait } from './utils/extraWait'
import { platforms } from './utils/platforms'

Expand Down Expand Up @@ -70,7 +64,7 @@ describe('EthersContract', () => {
})
class TestModule {}

const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
const server = app.getHttpServer()

await app.init()
Expand Down Expand Up @@ -128,7 +122,7 @@ describe('EthersContract', () => {
})
class TestModule {}

const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
const server = app.getHttpServer()

await app.init()
Expand Down Expand Up @@ -189,7 +183,7 @@ describe('EthersContract', () => {
})
class TestModule {}

const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
const server = app.getHttpServer()

await app.init()
Expand Down Expand Up @@ -255,7 +249,7 @@ describe('EthersContract', () => {
})
class TestModule {}

const app = await NestFactory.create(TestModule, new PlatformAdapter(), { logger: false })
const app = await NestFactory.create(TestModule, new PlatformAdapter(), NEST_APP_OPTIONS)
const server = app.getHttpServer()

await app.init()
Expand Down
Loading

0 comments on commit cf9449f

Please sign in to comment.