Skip to content

Commit

Permalink
Stress Tests 2 - QA Tests (#6583)
Browse files Browse the repository at this point in the history
* add data stress test

* fix unit tests

* fix

* try to fix validator test

* fix ipc tests

* fix load test

* fix

* move to tests folder

* moved

* fix

* move validator test to web3 package

* move to TS. remove time logs

* fix start.sh

* fix validation test run script

* fix name
  • Loading branch information
avkos authored Nov 20, 2023
1 parent d8b8e18 commit 2c60685
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 186 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
"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/start.sh",
"test:manual:stress:validation": "npx ts-node packages/web3/test/stress/validator.ts",
"test:manual:stress": "yarn test:manual:stress:data && yarn test:manual:stress:validation",
"husky:install": "husky install",
"husky:uninstall": "husky uninstall",
"postinstall": "yarn build",
Expand Down
184 changes: 0 additions & 184 deletions packages/web3-validator/test/unit/load.test.ts

This file was deleted.

68 changes: 68 additions & 0 deletions packages/web3/test/stress/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
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/>.
*/

/* 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<typeof BasicAbi>(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);
17 changes: 17 additions & 0 deletions packages/web3/test/stress/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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
Loading

0 comments on commit 2c60685

Please sign in to comment.