Skip to content

Commit

Permalink
close connections in other test files
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Urbas committed Oct 21, 2024
1 parent c700d82 commit 7633c3c
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose",
"test:watch": "npm test -- --watch",
"test:unit": "jest --config=./test/unit/jest.config.js",
"test:integration": "jest --config=./test/integration/jest.config.js --runInBand",
"test:integration": "jest --config=./test/integration/jest.config.js --runInBand --detectOpenHandles",
"test:e2e:electron": "npx cypress run --headless --browser electron --env grep='ignore',invert=true",
"test:e2e:chrome": "npx cypress run --headless --browser chrome --env grep='ignore',invert=true",
"test:e2e:firefox": "npx cypress run --headless --browser firefox --env grep='ignore',invert=true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
describeIf,
getSystemTestBackend,
BACKEND,
closeOpenConnection,
} from '../fixtures/system_test_utils';

describe('contract', () => {
Expand All @@ -46,6 +47,10 @@ describe('contract', () => {
sendOptions = { from: acc.address, gas: '1000000' };
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('create access list for setter', async () => {
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);
deployedContract.defaultAccount = acc.address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { Contract } from '../../src';
import { GreeterBytecode, GreeterAbi } from '../shared_fixtures/build/Greeter';
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
import {
getSystemTestProvider,
createTempAccount,
closeOpenConnection,
} from '../fixtures/system_test_utils';

describe('contract', () => {
describe('clone', () => {
let contract: Contract<typeof GreeterAbi>;
let deployOptions: Record<string, unknown>;
let sendOptions: Record<string, unknown>;

beforeAll(async () => {
contract = new Contract(GreeterAbi, undefined, {
provider: getSystemTestProvider(),
Expand All @@ -37,6 +42,10 @@ describe('contract', () => {
sendOptions = { from: acc.address, gas: '1000000' };
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('should clone the contract but with same address', async () => {
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);
const newContract = deployedContract.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { Web3Context } from 'web3-core';

import { Contract } from '../../src';
import { GreeterBytecode, GreeterAbi } from '../shared_fixtures/build/Greeter';
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
import {
getSystemTestProvider,
createTempAccount,
closeOpenConnection,
} from '../fixtures/system_test_utils';

describe('contract', () => {
describe('defaults', () => {
Expand All @@ -43,6 +47,10 @@ describe('contract', () => {
sendOptions = { from: acc.address, gas: '1000000' };
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('should use "defaultAccount" on "instance" level instead of "from"', async () => {
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);
// eslint-disable-next-line prefer-destructuring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('contract defaults (extra)', () => {
sendOptions = { from: acc.address, gas: '1000000' };
});

afterEach(async () => {
afterAll(async () => {
await closeOpenConnection(contract);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Contract } from '../../src';
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
import {
getSystemTestProvider,
createTempAccount,
closeOpenConnection,
} from '../fixtures/system_test_utils';
import { MyContractAbi, MyContractBytecode } from '../fixtures/MyContract';

describe('request empty string from contract', () => {
let contract: Contract<typeof MyContractAbi>;
let deployOptions: Record<string, unknown>;
let sendOptions: Record<string, unknown>;

beforeAll(async () => {
contract = new Contract(MyContractAbi, undefined, {
provider: getSystemTestProvider(),
Expand All @@ -37,6 +42,10 @@ describe('request empty string from contract', () => {
sendOptions = { from: acc.address, gas: '1000000' };
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('should fetch empty string', async () => {
const deployedContract = await contract.deploy(deployOptions).send(sendOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ describe('contract', () => {
contractDeployed = await contract.deploy(deployOptions).send(sendOptions);
});

afterAll(async () => {
await closeOpenConnection(contractDeployed);
});

describe('methods', () => {
it('should return the name', async () => {
expect(await contractDeployed.methods.name().call()).toBe('Gold');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('contract', () => {

afterAll(async () => {
await closeOpenConnection(contract);
await closeOpenConnection(contractDeployed);
});

it('should deploy the contract', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('contract', () => {

afterAll(async () => {
await closeOpenConnection(contract);
await closeOpenConnection(contractDeployed);
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import Web3 from 'web3';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Web3Account } from 'web3-eth-accounts';
import { GreeterBytecode, GreeterAbi } from '../../shared_fixtures/build/Greeter';
import { getSystemTestProvider, createLocalAccount } from '../../fixtures/system_test_utils';
import {
getSystemTestProvider,
createLocalAccount,
closeOpenConnection,
} from '../../fixtures/system_test_utils';
import { Contract } from '../../../src';

describe('contract', () => {
Expand All @@ -45,6 +49,10 @@ describe('contract', () => {
};
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it.each(['0x1', '0x2'])('should emit the "sending" event', async txType => {
const handler = jest.fn();
const acc = await createLocalAccount(web3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import Web3 from 'web3';
import { Web3Account } from 'web3-eth-accounts';
import { Contract } from '../../../src';
import { ERC20TokenAbi, ERC20TokenBytecode } from '../../shared_fixtures/build/ERC20Token';
import { getSystemTestProvider, createLocalAccount } from '../../fixtures/system_test_utils';
import {
getSystemTestProvider,
createLocalAccount,
closeOpenConnection,
} from '../../fixtures/system_test_utils';

const initialSupply = BigInt('5000000000');

Expand Down Expand Up @@ -53,6 +57,10 @@ describe('contract', () => {
contractDeployed = await contract.deploy(deployOptions).send(sendOptions);
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('should deploy the contract', () => {
expect(contractDeployed.options.address).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import Web3 from 'web3';
import { Web3Account } from 'web3-eth-accounts';
import { Contract } from '../../../src';
import { ERC721TokenAbi, ERC721TokenBytecode } from '../../shared_fixtures/build/ERC721Token';
import { getSystemTestProvider, createLocalAccount } from '../../fixtures/system_test_utils';
import {
getSystemTestProvider,
createLocalAccount,
closeOpenConnection,
} from '../../fixtures/system_test_utils';
import { toUpperCaseHex } from '../../shared_fixtures/utils';

describe('contract', () => {
Expand All @@ -32,6 +36,7 @@ describe('contract', () => {
let localAccount: Web3Account;
let web3: Web3;
let contractDeployed: Contract<typeof ERC721TokenAbi>;

beforeAll(async () => {
web3 = new Web3(getSystemTestProvider());
localAccount = await createLocalAccount(web3);
Expand All @@ -53,6 +58,10 @@ describe('contract', () => {
.send({ ...sendOptions, gas: '3000000' });
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('should deploy the contract', () => {
expect(contractDeployed.options.address).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { utf8ToHex } from 'web3-utils';
import { EventLog } from 'web3-types';
import { Contract } from '../../../src';
import { ERC721TokenAbi, ERC721TokenBytecode } from '../../shared_fixtures/build/ERC721Token';
import { getSystemTestProvider, createLocalAccount } from '../../fixtures/system_test_utils';
import {
getSystemTestProvider,
createLocalAccount,
closeOpenConnection,
} from '../../fixtures/system_test_utils';
import { toUpperCaseHex } from '../../shared_fixtures/utils';

describe('contract ERC721 overloaded functions', () => {
Expand Down Expand Up @@ -55,6 +59,10 @@ describe('contract ERC721 overloaded functions', () => {
.send({ ...sendOptions, gas: '3000000' });
});

afterAll(async () => {
await closeOpenConnection(contract);
});

it('transferFrom with 4 arguments', async () => {
const tempAccount = await createLocalAccount(web3);
const toAccount = await createLocalAccount(web3);
Expand Down

0 comments on commit 7633c3c

Please sign in to comment.