diff --git a/.github/workflows/app-deploy-feature-branch.yml b/.github/workflows/app-deploy-feature-branch.yml index 0e52cfd1e8..b886f8fb1e 100644 --- a/.github/workflows/app-deploy-feature-branch.yml +++ b/.github/workflows/app-deploy-feature-branch.yml @@ -33,7 +33,7 @@ jobs: npm run lint -- --no-fix --max-warnings 0 - name: Test - run: npm run test:unit:ci + run: npm run test:ci - name: Type check run: npm run typecheck diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8cdc307afa..1615a8f5bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: - name: Test run: | - npm run test:unit:ci + npm run test:ci - name: App type check working-directory: ./packages/app diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index 797523479d..e0e54ad6e2 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -49,7 +49,7 @@ jobs: - name: Test run: | - npm run test:unit:ci + npm run test:ci - name: Publish Test Results uses: EnricoMi/publish-unit-test-result-action/composite@v2 diff --git a/README.md b/README.md index 7b5d9034ca..0106eaff3d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,97 @@ -# block-explorer -zkSync Era Block Explorer +

zkSync Era Block Explorer

+ +

Online blockchain browser for viewing and analyzing zkSync Era blockchain.

+ +## 📌 Overview +This repository is a monorepo consisting of 3 packages: +- [Worker](./packages/worker) - an indexer service for [zkSync Era](https://zksync.io) blockchain data. The purpose of the service is to read the data from the blockchain in real time, transform it and fill in it's database with the data in a way that makes it easy to be queried by the [API](./packegs/api) service. +- [API](./packages/api) - a service providing Web API for retrieving structured [zkSync Era](https://zksync.io) blockchain data collected by [Worker](./packages/worker). It connects to the Worker's database to be able to query the collected data. +- [App](./packages/app) - a front-end app providing an easy-to-use interface for users to view and inspect transactions, blocks, contracts and more. It makes requests to the [API](./packages/api) to get the data and presents it in a way that's easy to read and understand. + +## 🏛 Architecture +The following diagram illustrates how are the block explorer components connected: + +```mermaid +flowchart + subgraph blockchain[Blockchain] + Blockchain[zkSync Era JSON-RPC API] + end + + subgraph explorer[Block explorer] + Database[("Block explorer DB
(PostgreSQL)")] + Worker(Worker service) + API(API service) + App(App) + + Worker-.Save processed data.->Database + API-.Query data.->Database + App-."Request data (HTTP)".->API + App-."Request data (HTTP)".->Blockchain + end + + Worker-."Request data (HTTP)".->Blockchain +``` + +[Worker](./packages/worker) service is responsible for getting data from blockchain using [zkSync Era JSON-RPC API](https://era.zksync.io/docs/api/api.html), processing it and saving into the database. [API](./packages/api) service is connected to the same database where it gets the data from to handle API requests. It performs only read requests to the database. The front-end [App](./packages/app) makes HTTP calls to the Block Explorer [API](./packages/api) to get blockchain data and to the [zkSync Era JSON-RPC API](https://era.zksync.io/docs/api/api.html) for reading contracts, performing transactions etc. + +## 🚀 Features + +- ✅ View transactions, blocks, transfers and logs. +- ✅ Inspect accounts, contracts, tokens and balances. +- ✅ Verify smart contracts. +- ✅ Interact with smart contracts. +- ✅ Standalone HTTP API. +- ✅ Local node support. + +## 📋 Prerequisites + +- Ensure you have `node >= 18.0.0` and `npm >= 9.0.0` installed. + +## 🛠 Installation + +```bash +$ npm install +``` + +## ⚙️ Setting up env variables + +Make sure you have set up all the necessary env variables. Follow [Setting up env variables for Worker](./packages/worker#setting-up-env-variables) and [Setting up env variables for API](./packages/api#setting-up-env-variables) for instructions. + +## 👨‍💻 Running locally + +Before running the solution, make sure you have a database server up and running and you have created a database. + +To run all the components (`Worker`, `API` and front-end `App`) in `development` mode run the following command from the root directory. +```bash +$ npm run dev +``` + +For `production` mode run: +```bash +$ npm run build +$ npm run start +``` +To verify front-end `App` is running open http://localhost:3010 in your browser. `API` should be available at http://localhost:3000. `Worker` - http://localhost:3001. + +Each component can also be started individually. Follow individual packages `README` for details. + +## 🕵️‍♂️ Testing +Run unit tests for all packages: +```bash +$ npm run test +``` +Run e2e tests for all packages: +```bash +$ npm run test:e2e +``` +Run tests for a specific package: +```bash +$ npm run test -w {package} +``` +For more details on testing please check individual packages `README`. + +## 💻 Conventional Commits +We follow the Conventional Commits [specification](https://www.conventionalcommits.org/en/v1.0.0/#specification). + +## 📘 License +MIT License. diff --git a/package.json b/package.json index 94439417ea..f25006026c 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,11 @@ "prepare": "husky install", "lint": "lerna run lint", "test": "lerna run test", - "test:unit:ci": "lerna run test:unit:ci", - "build": "lerna run build" + "test:ci": "lerna run test:ci", + "test:e2e": "lerna run test:e2e", + "dev": "lerna run dev", + "build": "lerna run build", + "start": "lerna run start" }, "devDependencies": { "@commitlint/cli": "^17.1.2", diff --git a/packages/api/README.md b/packages/api/README.md index 810aee9fef..9213c2b77b 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -28,16 +28,16 @@ You need to have a running Worker database, for instructions on how to run the w ```bash # development -$ npm run start +$ npm run dev # watch mode -$ npm run start:dev +$ npm run dev:watch # debug mode -$ npm run start:debug +$ npm run dev:debug # production mode -$ npm run start:prod +$ npm run start ``` ## Test diff --git a/packages/api/docker-compose.yaml b/packages/api/docker-compose.yaml index 81a8fc620d..526ede2ade 100644 --- a/packages/api/docker-compose.yaml +++ b/packages/api/docker-compose.yaml @@ -4,7 +4,7 @@ services: build: context: . target: development-stage - command: npm run start:debug + command: npm run dev:debug environment: - PORT=3000 - METRICS_PORT=3005 diff --git a/packages/api/package.json b/packages/api/package.json index d5e41c81ba..6099d980e5 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -11,15 +11,15 @@ "prebuild": "rimraf dist", "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug 0.0.0.0:9229 --watch", - "start:prod": "node dist/main", + "dev": "nest start", + "dev:watch": "nest start --watch", + "dev:debug": "nest start --debug 0.0.0.0:9229 --watch", + "start": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", - "test:unit:ci": "jest --coverage", + "test:ci": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json --runInBand --detectOpenHandles", "test:perf": "artillery run ./performance/load-test.yaml" diff --git a/packages/app/README.md b/packages/app/README.md index b5756da5ba..d799c11bba 100644 --- a/packages/app/README.md +++ b/packages/app/README.md @@ -105,7 +105,7 @@ npm run build ### Run Unit Tests with [Vitest](https://vitest.dev/) ```sh -npm run test:unit +npm run test ``` ### Run End-to-End Tests with [Playwright](https://www.playwright.io/) diff --git a/packages/app/package.json b/packages/app/package.json index 61d82a772b..7a0bb9cc46 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -4,9 +4,9 @@ "scripts": { "dev": "vite", "build": "vue-tsc --noEmit && vite build", - "preview": "vite preview --port 5050", + "start": "vite preview --port 3010", "test": "TZ=UTC-3 vitest --environment jsdom", - "test:unit:ci": "TZ=UTC-3 vitest --environment jsdom --run --reporter=verbose --reporter=junit --outputFile.junit=./junit.xml", + "test:ci": "TZ=UTC-3 vitest --environment jsdom --run --reporter=verbose --reporter=junit --outputFile.junit=./junit.xml", "test:e2e": "cucumber-js -t \"not @testnet\"", "typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix", diff --git a/packages/worker/README.md b/packages/worker/README.md index d30daef05c..44097746ec 100644 --- a/packages/worker/README.md +++ b/packages/worker/README.md @@ -29,16 +29,16 @@ You need to have a running Postgres server, set the following env variables to p ```bash # development -$ npm run start +$ npm run dev # watch mode -$ npm run start:dev +$ npm run dev:watch # debug mode -$ npm run start:debug +$ npm run dev:debug # production mode -$ npm run start:prod +$ npm run start ``` ## Running the app in Docker diff --git a/packages/worker/docker-compose.yaml b/packages/worker/docker-compose.yaml index a12e78ef2e..e229f2bd50 100644 --- a/packages/worker/docker-compose.yaml +++ b/packages/worker/docker-compose.yaml @@ -4,7 +4,7 @@ services: build: context: . target: development-stage - command: npm run start:debug + command: npm run dev:debug environment: - PORT=3001 - LOG_LEVEL=verbose diff --git a/packages/worker/package.json b/packages/worker/package.json index f91c923376..9028d97184 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -11,15 +11,15 @@ "prebuild": "rimraf dist", "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug 0.0.0.0:9229 --watch", - "start:prod": "node dist/main", + "dev": "nest start", + "dev:watch": "nest start --watch", + "dev:debug": "nest start --debug 0.0.0.0:9229 --watch", + "start": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", - "test:unit:ci": "jest --coverage", + "test:ci": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", "typeorm": "typeorm-ts-node-commonjs",