From 94b7910dcb8a369b468b3d0ff050990812da4ca7 Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 18:09:14 +0100 Subject: [PATCH 1/8] test: exclude cli-tests from eslint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7549c74c..ec8ba549 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "build": "tsc -p tsconfig.build.json", "dev": "cross-env NODE_ENV=development ts-node-esm src/index.ts", "typecheck": "tsc -p . --noEmit", - "lint": "eslint . --ext ./src/* --fix --ignore-path .gitignore --no-error-on-unmatched-pattern --max-warnings=0", + "lint": "eslint . --ext ./src/* --fix --ignore-path .gitignore --ignore-pattern cli-tests --no-error-on-unmatched-pattern --max-warnings=0", "commitlint": "commitlint --edit" }, "keywords": [ From ee4b1b1144ecf111579fe56710de0deb0f10a794 Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 18:26:43 +0100 Subject: [PATCH 2/8] test: added notes in readme --- README.md | 10 +++++++++- tsconfig.json | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b2a48e0..8b2fedf6 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,17 @@ If you're using [local setup (dockerized testing node)](https://github.com/matte ### Testing -At the moment, we don't have any tests, but we are working on it. +At the moment, we are working on CLI tests. In the meantime, you can test the code manually by running the code in [development mode](#run-in-development-mode). +### CLI tests + +To run CLI tests for zksync-cli do the following: +1. Go to [cli-tests](`./src/tests/cli-tests`) folder +2. Run `npm i` and install zksync-cli `npm i zksync-cli` +3. Make sure you have [Docker](https://docs.docker.com/engine/install/) on your system. +4. Run `npm test` + ## 🌍 Official Links - [Website](https://zksync.io/) diff --git a/tsconfig.json b/tsconfig.json index c76306d8..89ac735d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,5 +9,6 @@ "strict": true, "resolveJsonModule": true }, - "include": ["./src"] + "include": ["./src"], + "exclude": ["**/cli-tests/**"] } From 2dd77307108acbcf01ad7c02dff2a8a927b0229d Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 18:37:03 +0100 Subject: [PATCH 3/8] test: added notes in readme and redirection switcher --- README.md | 3 ++- src/tests/cli-tests/tests/common.test.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b2fedf6..92cd639d 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,8 @@ To run CLI tests for zksync-cli do the following: 1. Go to [cli-tests](`./src/tests/cli-tests`) folder 2. Run `npm i` and install zksync-cli `npm i zksync-cli` 3. Make sure you have [Docker](https://docs.docker.com/engine/install/) on your system. -4. Run `npm test` +4. Make sure you have `.env` file with your wallet private key in `src\tests\cli-tests\src\` dir. Key is `E2E_TESTNET_PK`. It may looks like `E2E_TESTNET_PK=012345...abcdef` +5. Run `npm test` ## 🌍 Official Links diff --git a/src/tests/cli-tests/tests/common.test.ts b/src/tests/cli-tests/tests/common.test.ts index 2d5facc2..f847e3e8 100644 --- a/src/tests/cli-tests/tests/common.test.ts +++ b/src/tests/cli-tests/tests/common.test.ts @@ -166,9 +166,13 @@ describe("User can call read method from deployed contract on network", () => { describe("User can call write method from deployed contract on network", () => { it('npx zksync-cli contract write', () => { + let optionalRedirection = ''; + if (process.platform === 'win32') { + optionalRedirection = ' > nul ' + } const command = `npx zksync-cli contract write --chain zksync-sepolia\ --contract ${contracts.sepoliaTestnet} --method "setGreeting(string _greeting) "\ - --args "New Test ARG" --private-key ${wallet.testnetPK} > nul`; // potential issue. on windows without the redirection we catching a wrong stdout. + --args "New Test ARG" --private-key ${wallet.testnetPK} ${optionalRedirection}`; // potential issue. on windows without the redirection we catching a wrong stdout. const result = executeCommand(command); console.log("Full output: ----> " + result.output); expect(result.output).toMatch(/(Transaction submitted.)/i); From f3cff2a0e672d4eb87d775dadc1bf13bf88239e7 Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 19:07:15 +0100 Subject: [PATCH 4/8] test: get a key --- .github/workflows/test-cli.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-cli.yml b/.github/workflows/test-cli.yml index e356bc05..90f7fbb9 100644 --- a/.github/workflows/test-cli.yml +++ b/.github/workflows/test-cli.yml @@ -37,6 +37,8 @@ jobs: npm i zksync-cli - name: Run tests + env: + E2E_TESTNET_PK: ${{ secrets.E2E_TESTNET_PK }} run: | cd src/tests/cli-tests npx jest --verbose --testPathPattern=${{ matrix.tags }} From 09b6a935418e86126a295a80aa6d874386ab8fdf Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 19:18:12 +0100 Subject: [PATCH 5/8] test: find a key --- .github/workflows/test-cli.yml | 2 +- src/tests/cli-tests/src/entities.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-cli.yml b/.github/workflows/test-cli.yml index 90f7fbb9..4e9e2d1f 100644 --- a/.github/workflows/test-cli.yml +++ b/.github/workflows/test-cli.yml @@ -38,9 +38,9 @@ jobs: - name: Run tests env: + CI: true E2E_TESTNET_PK: ${{ secrets.E2E_TESTNET_PK }} run: | cd src/tests/cli-tests npx jest --verbose --testPathPattern=${{ matrix.tags }} shell: bash - diff --git a/src/tests/cli-tests/src/entities.ts b/src/tests/cli-tests/src/entities.ts index b7e42e85..ab9a6404 100644 --- a/src/tests/cli-tests/src/entities.ts +++ b/src/tests/cli-tests/src/entities.ts @@ -1,8 +1,8 @@ import * as dotenv from "dotenv"; -import * as path from 'path'; +// import * as path from 'path'; -dotenv.config({ path: path.resolve(__dirname, ".env") }); +dotenv.config(); // { path: path.resolve(__dirname, ".env") } export const adresses = { sepoliaTestnet: "0x52B6d10d7d865B3d4103f8809AA3521288568f46", From 628321579ce73c6cce5b7860200e792e74bb2e41 Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 19:20:57 +0100 Subject: [PATCH 6/8] test: update stdout --- src/tests/cli-tests/tests/common.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/cli-tests/tests/common.test.ts b/src/tests/cli-tests/tests/common.test.ts index f847e3e8..8565d467 100644 --- a/src/tests/cli-tests/tests/common.test.ts +++ b/src/tests/cli-tests/tests/common.test.ts @@ -166,7 +166,7 @@ describe("User can call read method from deployed contract on network", () => { describe("User can call write method from deployed contract on network", () => { it('npx zksync-cli contract write', () => { - let optionalRedirection = ''; + let optionalRedirection = '> /dev/null'; if (process.platform === 'win32') { optionalRedirection = ' > nul ' } From f27cc7103a3b4650debc587951b2fb4fbf19be8c Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 19:25:56 +0100 Subject: [PATCH 7/8] test: update node --- .github/workflows/test-cli.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-cli.yml b/.github/workflows/test-cli.yml index 4e9e2d1f..0d26dc2e 100644 --- a/.github/workflows/test-cli.yml +++ b/.github/workflows/test-cli.yml @@ -14,7 +14,7 @@ jobs: windows-latest, macos-latest ] - node-version: ['lts/*', '18.17.1'] # or 18.17.1 + node-version: ['19.9.0', '18.17.1'] # or 18.17.1 tags: [ "common.test.ts" ] From 5228b808eef42327509642d7644ecee12e794c14 Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 25 Jan 2024 19:26:16 +0100 Subject: [PATCH 8/8] test: update node --- src/tests/cli-tests/tests/common.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/cli-tests/tests/common.test.ts b/src/tests/cli-tests/tests/common.test.ts index 8565d467..ae32c706 100644 --- a/src/tests/cli-tests/tests/common.test.ts +++ b/src/tests/cli-tests/tests/common.test.ts @@ -174,7 +174,6 @@ describe("User can call write method from deployed contract on network", () => { --contract ${contracts.sepoliaTestnet} --method "setGreeting(string _greeting) "\ --args "New Test ARG" --private-key ${wallet.testnetPK} ${optionalRedirection}`; // potential issue. on windows without the redirection we catching a wrong stdout. const result = executeCommand(command); - console.log("Full output: ----> " + result.output); expect(result.output).toMatch(/(Transaction submitted.)/i); expect(result.output).toMatch(/(Transaction processed successfully.)/i); expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);