Skip to content

Commit

Permalink
Fix unstable tests [DRAFT] (#6857)
Browse files Browse the repository at this point in the history
* void test

* set arc

* fix jest warnings

* increase cache

* increase cache

* try diff version

* fix bigint problem

* ix

* +

* hot fix

* update geth-binary version

* increase timout for accounts test

* fix

* revert

* fix

---------

Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com>
  • Loading branch information
avkos and jdevcs authored Mar 7, 2024
1 parent edf3164 commit cf60f71
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 124 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ jobs:
steps:
- uses: actions/setup-node@v4
with:
architecture: x64
node-version: ${{ matrix.node }}
- uses: actions/cache/restore@v3
with:
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-core/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
},
verbose: false,
collectCoverage: false,
coverageReporters: ['json'],
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-eth-abi/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-eth-accounts/test/unit/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import {
import { TransactionFactory } from '../../src/tx/transactionFactory';
import { TxData } from '../../src/tx/types';

jest.setTimeout(25000);

describe('accounts', () => {
describe('create', () => {
describe('valid cases', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-eth-contract/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-ens/test/integration/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { ENSRegistryBytecode } from '../fixtures/ens/bytecode/ENSRegistryBytecod
import { NameWrapperBytecode } from '../fixtures/ens/bytecode/NameWrapperBytecode';
import { PublicResolverBytecode } from '../fixtures/ens/bytecode/PublicResolverBytecode';

jest.setTimeout(25000);
describe('ens', () => {
let registry: Contract<typeof ENSRegistryAbi>;
let resolver: Contract<typeof PublicResolverAbi>;
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-eth-personal/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
32 changes: 20 additions & 12 deletions packages/web3-eth/test/unit/format_transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
numbersAsNumberTransaction,
bytesAsUint8ArrayTransaction,
} from '../fixtures/format_transaction';
import { objectBigintToString } from '../fixtures/system_test_utils';

const transactionsDataForNumberTypes: Record<FMT_NUMBER, Record<string, unknown>> = {
[FMT_NUMBER.BIGINT]: numbersAsBigIntTransaction,
Expand Down Expand Up @@ -59,14 +60,16 @@ describe('formatTransaction', () => {
delete expectedFormattedTransaction.data;

expect(
formatTransaction(
transactionsDataForNumberTypes[sourceType as FMT_NUMBER],
{
...DEFAULT_RETURN_FORMAT,
number: destinationType as FMT_NUMBER,
},
objectBigintToString(
formatTransaction(
transactionsDataForNumberTypes[sourceType as FMT_NUMBER],
{
...DEFAULT_RETURN_FORMAT,
number: destinationType as FMT_NUMBER,
},
),
),
).toStrictEqual(expectedFormattedTransaction);
).toStrictEqual(objectBigintToString(expectedFormattedTransaction));
});
}
}
Expand All @@ -85,11 +88,16 @@ describe('formatTransaction', () => {
delete expectedFormattedTransaction.data;

expect(
formatTransaction(transactionsDataForByteTypes[sourceType as FMT_BYTES], {
...DEFAULT_RETURN_FORMAT,
bytes: destinationType as FMT_BYTES,
}),
).toStrictEqual(expectedFormattedTransaction);
objectBigintToString(
formatTransaction(
transactionsDataForByteTypes[sourceType as FMT_BYTES],
{
...DEFAULT_RETURN_FORMAT,
bytes: destinationType as FMT_BYTES,
},
),
),
).toStrictEqual(objectBigintToString(expectedFormattedTransaction));
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-net/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-providers-ipc/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-types/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
verbose: false,
collectCoverage: false,
Expand Down
9 changes: 5 additions & 4 deletions packages/web3-utils/src/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ export const mergeDeep = (
destination: Record<string, unknown>,
...sources: Record<string, unknown>[]
): Record<string, unknown> => {
const result = { ...destination }; // clone deep here
if (!isIterable(result)) {
return result;
if (!isIterable(destination)) {
return destination;
}
const result = { ...destination }; // clone deep here
for (const src of sources) {
// const src = { ..._src };
// eslint-disable-next-line no-restricted-syntax
for (const key in src) {
if (isIterable(src[key])) {
if (!result[key]) {
result[key] = {};
}
mergeDeep(
result[key] = mergeDeep(
result[key] as Record<string, unknown>,
src[key] as Record<string, unknown>,
);
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-utils/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
},
verbose: false,
collectCoverage: false,
coverageReporters: ['json'],
Expand Down
4 changes: 1 addition & 3 deletions packages/web3-utils/test/unit/objects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import { mergeDeepData } from '../fixtures/objects';
describe('objects', () => {
describe('mergeDeep', () => {
it.each(mergeDeepData)('$message', ({ destination, sources, output }) => {
mergeDeep(destination, ...sources);

expect(destination).toEqual(output);
expect(mergeDeep(destination, ...sources)).toEqual(output);
});

it('should not mutate the sources', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-validator/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
22 changes: 22 additions & 0 deletions packages/web3-validator/test/integration/void.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
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/>.
*/

describe('Web3 validator test', () => {
it('void', () => {
expect(1).toBe(1);
});
});
7 changes: 6 additions & 1 deletion packages/web3/test/cjs_black_box/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ module.exports = {
},
},
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
};
12 changes: 6 additions & 6 deletions packages/web3/test/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/config/setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
7 changes: 6 additions & 1 deletion packages/web3/test/esm_black_box/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export default {
},
},
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: './test/tsconfig.json',
},
],
},
};
8 changes: 4 additions & 4 deletions scripts/geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ start() {
if [ -z "${ORIGARGS[1]}" ]
then
echo "Starting geth..."
echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev"
docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev
echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev"
docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev
else
echo "Starting geth..."
echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev"
docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:latest --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev
echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev"
docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:v1.13.14-amd64 --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev
echo "Waiting for geth..."
npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT"
echo "Geth started"
Expand Down
Loading

1 comment on commit cf60f71

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: cf60f71 Previous: 6c075db Ratio
processingTx 9411 ops/sec (±5.38%) 9301 ops/sec (±4.81%) 0.99
processingContractDeploy 42893 ops/sec (±7.08%) 39129 ops/sec (±7.62%) 0.91
processingContractMethodSend 20615 ops/sec (±6.15%) 19443 ops/sec (±5.19%) 0.94
processingContractMethodCall 41729 ops/sec (±4.91%) 38971 ops/sec (±6.34%) 0.93
abiEncode 48362 ops/sec (±6.33%) 44252 ops/sec (±6.92%) 0.92
abiDecode 32365 ops/sec (±7.10%) 30419 ops/sec (±8.89%) 0.94
sign 1636 ops/sec (±3.29%) 1656 ops/sec (±4.08%) 1.01
verify 371 ops/sec (±0.66%) 373 ops/sec (±0.78%) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.