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

Fix unstable tests [DRAFT] #6857

Merged
merged 18 commits into from
Mar 7, 2024
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 @@
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;

Check warning on line 40 in packages/web3-utils/src/objects.ts

View check run for this annotation

Codecov / codecov/patch

packages/web3-utils/src/objects.ts#L40

Added line #L40 was not covered by tests
}
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
Loading