Skip to content

Commit

Permalink
set up env for test & add basic unit test example
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Dec 6, 2023
1 parent d90755c commit f7c1d64
Show file tree
Hide file tree
Showing 25 changed files with 1,061 additions and 1,556 deletions.
27 changes: 19 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
browser: true,
es6: true,
node: true,
jest: true,
mocha: true,
},
globals: {
BigInt: true,
Expand Down Expand Up @@ -161,14 +161,25 @@ module.exports = {
},
{
files: ["**/test/**/*.test.ts"],
plugins: ["jest"],
plugins: ["mocha", "chai-expect"],
extends: ["plugin:mocha/recommended", "plugin:chai-expect/recommended"],
rules: {
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
// We observed that having multiple top level "describe" save valuable indentation
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/max-top-level-suites.md
"mocha/max-top-level-suites": "off",
// We need to disable because we disabled "mocha/no-setup-in-describe" rule
// TODO: Move all setup code to before/beforeEach and then disable async describe
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-async-describe.md
"mocha/no-async-describe": "off",
// Use of arrow functions are very common
"mocha/no-mocha-arrows": "off",
// It's common to call function inside describe block
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md
"mocha/no-setup-in-describe": "off",
// We use to split before in small isolated tasks
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-sibling-hooks.md
"mocha/no-sibling-hooks": "off",
},
},
{
files: ["**/types/**/*.ts"],
Expand Down
4 changes: 4 additions & 0 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension: ["ts"]
colors: true
node-option:
- "loader=ts-node/esm"
183 changes: 0 additions & 183 deletions jest.config.js

This file was deleted.

21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "yarn workspace types run build && yarn workspace db run build & lerna run build",
"lint": "eslint --color --ext .ts packages/*/src/",
"fix-lint": "eslint --ext .ts --fix packages/*/src/",
"test": "lerna run test --concurrency 1",
"test:unit": "lerna run test:unit --no-bail --concurrency 1",
"check-readme": "lerna run check-readme",
"release:publish": "lerna publish from-package --yes --no-verify-access",
Expand All @@ -22,23 +23,33 @@
"lru-cache": "^6.0.0"
},
"devDependencies": {
"@types/chai": "4.3.6",
"@types/chai-as-promised": "7.1.6",
"@types/mocha": "10.0.1",
"@types/sinon": "10.0.16",
"@types/sinon-chai": "3.2.9",
"@types/abstract-leveldown": "7.2.1",
"@types/compression": "1.7.2",
"@types/jest": "29.2.3",
"@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "5.43.0",
"@typescript-eslint/parser": "5.43.0",
"eslint": "8.27.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-prettier": "4.2.1",
"jest": "29.3.1",
"jest-express": "1.12.0",
"eslint-plugin-mocha": "10.2.0",
"lerna": "6.4.1",
"ts-jest": "29.0.3",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.2",
"typescript": "4.8.4"
"typescript": "4.8.4",
"chai": "4.3.8",
"chai-as-promised": "7.1.1",
"sinon": "16.0.0",
"sinon-chai": "3.7.0",
"mocha": "10.2.0",
"vitest": "0.34.6",
"vitest-when": "0.2.0",
"@vitest/coverage-v8": "0.34.6"
},
"license": "MIT",
"workspaces": [
Expand Down
3 changes: 0 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
"test": "yarn test:unit",
"test:unit": "mocha 'test/unit/**/*.test.ts'",
"check-readme": "typescript-docs-verifier"
},
"dependencies": {
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
"test": "yarn test:unit",
"test:unit": "mocha 'test/unit/**/*.test.ts'",
"check-readme": "typescript-docs-verifier"
},
"bugs": {
Expand Down
3 changes: 0 additions & 3 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
"test": "yarn test:unit",
"test:unit": "mocha 'test/unit/**/*.test.ts'",
"check-readme": "typescript-docs-verifier"
},
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/executor/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
colors: true
require:
- ./test/setup.ts
timeout: 5000
exit: true
extension: ["ts"]
node-option:
- "loader=ts-node/esm"
3 changes: 1 addition & 2 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
"test": "yarn test:unit",
"test:unit": "mocha 'test/unit/**/*.test.ts'",
"test:unit": "vitest --run --dir test/unit/",
"check-readme": "typescript-docs-verifier"
},
"dependencies": {
Expand Down
23 changes: 23 additions & 0 deletions packages/executor/test/mocks/GethTracer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { providers } from "ethers";
import { BundlerCollectorReturn } from "types/lib/executor";
import { TracerPrestateResponse } from "../../src/interfaces";

export class GethTracer {
async debug_traceCall(
tx: providers.TransactionRequest
): Promise<BundlerCollectorReturn> {
return {
callsFromEntryPoint: [],
keccak: [],
calls: [],
logs: [],
debug: [],
}
}

async debug_traceCallPrestate(
tx: providers.TransactionRequest
): Promise<TracerPrestateResponse> {
return {};
}
}
Loading

0 comments on commit f7c1d64

Please sign in to comment.