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 95f4f29
Show file tree
Hide file tree
Showing 20 changed files with 422 additions and 323 deletions.
387 changes: 194 additions & 193 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -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/*"]
}
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,16 +23,18 @@ import {
describeIf,
getSystemTestBackend,
BACKEND,
closeOpenConnection,
} from '../fixtures/system_test_utils';

describe('contract', () => {
describeIf(getSystemTestBackend() === BACKEND.GETH)('createAccessList', () => {
let contract: Contract<typeof GreeterAbi>;
let deployedContract: Contract<typeof GreeterAbi>;
let deployOptions: Record<string, unknown>;
let sendOptions: Record<string, unknown>;
let acc: { address: string; privateKey: string };

beforeEach(async () => {
beforeAll(async () => {
contract = new Contract(GreeterAbi, undefined, {
provider: getSystemTestProvider(),
});
Expand All @@ -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' });
Expand All @@ -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' });
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' };
});

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
Expand All @@ -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', () => {
Expand Down
Loading

0 comments on commit 95f4f29

Please sign in to comment.