Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stress Tests 1 - QA Tests #6595

Merged
merged 36 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4060610
add data stress test
avkos Nov 9, 2023
b9188d6
fix unit tests
avkos Nov 9, 2023
a9a1138
fix
avkos Nov 9, 2023
7217b8c
try to fix validator test
avkos Nov 9, 2023
071effb
fix ipc tests
avkos Nov 9, 2023
a59ee25
fix load test
avkos Nov 9, 2023
7ac76be
fix
avkos Nov 9, 2023
df948c0
move to tests folder
avkos Nov 13, 2023
21114eb
moved
avkos Nov 13, 2023
ba56d6a
fix
avkos Nov 13, 2023
0c3afb9
Merge branch '4.x' into ok/5563-Stress-Tests-2---QA-Tests
avkos Nov 13, 2023
40decbb
add send tests
avkos Nov 14, 2023
faba5aa
browser tests
avkos Nov 14, 2023
3ddf0dd
move validator test to web3 package
avkos Nov 14, 2023
5320283
Merge branch 'ok/5563-Stress-Tests-2---QA-Tests' into ok/5562-Stress-…
avkos Nov 14, 2023
e7eaee1
fix
avkos Nov 14, 2023
548eadb
fix naming
avkos Nov 14, 2023
61c41e5
add browser test
avkos Nov 14, 2023
c6a91e8
fix
avkos Nov 15, 2023
dfb00d3
Merge branch '4.x' into ok/5562-Stress-Tests-1---QA-Tests
Muhammad-Altabba Nov 19, 2023
3f35de2
move to TS. remove time logs
avkos Nov 20, 2023
11dd804
fix start.sh
avkos Nov 20, 2023
d38f993
Merge branch '4.x' into ok/5563-Stress-Tests-2---QA-Tests
avkos Nov 20, 2023
af66127
fix validation test run script
avkos Nov 20, 2023
cca9311
fix name
avkos Nov 20, 2023
2431a16
Merge branch 'ok/5563-Stress-Tests-2---QA-Tests' into ok/5562-Stress-…
avkos Nov 20, 2023
69e9b7b
move to TS
avkos Nov 20, 2023
9c88783
move to jest
avkos Nov 21, 2023
008de2c
Merge branch '4.x' into ok/5562-Stress-Tests-1---QA-Tests
avkos Nov 21, 2023
192f70b
add browser tests
avkos Nov 21, 2023
acf1649
fix
avkos Nov 21, 2023
900eb97
Merge branch '4.x' into ok/5562-Stress-Tests-1---QA-Tests
avkos Nov 23, 2023
de28728
fixes
avkos Nov 27, 2023
425359b
fix
avkos Nov 27, 2023
5b7cd0c
Merge branch '4.x' into ok/5562-Stress-Tests-1---QA-Tests
avkos Nov 27, 2023
bd18b4a
fix tests count
avkos Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move to jest
  • Loading branch information
avkos committed Nov 21, 2023
commit 9c8878395bc327d7f80b590c17ab4cf97750bf0e
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"geth-binary:start": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh start",
"geth-binary:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh start 1",
"geth-binary:stop": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh stop",
"geth-manual:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh manualStart 1",
"geth-manual:stop": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh stop",
"lint": "lerna run lint --stream --parallel",
"lint:fix": "lerna run lint:fix --stream --parallel",
"format": "lerna run format --stream --parallel && prettier --write ./scripts/**/*.ts",
Expand All @@ -61,6 +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:manual": "lerna run test:manual --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",
Expand All @@ -74,6 +77,8 @@
"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",
"generate:accounts": "node ./scripts/gen_accounts.js",
"pre-blackbox": "yarn config set registry http://localhost:4873 && git init && git config --global user.email \"[email protected]\" && git config --global user.name \"CI\"",
"post-blackbox": "./scripts/verdaccio.sh stop",
Expand All @@ -85,10 +90,6 @@
"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:stress:data": "packages/web3/test/stress/large_request_data/start.sh",
"test:manual:stress:requests": "packages/web3/test/stress/many_requests/start.sh",
"test:manual:stress:validation": "npx ts-node packages/web3/test/stress/large_validator_data/index.ts",
"test:manual:stress": "yarn test:manual:stress:data && yarn test:manual:stress:validation && yarn test:stress:requests",
"husky:install": "husky install",
"husky:uninstall": "husky uninstall",
"postinstall": "yarn build",
Expand Down
1 change: 1 addition & 0 deletions packages/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"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:manual": "jest --config=./test/manual/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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

