Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 1724f35

Browse files
authored
fix: correctly close ws connection in web3-eth-contract integration tests (#7338)
1 parent 098ee6d commit 1724f35

22 files changed

+487
-347
lines changed

lerna.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"lerna": "4.0.0",
3-
"npmClient": "yarn",
4-
"useWorkspaces": true,
5-
"version": "independent",
6-
"packages": ["packages/*", "tools/*"]
2+
"lerna": "4.0.0",
3+
"npmClient": "yarn",
4+
"useWorkspaces": true,
5+
"version": "independent",
6+
"packages": ["packages/*", "tools/*"]
77
}

packages/web3-eth-contract/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
"format": "prettier --write '**/*'",
3636
"test": "jest --config=./test/unit/jest.config.js",
3737
"test:coverage:unit": "jest --config=./test/unit/jest.config.js --coverage=true --coverage-reporters=text",
38-
"test:coverage:integration": "jest --config=./test/integration/jest.config.js --runInBand --forceExit --coverage=true --coverage-reporters=text",
38+
"test:coverage:integration": "jest --config=./test/integration/jest.config.js --runInBand --coverage=true --coverage-reporters=text",
3939
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose",
4040
"test:watch": "npm test -- --watch",
4141
"test:unit": "jest --config=./test/unit/jest.config.js",
42-
"test:integration": "jest --config=./test/integration/jest.config.js --runInBand --forceExit",
42+
"test:integration": "jest --config=./test/integration/jest.config.js --runInBand",
4343
"test:e2e:electron": "npx cypress run --headless --browser electron --env grep='ignore',invert=true",
4444
"test:e2e:chrome": "npx cypress run --headless --browser chrome --env grep='ignore',invert=true",
4545
"test:e2e:firefox": "npx cypress run --headless --browser firefox --env grep='ignore',invert=true"

packages/web3-eth-contract/test/integration/contract_accesslist.test.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ import {
2323
describeIf,
2424
getSystemTestBackend,
2525
BACKEND,
26+
closeOpenConnection,
2627
} from '../fixtures/system_test_utils';
2728

2829
describe('contract', () => {
2930
describeIf(getSystemTestBackend() === BACKEND.GETH)('createAccessList', () => {
3031
let contract: Contract<typeof GreeterAbi>;
32+
let deployedContract: Contract<typeof GreeterAbi>;
3133
let deployOptions: Record<string, unknown>;
3234
let sendOptions: Record<string, unknown>;
3335
let acc: { address: string; privateKey: string };
3436

35-
beforeEach(async () => {
37+
beforeAll(async () => {
3638
contract = new Contract(GreeterAbi, undefined, {
3739
provider: getSystemTestProvider(),
3840
});
@@ -46,10 +48,16 @@ describe('contract', () => {
4648
sendOptions = { from: acc.address, gas: '1000000' };
4749
});
4850

49-
it('create access list for setter', async () => {
50-
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);
51+
afterAll(async () => {
52+
await closeOpenConnection(contract);
53+
});
54+
55+
beforeEach(async () => {
56+
deployedContract = await contract.deploy(deployOptions).send(sendOptions);
5157
deployedContract.defaultAccount = acc.address;
58+
});
5259

60+
it('create access list for setter', async () => {
5361
const receipt = await deployedContract.methods
5462
.setGreeting('New Greeting')
5563
.send({ gas: '1000000' });
@@ -75,9 +83,6 @@ describe('contract', () => {
7583
});
7684

7785
it('create access list for getter', async () => {
78-
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);
79-
deployedContract.defaultAccount = acc.address;
80-
8186
const receipt = await deployedContract.methods
8287
.setGreeting('New Greeting')
8388
.send({ gas: '1000000' });

packages/web3-eth-contract/test/integration/contract_clone.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
import { Contract } from '../../src';
1818
import { GreeterBytecode, GreeterAbi } from '../shared_fixtures/build/Greeter';
19-
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
19+
import {
20+
getSystemTestProvider,
21+
createTempAccount,
22+
closeOpenConnection,
23+
} from '../fixtures/system_test_utils';
2024

2125
describe('contract', () => {
2226
describe('clone', () => {
2327
let contract: Contract<typeof GreeterAbi>;
2428
let deployOptions: Record<string, unknown>;
2529
let sendOptions: Record<string, unknown>;
30+
2631
beforeAll(async () => {
2732
contract = new Contract(GreeterAbi, undefined, {
2833
provider: getSystemTestProvider(),
@@ -34,7 +39,11 @@ describe('contract', () => {
3439
arguments: ['My Greeting'],
3540
};
3641

37-
sendOptions = { from: acc.address, gas: '1000000' };
42+
sendOptions = { from: acc.address };
43+
});
44+
45+
afterAll(async () => {
46+
await closeOpenConnection(contract);
3847
});
3948

4049
it('should clone the contract but with same address', async () => {

packages/web3-eth-contract/test/integration/contract_defaults.test.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { Web3Context } from 'web3-core';
2020

2121
import { Contract } from '../../src';
2222
import { GreeterBytecode, GreeterAbi } from '../shared_fixtures/build/Greeter';
23-
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
23+
import {
24+
getSystemTestProvider,
25+
createTempAccount,
26+
closeOpenConnection,
27+
} from '../fixtures/system_test_utils';
2428

2529
describe('contract', () => {
2630
describe('defaults', () => {
@@ -43,6 +47,10 @@ describe('contract', () => {
4347
sendOptions = { from: acc.address, gas: '1000000' };
4448
});
4549

50+
afterEach(async () => {
51+
await closeOpenConnection(contract);
52+
});
53+
4654
it('should use "defaultAccount" on "instance" level instead of "from"', async () => {
4755
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);
4856
// eslint-disable-next-line prefer-destructuring
@@ -63,23 +71,27 @@ describe('contract', () => {
6371
});
6472

6573
it('should set syncWithContext from init options', async () => {
66-
contract = new Contract(GreeterAbi, {
74+
const testContract = new Contract(GreeterAbi, {
6775
provider: getSystemTestProvider(),
6876
syncWithContext: true,
6977
});
7078

71-
contract = await contract.deploy(deployOptions).send(sendOptions);
79+
const deployedContract = await testContract.deploy(deployOptions).send(sendOptions);
7280

73-
expect(contract.syncWithContext).toBeTruthy();
81+
expect(deployedContract.syncWithContext).toBeTruthy();
82+
83+
await closeOpenConnection(testContract);
7484
});
7585

76-
it('should subscribe to provided context upon instantiation', () => {
86+
it('should subscribe to provided context upon instantiation', async () => {
7787
const web3Context = new Web3Context('http://127.0.0.1:8545');
7888
const _contract = new Contract([], { syncWithContext: true }, web3Context);
7989
expect(_contract.defaultBlock).toBe('latest');
8090

8191
web3Context.defaultBlock = 'earliest';
8292
expect(_contract.defaultBlock).toBe('earliest');
93+
94+
await closeOpenConnection(_contract);
8395
});
8496

8597
describe('defaultBlock', () => {

0 commit comments

Comments
 (0)