diff --git a/lerna.json b/lerna.json index b5104ac58aa..e45823a46f8 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,7 @@ { - "lerna": "4.0.0", - "npmClient": "yarn", - "useWorkspaces": true, - "version": "independent", - "packages": ["packages/*", "tools/*"] + "lerna": "4.0.0", + "npmClient": "yarn", + "useWorkspaces": true, + "version": "independent", + "packages": ["packages/*", "tools/*"] } diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 20b368174c8..0cd539d966b 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -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" diff --git a/packages/web3-eth-contract/test/integration/contract_accesslist.test.ts b/packages/web3-eth-contract/test/integration/contract_accesslist.test.ts index 3173f452c33..9c1aff2af36 100644 --- a/packages/web3-eth-contract/test/integration/contract_accesslist.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_accesslist.test.ts @@ -23,16 +23,18 @@ import { describeIf, getSystemTestBackend, BACKEND, + closeOpenConnection, } from '../fixtures/system_test_utils'; describe('contract', () => { describeIf(getSystemTestBackend() === BACKEND.GETH)('createAccessList', () => { let contract: Contract; + let deployedContract: Contract; let deployOptions: Record; let sendOptions: Record; let acc: { address: string; privateKey: string }; - beforeEach(async () => { + beforeAll(async () => { contract = new Contract(GreeterAbi, undefined, { provider: getSystemTestProvider(), }); @@ -46,10 +48,16 @@ describe('contract', () => { sendOptions = { from: acc.address, gas: '1000000' }; }); - it('create access list for setter', async () => { - const deployedContract = await contract.deploy(deployOptions).send(sendOptions); + afterAll(async () => { + await closeOpenConnection(contract); + }); + + beforeEach(async () => { + deployedContract = await contract.deploy(deployOptions).send(sendOptions); deployedContract.defaultAccount = acc.address; + }); + it('create access list for setter', async () => { const receipt = await deployedContract.methods .setGreeting('New Greeting') .send({ gas: '1000000' }); @@ -75,9 +83,6 @@ describe('contract', () => { }); it('create access list for getter', async () => { - const deployedContract = await contract.deploy(deployOptions).send(sendOptions); - deployedContract.defaultAccount = acc.address; - const receipt = await deployedContract.methods .setGreeting('New Greeting') .send({ gas: '1000000' }); diff --git a/packages/web3-eth-contract/test/integration/contract_clone.test.ts b/packages/web3-eth-contract/test/integration/contract_clone.test.ts index 873ac0658ea..937a20172fa 100644 --- a/packages/web3-eth-contract/test/integration/contract_clone.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_clone.test.ts @@ -16,13 +16,18 @@ along with web3.js. If not, see . */ 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; let deployOptions: Record; let sendOptions: Record; + beforeAll(async () => { contract = new Contract(GreeterAbi, undefined, { provider: getSystemTestProvider(), @@ -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(); diff --git a/packages/web3-eth-contract/test/integration/contract_defaults.test.ts b/packages/web3-eth-contract/test/integration/contract_defaults.test.ts index b481237c739..0f28e31269b 100644 --- a/packages/web3-eth-contract/test/integration/contract_defaults.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_defaults.test.ts @@ -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', () => { @@ -43,6 +47,10 @@ describe('contract', () => { sendOptions = { from: acc.address, gas: '1000000' }; }); + afterEach(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 @@ -63,23 +71,27 @@ describe('contract', () => { }); it('should set syncWithContext from init options', async () => { - contract = new Contract(GreeterAbi, { + const testContract = new Contract(GreeterAbi, { provider: getSystemTestProvider(), syncWithContext: true, }); - contract = await contract.deploy(deployOptions).send(sendOptions); + const deployedContract = await testContract.deploy(deployOptions).send(sendOptions); - expect(contract.syncWithContext).toBeTruthy(); + expect(deployedContract.syncWithContext).toBeTruthy(); + + await closeOpenConnection(testContract); }); - it('should subscribe to provided context upon instantiation', () => { + it('should subscribe to provided context upon instantiation', async () => { const web3Context = new Web3Context('http://127.0.0.1:8545'); const _contract = new Contract([], { syncWithContext: true }, web3Context); expect(_contract.defaultBlock).toBe('latest'); web3Context.defaultBlock = 'earliest'; expect(_contract.defaultBlock).toBe('earliest'); + + await closeOpenConnection(_contract); }); describe('defaultBlock', () => { diff --git a/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts b/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts index 206b10ee709..ce4f126a539 100644 --- a/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_defaults_extra.test.ts @@ -48,7 +48,11 @@ describe('contract defaults (extra)', () => { let sendOptions: Record; let acc: { address: string; privateKey: string }; - beforeEach(async () => { + beforeAll(async () => { + contract = new Contract(GreeterAbi, undefined, { + provider: getSystemTestProvider(), + }); + acc = await createTempAccount(); deployOptions = { @@ -59,27 +63,23 @@ describe('contract defaults (extra)', () => { sendOptions = { from: acc.address, gas: '1000000' }; }); - afterEach(async () => { + afterAll(async () => { await closeOpenConnection(contract); }); it('should use "defaultHardfork" on "instance" level', async () => { const hardfork = 'berlin'; - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); - - contract = await contract.deploy(deployOptions).send(sendOptions); - contract.defaultHardfork = hardfork; + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); + deployedContract.defaultHardfork = hardfork; - await contract.methods.setGreeting('New Greeting').send(sendOptions); - await contract.methods.greet().send(sendOptions); + await deployedContract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods.greet().send(sendOptions); - expect(contract.defaultHardfork).toBe(hardfork); + expect(deployedContract.defaultHardfork).toBe(hardfork); const callSpy = jest.spyOn(Web3Eth, 'call'); - await contract.methods.greet().call(); + await deployedContract.methods.greet().call(); expect(callSpy).toHaveBeenLastCalledWith( expect.objectContaining({ @@ -93,24 +93,20 @@ describe('contract defaults (extra)', () => { describe('defaultChain', () => { it('should use "defaultChain" on "instance" level', async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); - contract = await contract.deploy(deployOptions).send(sendOptions); - - expect(contract.defaultChain).toBe('mainnet'); + expect(deployedContract.defaultChain).toBe('mainnet'); const defaultChain = 'ropsten'; - contract.defaultChain = defaultChain; + deployedContract.defaultChain = defaultChain; - expect(contract.defaultChain).toBe(defaultChain); + expect(deployedContract.defaultChain).toBe(defaultChain); - await contract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods.setGreeting('New Greeting').send(sendOptions); const callSpy = jest.spyOn(Web3Eth, 'call'); - await contract.methods.greet().call(); + await deployedContract.methods.greet().call(); expect(callSpy).toHaveBeenCalledWith( expect.objectContaining({ @@ -131,27 +127,12 @@ describe('contract defaults (extra)', () => { hardfork: 'london' as Hardfork, }; - beforeEach(async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); - acc = await createTempAccount(); - - deployOptions = { - data: GreeterBytecode, - arguments: ['My Greeting'], - }; - - sendOptions = { from: acc.address, gas: '1000000' }; - - contract = await contract.deploy(deployOptions).send(sendOptions); - }); - it('should use "defaultCommon" on "instance" level', async () => { - contract.defaultCommon = common; + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); + deployedContract.defaultCommon = common; const callSpy = jest.spyOn(Web3Eth, 'call'); - await contract.methods.greet().call(); + await deployedContract.methods.greet().call(); expect(callSpy).toHaveBeenCalledWith( expect.objectContaining({ @@ -166,19 +147,16 @@ describe('contract defaults (extra)', () => { describeIf(isWs)('transactionBlockTimeout', () => { it('should use "transactionBlockTimeout" on "instance" level', async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); - contract = await contract.deploy(deployOptions).send(sendOptions); + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); const sendTransactionSpy = jest.spyOn(Web3Eth, 'sendTransaction'); - expect(contract.transactionBlockTimeout).toBe(50); + expect(deployedContract.transactionBlockTimeout).toBe(50); - contract.transactionBlockTimeout = 32; - expect(contract.transactionBlockTimeout).toBe(32); + deployedContract.transactionBlockTimeout = 32; + expect(deployedContract.transactionBlockTimeout).toBe(32); // eslint-disable-next-line @typescript-eslint/no-unsafe-call - await contract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods.setGreeting('New Greeting').send(sendOptions); expect(sendTransactionSpy).toHaveBeenLastCalledWith( expect.objectContaining({ @@ -191,38 +169,41 @@ describe('contract defaults (extra)', () => { }); it('should fail if transaction was not mined within `transactionBlockTimeout` blocks', async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); - contract = await contract.deploy(deployOptions).send(sendOptions); + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); // Make the test run faster by casing the polling to start after 2 blocks - contract.transactionBlockTimeout = 1; + deployedContract.transactionBlockTimeout = 1; // Prevent transaction from stucking for a long time if the provider (like Ganache v7.4.0) // does not respond, when raising the nonce - contract.transactionSendTimeout = MAX_32_SIGNED_INTEGER; + deployedContract.transactionSendTimeout = MAX_32_SIGNED_INTEGER; // Increase other timeouts - contract.transactionPollingTimeout = MAX_32_SIGNED_INTEGER; + deployedContract.transactionPollingTimeout = MAX_32_SIGNED_INTEGER; // Setting a high `nonce` when sending a transaction, to cause the RPC call to stuck at the Node // The previous test has the nonce set to Number.MAX_SAFE_INTEGER. // So, just decrease 1 from it here to not fall into another error. - const sentTx = contract.methods.setGreeting('New Greeting with high nonce').send({ - ...sendOptions, - nonce: (Number.MAX_SAFE_INTEGER - 1).toString(), - }); + const sentTx = deployedContract.methods + .setGreeting('New Greeting with high nonce') + .send({ + ...sendOptions, + nonce: (Number.MAX_SAFE_INTEGER - 1).toString(), + }); // Some providers (mostly used for development) will make blocks only when there are new transactions // So, send 2 transactions because in this test `transactionBlockTimeout = 2`. And do nothing if an error happens. setTimeout(() => { (async () => { try { - await contract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods + .setGreeting('New Greeting') + .send(sendOptions); } catch (error) { // Nothing needed to be done. } try { - await contract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods + .setGreeting('New Greeting') + .send(sendOptions); } catch (error) { // Nothing needed to be done. } @@ -237,20 +218,16 @@ describe('contract defaults (extra)', () => { describeIf(isWs)('blockHeaderTimeout', () => { it('should use "blockHeaderTimeout" on "instance" level', async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); - contract = await contract.deploy(deployOptions).send(sendOptions); - - expect(contract.blockHeaderTimeout).toBe(10); + expect(deployedContract.blockHeaderTimeout).toBe(10); const blockHeaderTimeout = 1; - contract.blockHeaderTimeout = blockHeaderTimeout; + deployedContract.blockHeaderTimeout = blockHeaderTimeout; - expect(contract.blockHeaderTimeout).toBe(blockHeaderTimeout); + expect(deployedContract.blockHeaderTimeout).toBe(blockHeaderTimeout); - const sentTx = contract.methods.setGreeting('New Greeting').send(sendOptions); + const sentTx = deployedContract.methods.setGreeting('New Greeting').send(sendOptions); const confirmationPromise = new Promise((resolve: Resolve) => { // Tx promise is handled separately @@ -262,7 +239,9 @@ describe('contract defaults (extra)', () => { resolve(); } else { // Send a transaction to cause dev providers creating new blocks to fire the 'confirmation' event again. - await contract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods + .setGreeting('New Greeting') + .send(sendOptions); } }, ); @@ -284,36 +263,28 @@ describe('contract defaults (extra)', () => { describeIf(isHttp)('transactionPollingInterval', () => { it('should use "transactionPollingTimeout" on "instance" level', async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); - - contract = await contract.deploy(deployOptions).send(sendOptions); + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); const transactionPollingInterval = 500; - contract.transactionPollingInterval = transactionPollingInterval; + deployedContract.transactionPollingInterval = transactionPollingInterval; - expect(contract.transactionPollingInterval).toBe(transactionPollingInterval); + expect(deployedContract.transactionPollingInterval).toBe(transactionPollingInterval); }); }); it('should use "handleRevert" on "instance" level', async () => { - contract = new Contract(GreeterAbi, undefined, { - provider: getSystemTestProvider(), - }); - - contract = await contract.deploy(deployOptions).send(sendOptions); + const deployedContract = await contract.deploy(deployOptions).send(sendOptions); - expect(contract.handleRevert).toBeFalsy(); + expect(deployedContract.handleRevert).toBeFalsy(); const handleRevert = true; - contract.handleRevert = handleRevert; + deployedContract.handleRevert = handleRevert; - expect(contract.handleRevert).toBe(handleRevert); + expect(deployedContract.handleRevert).toBe(handleRevert); const sendTransactionSpy = jest.spyOn(Web3Eth, 'sendTransaction'); - await contract.methods.setGreeting('New Greeting').send(sendOptions); + await deployedContract.methods.setGreeting('New Greeting').send(sendOptions); expect(sendTransactionSpy).toHaveBeenCalled(); }); diff --git a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts index b54ed63b41d..b81aa3c0621 100644 --- a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts @@ -51,6 +51,11 @@ describe('contract', () => { arguments: ['My Greeting'], }; }); + + afterAll(async () => { + await closeOpenConnection(web3Eth); + }); + beforeEach(async () => { acc = await createTempAccount(); contract = new Contract(GreeterAbi, undefined, { @@ -59,6 +64,10 @@ describe('contract', () => { sendOptions = { from: acc.address, gas: '1000000' }; }); + afterEach(async () => { + await closeOpenConnection(contract); + }); + it('should get correct contract address before deploymet using CREATE', async () => { const nonce = await web3Eth.getTransactionCount(sendOptions.from as string); @@ -71,9 +80,6 @@ describe('contract', () => { expect(deployedContract.options.address).toEqual(address); }); - afterAll(async () => { - await closeOpenConnection(web3Eth); - }); describe('local account', () => { it.each([signTxAndSendEIP1559, signTxAndSendEIP2930])( 'should deploy the contract %p', @@ -112,9 +118,11 @@ describe('contract', () => { ); it('should return estimated gas of contract constructor %p', async () => { - const estimatedGas = await new Contract(GreeterAbi, undefined, { + const testContract = new Contract(GreeterAbi, undefined, { provider: getSystemTestProvider(), - }) + }); + + const estimatedGas = await testContract .deploy({ data: GreeterBytecode, arguments: ['My Greeting'], @@ -123,21 +131,27 @@ describe('contract', () => { from: acc.address, gas: '1000000', }); + expect(typeof estimatedGas).toBe('bigint'); expect(Number(estimatedGas)).toBeGreaterThan(0); + + await closeOpenConnection(testContract); }); + it.each(Object.values(FMT_NUMBER))( 'should return estimated gas of contract constructor %p with correct type', async format => { const returnFormat = { number: format as FMT_NUMBER, bytes: FMT_BYTES.HEX }; - const estimatedGas = await new Contract( + const testContract = new Contract( GreeterAbi, { provider: getSystemTestProvider(), }, returnFormat, - ) + ); + + const estimatedGas = await testContract .deploy({ data: GreeterBytecode, arguments: ['My Greeting'], @@ -146,14 +160,20 @@ describe('contract', () => { from: acc.address, gas: '1000000', }); + expect(typeof estimatedGas).toBe(mapFormatToType[format as string]); expect(Number(estimatedGas)).toBeGreaterThan(0); + + await closeOpenConnection(testContract); }, ); + it('should return estimated gas of contract constructor without arguments', async () => { - const estimatedGas = await new Contract(ERC721TokenAbi, undefined, { + const testContract = new Contract(ERC721TokenAbi, undefined, { provider: getSystemTestProvider(), - }) + }); + + const estimatedGas = await testContract .deploy({ data: ERC721TokenBytecode, arguments: [], @@ -162,8 +182,12 @@ describe('contract', () => { from: acc.address, gas: '10000000', }); + expect(Number(estimatedGas)).toBeGreaterThan(0); + + await closeOpenConnection(testContract); }); + it('should return estimated gas of contract method', async () => { const contractDeployed = await contract.deploy(deployOptions).send(sendOptions); @@ -173,8 +197,10 @@ describe('contract', () => { gas: '1000000', from: acc.address, }); + expect(Number(estimatedGas)).toBeGreaterThan(0); }); + it('should return estimated gas of contract method without arguments', async () => { const contractDeployed = await contract.deploy(deployOptions).send(sendOptions); @@ -193,15 +219,19 @@ describe('contract', () => { }); it('should deploy the contract if data is provided at initiation', async () => { - contract = new Contract(GreeterAbi, { + const testContract = new Contract(GreeterAbi, { provider: getSystemTestProvider(), data: GreeterBytecode, from: acc.address, gas: '1000000', }); - const deployedContract = await contract.deploy({ arguments: ['Hello World'] }).send(); + const deployedContract = await testContract + .deploy({ arguments: ['Hello World'] }) + .send(); expect(deployedContract).toBeDefined(); + + await closeOpenConnection(testContract); }); it('should return instance of the contract', async () => { @@ -345,6 +375,8 @@ describe('contract', () => { 'Error happened while trying to execute a function inside a smart contract', ); } + + await closeOpenConnection(revert); }); }); }); diff --git a/packages/web3-eth-contract/test/integration/contract_empty_string.test.ts b/packages/web3-eth-contract/test/integration/contract_empty_string.test.ts index 25540c2ebf4..332801421be 100644 --- a/packages/web3-eth-contract/test/integration/contract_empty_string.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_empty_string.test.ts @@ -16,13 +16,18 @@ along with web3.js. If not, see . */ 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; let deployOptions: Record; let sendOptions: Record; + beforeAll(async () => { contract = new Contract(MyContractAbi, undefined, { provider: getSystemTestProvider(), @@ -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); diff --git a/packages/web3-eth-contract/test/integration/contract_erc20.test.ts b/packages/web3-eth-contract/test/integration/contract_erc20.test.ts index 890163239b5..5dea78f2c50 100644 --- a/packages/web3-eth-contract/test/integration/contract_erc20.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_erc20.test.ts @@ -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'); diff --git a/packages/web3-eth-contract/test/integration/contract_erc721.test.ts b/packages/web3-eth-contract/test/integration/contract_erc721.test.ts index 14e3d9fa859..f98bc8e8877 100644 --- a/packages/web3-eth-contract/test/integration/contract_erc721.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_erc721.test.ts @@ -54,7 +54,6 @@ describe('contract', () => { afterAll(async () => { await closeOpenConnection(contract); - await closeOpenConnection(contractDeployed); }); it('should deploy the contract', async () => { @@ -65,11 +64,13 @@ describe('contract', () => { let acc: { address: string; privateKey: string }; let acc2: { address: string; privateKey: string }; let pkAccount: { address: string; privateKey: string }; + beforeAll(async () => { acc = await createTempAccount(); pkAccount = await createNewAccount(); await refillAccount(acc.address, pkAccount.address, '20000000000000000'); }); + beforeEach(async () => { acc2 = await createTempAccount(); sendOptions = { from: acc.address, gas: '10000000' }; diff --git a/packages/web3-eth-contract/test/integration/contract_estimateGas_without_0x.test.ts b/packages/web3-eth-contract/test/integration/contract_estimateGas_without_0x.test.ts index d74a901e265..7212060bac5 100644 --- a/packages/web3-eth-contract/test/integration/contract_estimateGas_without_0x.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_estimateGas_without_0x.test.ts @@ -17,7 +17,11 @@ along with web3.js. If not, see . import { ETH_DATA_FORMAT } from 'web3-types'; import { Contract } from '../../src'; -import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils'; +import { + getSystemTestProvider, + createTempAccount, + closeOpenConnection, +} from '../fixtures/system_test_utils'; describe('contract', () => { // Create a new contract object using the ABI and bytecode @@ -49,6 +53,10 @@ describe('contract', () => { acc = await createTempAccount(); }); + afterAll(async () => { + await closeOpenConnection(contract); + }); + it('should be able to add `data` input without `0x` prefix', async () => { contract = new Contract(abi, undefined, { provider: getSystemTestProvider(), diff --git a/packages/web3-eth-contract/test/integration/contract_events.test.ts b/packages/web3-eth-contract/test/integration/contract_events.test.ts index 3f7d78db643..1bf3340d4a1 100644 --- a/packages/web3-eth-contract/test/integration/contract_events.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_events.test.ts @@ -43,7 +43,6 @@ describe('contract', () => { afterAll(async () => { await closeOpenConnection(contract); - await closeOpenConnection(contractDeployed); }); beforeEach(async () => { diff --git a/packages/web3-eth-contract/test/integration/contract_filter_events.test.ts b/packages/web3-eth-contract/test/integration/contract_filter_events.test.ts index 338cd448c12..000a305eb72 100644 --- a/packages/web3-eth-contract/test/integration/contract_filter_events.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_filter_events.test.ts @@ -24,6 +24,7 @@ import { getSystemTestProvider, createTempAccount, createNewAccount, + closeOpenConnection, } from '../fixtures/system_test_utils'; const initialSupply = BigInt('5000000000'); @@ -60,6 +61,10 @@ describe('contract getPastEvent filter', () => { await contractDeployed.methods.transfer(toAcc3.address, value).send(sendOptions); }); + afterAll(async () => { + await closeOpenConnection(contract); + }); + it('should filter one event by address with event name and filter param', async () => { const res: EventLog[] = (await contractDeployed.getPastEvents('Transfer', { fromBlock: 'earliest', @@ -155,6 +160,7 @@ describe('contract getPastEvent filter', () => { ); }); }); + describe('basic', () => { let contract: Contract; let contractDeployed: Contract; @@ -188,6 +194,10 @@ describe('contract getPastEvent filter', () => { .send(sendOptions); }); + afterAll(async () => { + await closeOpenConnection(contract); + }); + it('should filter one event by address with event name and filter param', async () => { const res: EventLog[] = (await contractDeployed.getPastEvents( 'MultiValueIndexedEvent', diff --git a/packages/web3-eth-contract/test/integration/contract_methods.test.ts b/packages/web3-eth-contract/test/integration/contract_methods.test.ts index 152c3feec8a..7048fe121d6 100644 --- a/packages/web3-eth-contract/test/integration/contract_methods.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_methods.test.ts @@ -22,6 +22,7 @@ import { createTempAccount, getSystemTestBackend, BACKEND, + closeOpenConnection, } from '../fixtures/system_test_utils'; describe('contract', () => { @@ -47,6 +48,10 @@ describe('contract', () => { contractDeployed = await contract.deploy(deployOptions).send(sendOptions); }); + afterAll(async () => { + await closeOpenConnection(contract); + }); + describe('methods', () => { describe('call', () => { it('should retrieve the values', async () => { @@ -72,6 +77,8 @@ describe('contract', () => { .send(); const res = await deployedTempContract.methods.getStringValue().call(); expect(res).toBe('string init value'); + + await closeOpenConnection(tempContract); }); describe('revert handling', () => { @@ -191,6 +198,8 @@ describe('contract', () => { await deployedTempContract.methods.setValues(10, 'TEST', true).send(); expect(await deployedTempContract.methods.getStringValue().call()).toBe('TEST'); + + await closeOpenConnection(tempContract); }); it('should returns errors on reverts', async () => { diff --git a/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts b/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts index bf9283d5a4f..8a18156657b 100644 --- a/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts @@ -15,7 +15,11 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ import Contract from '../../src'; -import { createTempAccount, getSystemTestProvider } from '../fixtures/system_test_utils'; +import { + closeOpenConnection, + createTempAccount, + getSystemTestProvider, +} from '../fixtures/system_test_utils'; import { NegativeNumbersAbi, NegativeNumbersBytecode, @@ -47,6 +51,10 @@ describe('Contract - NegativeNumbers.sol', () => { contractDeployed = await contract.deploy(deployOptions).send(sendOptions); }); + afterAll(async () => { + await closeOpenConnection(contract); + }); + it('should retrieve storedNegativeNumber', async () => { const response = await contractDeployed.methods.storedNegativeNumber().call(); expect(response).toBe(BigInt(storedNegativeNumber)); diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts index 821101ca225..cb24ad22fca 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts @@ -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', () => { @@ -31,13 +35,20 @@ describe('contract', () => { let localAccount: Web3Account; let web3: Web3; - beforeEach(async () => { + beforeAll(async () => { web3 = new Web3(getSystemTestProvider()); contract = new web3.eth.Contract(GreeterAbi) as unknown as Contract; deployOptions = { data: GreeterBytecode, arguments: ['My Greeting'], }; + }); + + afterAll(async () => { + await closeOpenConnection(web3); + }); + + beforeEach(async () => { localAccount = await createLocalAccount(web3); sendOptions = { from: localAccount.address, diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_erc20.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_erc20.test.ts index edff03fe598..35ebc29cc46 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_erc20.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_erc20.test.ts @@ -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'); @@ -53,6 +57,10 @@ describe('contract', () => { contractDeployed = await contract.deploy(deployOptions).send(sendOptions); }); + afterAll(async () => { + await closeOpenConnection(web3); + }); + it('should deploy the contract', () => { expect(contractDeployed.options.address).toBeDefined(); }); diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_erc721.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_erc721.test.ts index d9226c580f1..0d3914db9cb 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_erc721.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_erc721.test.ts @@ -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', () => { @@ -32,6 +36,7 @@ describe('contract', () => { let localAccount: Web3Account; let web3: Web3; let contractDeployed: Contract; + beforeAll(async () => { web3 = new Web3(getSystemTestProvider()); localAccount = await createLocalAccount(web3); @@ -53,6 +58,10 @@ describe('contract', () => { .send({ ...sendOptions, gas: '3000000' }); }); + afterAll(async () => { + await closeOpenConnection(web3); + }); + it('should deploy the contract', () => { expect(contractDeployed.options.address).toBeDefined(); }); diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_overloaded_methods.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_overloaded_methods.test.ts index 96985cda3a7..dcc1a03d20a 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_overloaded_methods.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_overloaded_methods.test.ts @@ -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', () => { @@ -55,6 +59,10 @@ describe('contract ERC721 overloaded functions', () => { .send({ ...sendOptions, gas: '3000000' }); }); + afterAll(async () => { + await closeOpenConnection(web3); + }); + it('transferFrom with 4 arguments', async () => { const tempAccount = await createLocalAccount(web3); const toAccount = await createLocalAccount(web3);