/* 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';
import accounts from '../../../../scripts/accounts.json';
import { isWs, isIpc, getSystemTestProvider } from '../../../../scripts/system_tests_utils';
import { BasicAbi, BasicBytecode } from '../../../../fixtures/build/Basic';

const DATA_AMOUNT = 50 * 1024; // 50 kB

Expand All @@ -38,32 +38,33 @@ const sendAndGetData = async (web3: Web3, i: number) => {
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);
describe('huge data', () => {
let web3: Web3;
beforeAll(() => {
web3 = new Web3(getSystemTestProvider());
});
afterAll(() => {
if (isWs || isIpc) {
(web3.provider as unknown as WebSocketProvider).disconnect();
}
});

for (const a of accounts) {
const acc = web3.eth.accounts.privateKeyToAccount(a.privateKey);
web3.eth.accounts.wallet.add(acc);
}
it('send and get', async () => {
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);
const prs = [];
for (let i = 0; i < 15; i++) {
prs.push(sendAndGetData(web3, i));
}
await Promise.all(prs);
});
});
33 changes: 33 additions & 0 deletions packages/web3/test/manual/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const base = require('../config/jest.config');

module.exports = {
...base,
setupFilesAfterEnv: ['<rootDir>/test/manual/setup.js'],
testMatch: ['<rootDir>/test/manual/**/*.(spec|test).(js|ts)'],
/**
* restoreMocks [boolean]
*
* Default: false
*
* Automatically restore mock state between every test.
* Equivalent to calling jest.restoreAllMocks() between each test.
* This will lead to any mocks having their fake implementations removed
* and restores their initial implementation.
*/
restoreMocks: true,

/**
* resetModules [boolean]
*
* Default: false
*
* By default, each test file gets its own independent module registry.
* Enabling resetModules goes a step further and resets the module registry before running each individual test.
* This is useful to isolate modules for every test so that local module state doesn't conflict between tests.
* This can be done programmatically using jest.resetModules().
*/
resetModules: true,
coverageDirectory: '.coverage/integration',
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable */
import { Web3, Contract, Numbers, EventLog } from 'web3';
import { IpcProvider } from 'web3-providers-ipc';
import { BasicBytecode, BasicAbi } from '../../shared_fixtures/build/Basic';
import WebSocketProvider from 'web3-providers-ws';
import { Web3Account } from 'web3-eth-accounts';
import { Web3, Contract, Numbers, EventLog } from 'web3';
import { BasicBytecode, BasicAbi } from '../../../../fixtures/build/Basic';
import { isWs, isIpc, getSystemTestProvider } from '../../../../scripts/system_tests_utils';

const providerString = String(process.env.WEB3_SYSTEM_TEST_PROVIDER);
const isWs = providerString.startsWith('ws');
const isIpc = providerString.includes('ipc');
const contracts: { [key: string]: Contract<typeof BasicAbi> } = {};

const deployContracts = async (web3: Web3, accounts: Web3Account[]) => {
Expand Down Expand Up @@ -108,53 +106,42 @@ const subscribeContract = (acc: Web3Account) => {
});
};
const contractSubscriptions = (accounts: Web3Account[]) => {
console.log(`Subscribe to ${accounts.length} contracts events`);
for (const acc of accounts) {
subscribeContract(acc);
}
};
const test = async () => {
console.log(`Start test with provider: ${providerString}`);
const provider = isIpc
? new IpcProvider(providerString)
: isWs
? new Web3.providers.WebsocketProvider(providerString)
: new Web3.providers.HttpProvider(providerString);
const web3 = new Web3(provider);
const n = Number(process.env.PARALLEL_COUNT) || 500;

console.log(`Prepare ${n} accounts in parallel`);
const accounts = await prepareAccounts(web3, n);

console.log(`Deploy ${n} contracts in parallel`);
await deployContracts(web3, accounts);
// if socket subscribe to events
if (isIpc || isWs) {
contractSubscriptions(accounts);
}

console.log(`Send data from ${n} accounts in parallel`);
const sendPrs = [];
for (let i = 0; i < n; i++) {
sendPrs.push(sendData(accounts[i]));
}
await Promise.all(sendPrs);
describe('huge data', () => {
let web3: Web3;
let parallelCount = 500;
beforeAll(() => {
parallelCount = isIpc ? 5 : parallelCount;
web3 = new Web3(getSystemTestProvider());
});
afterAll(() => {
if (isWs || isIpc) {
(web3.provider as unknown as WebSocketProvider).disconnect();
}
});
it('send requests', async () => {
const accounts = await prepareAccounts(web3, parallelCount);

if (isIpc || isWs) {
if (Object.keys(receivedEvents).length !== accounts.length) {
throw new Error('Incorrect event count');
await deployContracts(web3, accounts);
// if socket subscribe to events
if (isIpc || isWs) {
contractSubscriptions(accounts);
}
}

console.log(`Get data from ${n} accounts in parallel`);
const getPrs = [];
for (let i = 0; i < n; i++) {
getPrs.push(getData(accounts[i]));
}
await Promise.all(getPrs);
if (isIpc || isWs) {
(web3.provider as IpcProvider).disconnect();
}
};
const sendPrs = [];
for (let i = 0; i < parallelCount; i++) {
sendPrs.push(sendData(accounts[i]));
}
await Promise.all(sendPrs);

test().catch(console.error);
const getPrs = [];
for (let i = 0; i < parallelCount; i++) {
getPrs.push(getData(accounts[i]));
}
await Promise.all(getPrs);
});
});
24 changes: 24 additions & 0 deletions packages/web3/test/manual/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
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 <http://www.gnu.org/licenses/>.
*/

// Have to use `require` because of Jest issue https://jestjs.io/docs/ecmascript-modules
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../config/setup');

const jestTimeout = 300000; // Sometimes `in3` takes long time because of its decentralized nature.

jest.setTimeout(jestTimeout);
Loading