Skip to content

Commit

Permalink
DO NOT MERGE: prototype running coverage for unit tests
Browse files Browse the repository at this point in the history
- measure unit test coverage
- enforce minimum requirements
- generate json reports
- unfinished:  derive from a common jest config

Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding committed Feb 7, 2024
1 parent be21702 commit 1255210
Show file tree
Hide file tree
Showing 26 changed files with 382 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
Dockerfile
Makefile
*.bats
coverage-fina.json
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ dist
.netrc

# Cache
.cache
.cache

# Coverage
**/coverage/**
2 changes: 2 additions & 0 deletions packages/devtools-config-jest/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions packages/devtools-config-jest/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.json"
}
2 changes: 2 additions & 0 deletions packages/devtools-config-jest/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
57 changes: 57 additions & 0 deletions packages/devtools-config-jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<p align="center">
<a href="https://layerzero.network">
<img alt="LayerZero" style="max-width: 500px" src="https://d3a2dpnnrypp5h.cloudfront.net/bridge-app/lz.png"/>
</a>
</p>

<h1 align="center">@layerzerolabs/devtools-evm</h1>

<!-- The badges section -->
<p align="center">
<!-- Shields.io NPM published package version -->
<a href="https://www.npmjs.com/package/@layerzerolabs/devtools-evm"><img alt="NPM Version" src="https://img.shields.io/npm/v/@layerzerolabs/devtools-evm"/></a>
<!-- Shields.io NPM downloads -->
<a href="https://www.npmjs.com/package/@layerzerolabs/devtools-evm"><img alt="Downloads" src="https://img.shields.io/npm/dm/@layerzerolabs/devtools-evm"/></a>
<!-- Shields.io license badge -->
<a href="https://www.npmjs.com/package/@layerzerolabs/devtools-evm"><img alt="NPM License" src="https://img.shields.io/npm/l/@layerzerolabs/devtools-evm"/></a>
</p>

Utilities for working with LayerZero EVM contracts.

## Installation

```bash
yarn add @layerzerolabs/devtools-evm

pnpm add @layerzerolabs/devtools-evm

npm install @layerzerolabs/devtools-evm
```

### Address utilities

#### ignoreZero(address: Address | null | undefined)

Turns EVM zero addresses to `undefined`

```typescript
import { ignoreZero } from "@layerzerolabs/devtools-evm";

ignoreZero("0xEe6cF2E1Bc7645F8439d241ce37820305F2BB3F8"); // Returns '0xEe6cF2E1Bc7645F8439d241ce37820305F2BB3F8'
ignoreZero("0x0000000000000000000000000000000000000000"); // Returns undefined
ignoreZero(undefined); // Returns undefined
ignoreZero(null); // Returns undefined
```

#### makeZeroAddress(address)

Turns `null` and `undefined` into EVM zero address

```typescript
import { makeZeroAddress } from "@layerzerolabs/devtools-evm";

makeZeroAddress("0xEe6cF2E1Bc7645F8439d241ce37820305F2BB3F8"); // Returns '0xEe6cF2E1Bc7645F8439d241ce37820305F2BB3F8'
makeZeroAddress("0x0000000000000000000000000000000000000000"); // Returns '0x0000000000000000000000000000000000000000'
makeZeroAddress(undefined); // Returns '0x0000000000000000000000000000000000000000'
makeZeroAddress(null); // Returns '0x0000000000000000000000000000000000000000'
```
83 changes: 83 additions & 0 deletions packages/devtools-config-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "@layerzerolabs/devtools-config-jest",
"version": "0.0.1",
"description": "Utilities for LayerZero EVM projects",
"repository": {
"type": "git",
"url": "git+https://github.com/LayerZero-Labs/devtools.git",
"directory": "packages/devtools-evm"
},
"license": "MIT",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"types": "./dist/*.d.ts",
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"./dist/index.*"
],
"scripts": {
"prebuild": "$npm_execpath tsc --noEmit -p tsconfig.build.json",
"build": "$npm_execpath tsup",
"clean": "rm -rf dist",
"dev": "$npm_execpath tsup --watch",
"lint": "$npm_execpath eslint '**/*.{js,ts,json}'",
"lint:fix": "eslint --fix '**/*.{js,ts,json}'",
"test": "jest --ci --changedSince=origin/main"
},
"dependencies": {
"p-memoize": "~4.0.4"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@layerzerolabs/devtools": "~0.1.3",
"@layerzerolabs/io-devtools": "~0.1.2",
"@layerzerolabs/lz-definitions": "~2.1.3",
"@layerzerolabs/test-devtools": "~0.1.2",
"@swc/core": "^1.4.0",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"fast-check": "^3.15.1",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"ts-node": "^10.9.2",
"tslib": "~2.6.2",
"tsup": "~8.0.1",
"typescript": "^5.3.3",
"zod": "^3.22.4"
},
"peerDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@layerzerolabs/devtools": "~0.1.3",
"@layerzerolabs/io-devtools": "~0.1.2",
"@layerzerolabs/lz-definitions": "~2.1.3",
"zod": "^3.22.4"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/devtools-config-jest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './jest.config'
14 changes: 14 additions & 0 deletions packages/devtools-config-jest/src/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Config } from 'jest'

const config: Config = {
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
},
},
}

export default config
4 changes: 4 additions & 0 deletions packages/devtools-config-jest/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "dist", "test"]
}
11 changes: 11 additions & 0 deletions packages/devtools-config-jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"exclude": ["dist", "node_modules"],
"include": ["src", "test", "*.config.ts"],
"compilerOptions": {
"types": ["node", "jest"],
"paths": {
"@/*": ["./src/*"]
}
}
}
14 changes: 14 additions & 0 deletions packages/devtools-config-jest/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'tsup'

export default defineConfig([
{
entry: ['src/index.ts'],
outDir: './dist',
clean: true,
dts: true,
sourcemap: true,
splitting: false,
treeshake: true,
format: ['esm', 'cjs'],
},
])
9 changes: 9 additions & 0 deletions packages/devtools-evm-hardhat/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 40,
functions: 50,
lines: 50,
statements: 50,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/devtools-evm/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 20,
functions: 50,
lines: 50,
statements: 50,
},
},
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
Expand Down
1 change: 1 addition & 0 deletions packages/devtools-evm/src/errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export type OmniContractErrorParserFactory = Factory<
[contract: OmniContract | null | undefined],
OmniContractErrorParser
>
// here too?
9 changes: 9 additions & 0 deletions packages/devtools/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
Expand Down
9 changes: 9 additions & 0 deletions packages/io-devtools/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 50,
functions: 50,
lines: 50,
statements: 50,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/omnicounter-devtools-evm/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/omnicounter-devtools/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/protocol-devtools-evm/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 0,
functions: 20,
lines: 40,
statements: 40,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/protocol-devtools/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 0,
functions: 0,
lines: 50,
statements: 50,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/toolbox-hardhat/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/ua-devtools-evm-hardhat/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
9 changes: 9 additions & 0 deletions packages/ua-devtools-evm/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
cache: false,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 50,
functions: 50,
lines: 70,
statements: 70,
},
},
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
Expand Down
Loading

0 comments on commit 1255210

Please sign in to comment.