From de28728db0835627a39201397f146faebb4801d5 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 27 Nov 2023 18:05:23 -0500 Subject: [PATCH] fixes --- package.json | 16 +-- packages/web3/package.json | 6 +- .../web3/test/{manual => stress}/data.test.ts | 14 +- packages/web3/test/stress/index.ts | 68 ---------- .../test/{manual => stress}/jest.config.js | 4 +- .../browser_test/connection.html | 0 .../nodejs_test/long_connection_ws.js | 0 .../test/{manual => stress}/requests.test.ts | 6 +- .../web3/test/{manual => stress}/setup.js | 0 packages/web3/test/stress/start.sh | 17 --- .../{manual => stress}/validation.test.ts | 0 packages/web3/test/stress/validator.ts | 126 ------------------ scripts/test-runner.sh | 4 +- 13 files changed, 24 insertions(+), 237 deletions(-) rename packages/web3/test/{manual => stress}/data.test.ts (84%) delete mode 100644 packages/web3/test/stress/index.ts rename packages/web3/test/{manual => stress}/jest.config.js (88%) rename packages/web3/test/{manual => stress}/long_ws_tests/browser_test/connection.html (100%) rename packages/web3/test/{manual => stress}/long_ws_tests/nodejs_test/long_connection_ws.js (100%) rename packages/web3/test/{manual => stress}/requests.test.ts (95%) rename packages/web3/test/{manual => stress}/setup.js (100%) delete mode 100755 packages/web3/test/stress/start.sh rename packages/web3/test/{manual => stress}/validation.test.ts (100%) delete mode 100644 packages/web3/test/stress/validator.ts diff --git a/package.json b/package.json index 290086dff09..2a767bf4d23 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "test:coverage:integration": "lerna run test:coverage:integration --stream --parallel", "test:unit": "lerna run test:unit --stream --parallel && jest --config=./scripts/jest.config.js", "test:integration": "lerna run test:integration --stream", - "test:integration:manual": "lerna run test:integration:manual --stream", + "test:integration:stress": "lerna run test:integration:stress --stream", "test:e2e:ganache:http": "./scripts/test-runner.sh ganache http", "test:e2e:ganache:ws": "./scripts/test-runner.sh ganache ws", "test:e2e:geth:http": "./scripts/test-runner.sh geth http", @@ -77,12 +77,10 @@ "test:e2e:mainnet:ws": "./scripts/test-runner.sh mainnet ws", "test:e2e:sepolia:http": "./scripts/test-runner.sh sepolia http", "test:e2e:sepolia:ws": "./scripts/test-runner.sh sepolia ws", - "test:e2e:manual:geth:ws": "./scripts/test-runner.sh geth-manual ws node manual", - "test:e2e:manual:geth:ipc": "./scripts/test-runner.sh geth-manual ipc node manual", - "test:e2e:manual:geth:http": "./scripts/test-runner.sh geth-manual http node manual", - "test:e2e:manual:geth:ws:chrome": "./scripts/test-runner.sh geth-manual ws chrome manual", - "test:e2e:manual:geth:ws:firefox": "./scripts/test-runner.sh geth-manual ws firefox manual", - "test:e2e:manual:geth:ws:electron": "./scripts/test-runner.sh geth-manual ws electron manual", + "test:stress:geth:ws": "./scripts/test-runner.sh geth-manual ws node manual", + "test:stress:geth:ipc": "./scripts/test-runner.sh geth-manual ipc node manual", + "test:stress:geth:http": "./scripts/test-runner.sh geth-manual http node manual", + "test:e2e:stress:geth:ws:chrome": "./scripts/test-runner.sh geth-manual ws chrome manual", "generate:accounts": "node ./scripts/gen_accounts.js", "pre-blackbox": "yarn config set registry http://localhost:4873 && git init && git config --global user.email \"ci@github.com\" && git config --global user.name \"CI\"", "post-blackbox": "./scripts/verdaccio.sh stop", @@ -94,8 +92,8 @@ "test:blackbox:geth:ws": "yarn pre-blackbox && yarn geth:start:background && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:geth:ws --stream && yarn post-blackbox:geth", "test:blackbox:infura:http": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:http --stream && yarn post-blackbox", "test:blackbox:infura:ws": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:ws --stream && yarn post-blackbox", - "test:manual:long-connection-ws":"node ./packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js", - "test:manual":"yarn test:e2e:manual:geth:ws && yarn test:e2e:manual:geth:http && yarn test:e2e:manual:geth:ipc", + "test:manual:long-connection-ws": "node packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js", + "test:stress":"yarn test:stress:geth:ws && yarn test:stress:geth:http && yarn test:stress:geth:ipc && yarn test:e2e:stress:geth:ws:chrome", "husky:install": "husky install", "husky:uninstall": "husky uninstall", "postinstall": "yarn build", diff --git a/packages/web3/package.json b/packages/web3/package.json index 8f33f3e7b08..675264fdbfd 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -53,16 +53,14 @@ "test:watch": "npm test -- --watch", "test:unit": "jest --config=./test/unit/jest.config.js", "test:integration": "jest --config=./test/integration/jest.config.js --forceExit", - "test:integration:manual": "jest --config=./test/manual/jest.config.js --forceExit", + "test:integration:stress": "jest --config=./test/stress/jest.config.js --forceExit", "test:blackbox:ganache:http": "./scripts/black_box_test.sh ganache http", "test:blackbox:ganache:ws": "./scripts/black_box_test.sh ganache ws", "test:blackbox:geth:http": "./scripts/black_box_test.sh geth http", "test:blackbox:geth:ws": "./scripts/black_box_test.sh geth ws", "test:blackbox:infura:http": "./scripts/black_box_test.sh infura http", "test:blackbox:infura:ws": "./scripts/black_box_test.sh infura ws", - "test:e2e:electron:manual": "npx cypress run --headless --browser electron", - "test:e2e:chrome:manual": "npx cypress run --headless --browser chrome", - "test:e2e:firefox:manual": "npx cypress run --headless --browser firefox" + "test:e2e:chrome:stress": "npx cypress run --headless --browser chrome" }, "devDependencies": { "@truffle/hdwallet-provider": "^2.0.12", diff --git a/packages/web3/test/manual/data.test.ts b/packages/web3/test/stress/data.test.ts similarity index 84% rename from packages/web3/test/manual/data.test.ts rename to packages/web3/test/stress/data.test.ts index eb57a6ebab8..7e9eb6a7f24 100644 --- a/packages/web3/test/manual/data.test.ts +++ b/packages/web3/test/stress/data.test.ts @@ -37,11 +37,13 @@ const sendAndGetData = async (web3: Web3, i: number) => { const c = new web3.eth.Contract(BasicAbi); const contract = await c.deploy(deployOptions).send(sendOptions); - await contract.methods - .setValues(1, 'A'.repeat(DATA_AMOUNT), true) - .send({ from: accounts[i].address }); + await expect( + contract.methods + .setValues(1, 'A'.repeat(DATA_AMOUNT), true) + .send({ from: accounts[i].address }), + ).resolves.toBeDefined(); - await contract.methods.getStringValue().call(); + await expect(contract.methods.getStringValue().call()).resolves.toBe('A'.repeat(DATA_AMOUNT)); }; describe('huge data', () => { @@ -55,7 +57,7 @@ describe('huge data', () => { } }); - it('send and get', async () => { + it('send and get large data', async () => { for (const a of accounts) { const acc = web3.eth.accounts.privateKeyToAccount(a.privateKey); web3.eth.accounts.wallet.add(acc); @@ -65,6 +67,6 @@ describe('huge data', () => { for (let i = 0; i < 15; i++) { prs.push(sendAndGetData(web3, i)); } - await Promise.all(prs); + await expect(Promise.all(prs)).resolves.toBeDefined(); }); }); diff --git a/packages/web3/test/stress/index.ts b/packages/web3/test/stress/index.ts deleted file mode 100644 index 67471e136fb..00000000000 --- a/packages/web3/test/stress/index.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* -This file is part of web3.js. - -web3.js is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -web3.js is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with web3.js. If not, see . -*/ - -/* eslint-disable */ -import { Web3 } from 'web3'; -import { IpcProvider } from 'web3-providers-ipc'; -import accounts from '../shared_fixtures/accounts.json'; -import { BasicAbi, BasicBytecode } from '../shared_fixtures/build/Basic'; -import WebSocketProvider from 'web3-providers-ws'; -const DATA_AMOUNT = 50 * 1024; // 50 kB - -const sendAndGetData = async (web3: Web3, i: number) => { - const sendOptions = { from: accounts[i].address }; - const deployOptions = { - data: BasicBytecode, - arguments: [0, ''] as [number, string], - gasPrice: await web3.eth.getGasPrice(), - gas: BigInt(9000000000000), - gasLimit: BigInt(9000000000000), - type: BigInt(0), - }; - const c = new web3.eth.Contract(BasicAbi); - const contract = await c.deploy(deployOptions).send(sendOptions); - - await contract.methods - // @ts-ignore - .setValues(1, 'A'.repeat(DATA_AMOUNT), true) - .send({ from: accounts[i].address }); - - await contract.methods.getStringValue().call(); -}; - -const test = async () => { - const providerString = String(process.env.WEB3_SYSTEM_TEST_PROVIDER); - console.log(`Start test with provider: ${providerString}`); - const provider = providerString.includes('ipc') - ? new IpcProvider(providerString) - : providerString; - const web3 = new Web3(provider); - - for (const a of accounts) { - const acc = web3.eth.accounts.privateKeyToAccount(a.privateKey); - web3.eth.accounts.wallet.add(acc); - } - - const prs = []; - for (let i = 0; i < 15; i++) { - prs.push(sendAndGetData(web3, i)); - } - await Promise.all(prs); - (web3.provider as unknown as WebSocketProvider).disconnect(); -}; - -test().catch(console.error); diff --git a/packages/web3/test/manual/jest.config.js b/packages/web3/test/stress/jest.config.js similarity index 88% rename from packages/web3/test/manual/jest.config.js rename to packages/web3/test/stress/jest.config.js index 3ce6277a283..de1e19d4ace 100644 --- a/packages/web3/test/manual/jest.config.js +++ b/packages/web3/test/stress/jest.config.js @@ -4,8 +4,8 @@ const base = require('../config/jest.config'); module.exports = { ...base, - setupFilesAfterEnv: ['/test/manual/setup.js'], - testMatch: ['/test/manual/**/*.(spec|test).(js|ts)'], + setupFilesAfterEnv: ['/test/stress/setup.js'], + testMatch: ['/test/stress/**/*.(spec|test).(js|ts)'], /** * restoreMocks [boolean] * diff --git a/packages/web3/test/manual/long_ws_tests/browser_test/connection.html b/packages/web3/test/stress/long_ws_tests/browser_test/connection.html similarity index 100% rename from packages/web3/test/manual/long_ws_tests/browser_test/connection.html rename to packages/web3/test/stress/long_ws_tests/browser_test/connection.html diff --git a/packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js b/packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js similarity index 100% rename from packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js rename to packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js diff --git a/packages/web3/test/manual/requests.test.ts b/packages/web3/test/stress/requests.test.ts similarity index 95% rename from packages/web3/test/manual/requests.test.ts rename to packages/web3/test/stress/requests.test.ts index b79e09fd573..6509bf869ac 100644 --- a/packages/web3/test/manual/requests.test.ts +++ b/packages/web3/test/stress/requests.test.ts @@ -126,12 +126,12 @@ describe('huge data', () => { (web3.provider as unknown as WebSocketProvider).disconnect(); } }); - it('send requests', async () => { + it('send requests large number of requests', async () => { const sendPrs = []; for (let i = 0; i < parallelCount; i++) { sendPrs.push(sendData(accounts[i])); } - await Promise.all(sendPrs); + expect(await Promise.all(sendPrs)).resolves.toBeDefined(); // if socket subscribe to events if (isIpc || isWs) { contractSubscriptions(accounts); @@ -142,6 +142,6 @@ describe('huge data', () => { for (let i = 0; i < parallelCount; i++) { getPrs.push(getData(accounts[i])); } - await Promise.all(getPrs); + await expect(Promise.all(getPrs)).resolves.toBeDefined(); }); }); diff --git a/packages/web3/test/manual/setup.js b/packages/web3/test/stress/setup.js similarity index 100% rename from packages/web3/test/manual/setup.js rename to packages/web3/test/stress/setup.js diff --git a/packages/web3/test/stress/start.sh b/packages/web3/test/stress/start.sh deleted file mode 100755 index 9de30d524d9..00000000000 --- a/packages/web3/test/stress/start.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -. scripts/env.sh - -export WEB3_SYSTEM_TEST_BACKEND="geth" -export TS_NODE_PREFER_TS_EXTS=true - -./scripts/geth_binary.sh stressStart - -yarn generate:accounts - -export WEB3_SYSTEM_TEST_PROVIDER=$IPC_PATH -npx ts-node ./packages/web3/test/stress/index.ts - -export WEB3_SYSTEM_TEST_PROVIDER=ws://127.0.0.1:8545 -npx ts-node ./packages/web3/test/stress/index.ts - -./scripts/geth_binary.sh stop diff --git a/packages/web3/test/manual/validation.test.ts b/packages/web3/test/stress/validation.test.ts similarity index 100% rename from packages/web3/test/manual/validation.test.ts rename to packages/web3/test/stress/validation.test.ts diff --git a/packages/web3/test/stress/validator.ts b/packages/web3/test/stress/validator.ts deleted file mode 100644 index 076351820c0..00000000000 --- a/packages/web3/test/stress/validator.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* -This file is part of web3.js. - -web3.js is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -web3.js is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with web3.js. If not, see . -*/ - -/* eslint-disable */ -import { Web3Validator, JsonSchema, Json } from 'web3-validator'; - -const abi = [ - { indexed: true, internalType: 'address', name: 'from', type: 'address' }, - { indexed: true, internalType: 'address', name: 'to', type: 'address' }, - { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, -]; - -const abiJsonSchema = { - type: 'array', - items: [ - { name: 'from', format: 'address' }, - { name: 'to', format: 'address' }, - { name: 'value', format: 'uint256' }, - ], -}; - -const abiData = [ - '0xCB00CDE33a7a0Fba30C63745534F1f7Ae607076b', - '0xCB00CDE33a7a0Fba30C63745534F1f7Ae607076b', - '0xCB00CDE33a7a0Fba30C63745534F1f7Ae607076b', -]; - -const simpleSchema = { - type: 'object', - required: ['blockHash', 'blockNumber', 'from', 'to', 'data'], - properties: { - blockHash: { - format: 'bytes32', - }, - blockNumber: { - format: 'uint', - }, - from: { - format: 'address', - }, - to: { - oneOf: [{ format: 'address' }, { type: 'null' }], - }, - data: { - format: 'bytes', - }, - }, -}; - -const simpleData = { - blockHash: '0x0dec0518fa672a70027b04c286582e543ab17319fbdd384fa7bc8f3d5a542c0b', - blockNumber: BigInt(2), - from: '0xCB00CDE33a7a0Fba30C63745534F1f7Ae607076b', - to: '0xCB00CDE33a7a0Fba30C63745534F1f7Ae607076b', - data: '0xafea', -}; - -const createHugeSchema = ( - schema: JsonSchema, - data: Json, - n = 3, -): { schema: JsonSchema; data: Json } => { - if (n > 0) { - const { data: resultData, schema: resultSchema } = createHugeSchema( - { ...simpleSchema }, - { ...simpleData } as unknown as Json, - n - 1, - ); - return { - data: { ...(typeof data === 'object' ? data : { data }), simple: resultData }, - schema: { ...schema, properties: { ...schema.properties, simple: resultSchema } }, - }; - } - return { - schema, - data, - }; -}; - -const { schema: hugeSchema, data: hugeData } = createHugeSchema( - { ...simpleSchema }, - { ...simpleData } as unknown as Json, - 500, -); - -const { schema: hugeSchema1000, data: hugeData1000 } = createHugeSchema( - { ...simpleSchema }, - { ...simpleData } as unknown as Json, - 1000, -); - -const validator = new Web3Validator(); - -validator.validateJSONSchema(hugeSchema, hugeData as object); - -validator.validateJSONSchema(hugeSchema1000, hugeData1000 as object); - -for (let i = 0; i < 500; i += 1) { - validator.validateJSONSchema(simpleSchema, simpleData); -} - -for (let i = 0; i < 1000; i += 1) { - validator.validateJSONSchema(simpleSchema, simpleData); -} - -for (let i = 0; i < 1000; i += 1) { - validator.validateJSONSchema(abiJsonSchema, abiData); -} - -for (let i = 0; i < 1000; i += 1) { - validator.validate(abi, abiData); -} diff --git a/scripts/test-runner.sh b/scripts/test-runner.sh index 4fb8e43c688..cbe35641285 100755 --- a/scripts/test-runner.sh +++ b/scripts/test-runner.sh @@ -56,7 +56,7 @@ fi if [[ $ENGINE == "node" ]] || [[ $ENGINE == "" ]]; then if [[ $TEST_OPTION == "manual" ]]; then - TEST_COMMAND="test:integration:manual" + TEST_COMMAND="test:integration:stress" elif [[ $TEST_OPTION == "coverage" ]]; then TEST_COMMAND="test:coverage:integration" elif [[ $BACKEND == "sepolia" || $BACKEND == "mainnet" ]]; then @@ -66,7 +66,7 @@ if [[ $ENGINE == "node" ]] || [[ $ENGINE == "" ]]; then fi else if [[ $TEST_OPTION == "manual" ]]; then - TEST_COMMAND="lerna run test:e2e:$ENGINE:manual --stream" + TEST_COMMAND="lerna run test:e2e:$ENGINE:stress --stream" else TEST_COMMAND="lerna run test:e2e:$ENGINE --stream" fi