Skip to content

Commit

Permalink
fix: typescript error
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Petrunic <[email protected]>
  • Loading branch information
mpetrunic committed Oct 27, 2023
1 parent a754771 commit f9f946f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,33 @@ describe('contract', () => {
});

it('should emit the "confirmation" event', async () => {
let confirmationHandler: jest.Mock;
const confirmationPromise = new Promise<void>((resolve) => {
confirmationHandler = jest.fn(() => {
resolve();
})
})
await new Promise<void>((resolve, reject) => {
contract
const confirmationHandler = jest.fn();
const promievent = contract
.deploy(deployOptions)
.send(sendOptions)
.on('receipt', () => {
resolve()
})
.on('confirmation', confirmationHandler)
.catch(reject)
.send(sendOptions);
const receiptPromise = new Promise<void>((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
promievent
.on('receipt', () => {
resolve()
})
})

const confirmationPRomise = new Promise<void>((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
promievent
.on('confirmation', () => {confirmationHandler(); resolve();})
})
await promievent;
await receiptPromise;

// Deploy once again to trigger block mining to trigger confirmation
// We can send any other transaction as well
await contract.deploy(deployOptions).send(sendOptions);
await confirmationPromise


await confirmationPRomise;
// eslint-disable-next-line jest/no-standalone-expect
expect(confirmationHandler!).toHaveBeenCalled();
expect(confirmationHandler).toHaveBeenCalled();
});

it('should emit the "transactionHash" event', async () => {
Expand Down
43 changes: 12 additions & 31 deletions packages/web3/test/integration/web3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import HttpProvider from 'web3-providers-http';
import { IpcProvider } from 'web3-providers-ipc';
import WebSocketProvider from 'web3-providers-ws';
import { JsonRpcOptionalRequest, SupportedProviders, Web3BaseProvider } from 'web3-types';
import Web3 from '../../src/index';
import {Web3} from '../../src/index';
import { BasicAbi } from '../shared_fixtures/Basic';
import { GreeterAbi, GreeterBytecode } from '../shared_fixtures/build/Greeter';
import { GreeterAbi } from '../shared_fixtures/build/Greeter';
import { validEncodeParametersData } from '../shared_fixtures/data';
import {
closeOpenConnection,
Expand All @@ -35,7 +35,7 @@ import {
isSocket,
isWs,
itIf,
waitForOpenConnection,
waitForOpenConnection
} from '../shared_fixtures/system_tests_utils';

/* eslint-disable jest/no-standalone-expect */
Expand All @@ -55,7 +55,11 @@ describe('Web3 instance', () => {
accounts = [acc1.address, acc2.address];
});
afterAll(async () => {
await closeOpenConnection(web3);
try {
await closeOpenConnection(web3);
} catch(e) {
console.warn("Failed to close open con", e)
}
});

beforeEach(() => {
Expand Down Expand Up @@ -303,25 +307,14 @@ describe('Web3 instance', () => {

describe('defaults', () => {
let contract: Contract<typeof GreeterAbi>;
let deployOptions: Record<string, unknown>;
let sendOptions: Record<string, unknown>;
let acc: { address: string; privateKey: string };

beforeAll(() => {
web3 = new Web3(provider);
});

beforeEach(async () => {
acc = await createTempAccount();

// todo import GreeterBytecode
deployOptions = {
data: GreeterBytecode,
arguments: ['My Greeting'],
};

sendOptions = { from: acc.address, gas: '1000000' };
});
afterAll(() => {
web3.provider?.disconnect();
})

it('should update defaults on contract instance', () => {
const hardfork = 'berlin';
Expand All @@ -334,20 +327,8 @@ describe('Web3 instance', () => {
web3.defaultHardfork = hardfork;

expect(contract.defaultHardfork).toBe(hardfork);
contract.provider?.disconnect();
});

it('should update defaults on deployed contract instance', async () => {
const hardfork = 'berlin';

contract = new web3.eth.Contract(GreeterAbi, undefined, {
provider: getSystemTestProvider(),
syncWithContext: true,
});
contract = await contract.deploy(deployOptions).send(sendOptions);

web3.defaultHardfork = hardfork;

expect(contract.defaultHardfork).toBe(hardfork);
});
});
});

0 comments on commit f9f946f

Please sign in to comment.