Skip to content

Commit c588248

Browse files
AlfredoG87ebadierequiet-node
authored
chore: Cherry pick 0 46 2332 (#2347)
feat: Updated to deploy the contract using a websocket provider. (#2332) * feat: Updated to deploy the contract using a websocket provider. * Update packages/ws-server/tests/acceptance/estimateGas.spec.ts * Update packages/ws-server/tests/acceptance/estimateGas.spec.ts * feat: Merged and fixed to deploy using WebSocketProvider. * fix: Removed .only * fix: Updated to wait for account to be propagated to the mirror node. --------- Signed-off-by: ebadiere <[email protected]> Signed-off-by: Eric Badiere <[email protected]> Signed-off-by: Alfredo Gutierrez <[email protected]> Co-authored-by: Eric Badiere <[email protected]> Co-authored-by: Logan Nguyen <[email protected]>
1 parent 02cd9e6 commit c588248

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

packages/ws-server/tests/acceptance/estimateGas.spec.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
// external resources
2222
import { expect } from 'chai';
23-
import { ethers, WebSocketProvider } from 'ethers';
24-
import { TransactionReceipt } from '@hashgraph/sdk';
23+
import { Contract, ethers, WebSocketProvider } from 'ethers';
24+
// import { TransactionReceipt } from '@hashgraph/sdk';
2525
import { WsTestConstant, WsTestHelper } from '../helper';
2626
import basicContractJson from '@hashgraph/json-rpc-server/tests/contracts/Basic.json';
2727
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/clients/servicesClient';
@@ -32,15 +32,22 @@ describe('@release @web-socket eth_estimateGas', async function () {
3232
const BASIC_CONTRACT_PING_CALL_DATA = '0x5c36b186';
3333

3434
let accounts: AliasAccount[] = [],
35-
basicContract: TransactionReceipt,
35+
basicContract: Contract,
3636
currentPrice: number,
3737
expectedGas: number,
3838
gasPriceDeviation: number,
39-
ethersWsProvider: WebSocketProvider;
39+
ethersWsProvider: WebSocketProvider,
40+
requestId = 'eth_estimateGas';
4041

4142
before(async () => {
4243
accounts[0] = await global.servicesNode.createAliasAccount(100, global.relay.provider);
43-
basicContract = await global.servicesNode.deployContract(basicContractJson);
44+
let result;
45+
let mirrorAccount = await global.mirrorNode.get(`accounts?account.id=${accounts[0].accountId}`, requestId);
46+
// Wait for the account to propagate the mirror node
47+
while (mirrorAccount.accounts.length === 0) {
48+
mirrorAccount = await global.mirrorNode.get(`accounts?account.id=${accounts[0].accountId}`, requestId);
49+
await new Promise((resolve) => setTimeout(resolve, 2000));
50+
}
4451

4552
currentPrice = await global.relay.gasPrice();
4653
expectedGas = parseInt(PING_CALL_ESTIMATED_GAS, 16);
@@ -51,6 +58,15 @@ describe('@release @web-socket eth_estimateGas', async function () {
5158

5259
beforeEach(async () => {
5360
ethersWsProvider = new ethers.WebSocketProvider(WsTestConstant.WS_RELAY_URL);
61+
const wallet = new ethers.Wallet(accounts[0].wallet.privateKey, ethersWsProvider);
62+
const basicContractFactory = await new ethers.ContractFactory(
63+
basicContractJson.abi,
64+
basicContractJson.bytecode,
65+
wallet,
66+
);
67+
68+
basicContract = (await basicContractFactory.deploy()) as Contract;
69+
await basicContract.waitForDeployment();
5470
});
5571

5672
afterEach(async () => {
@@ -64,7 +80,7 @@ describe('@release @web-socket eth_estimateGas', async function () {
6480

6581
it('@release should execute "eth_estimateGas" for contract call, using a websocket provider', async function () {
6682
const estimatedGas = await ethersWsProvider.estimateGas({
67-
to: `0x${basicContract.contractId?.toSolidityAddress()}`,
83+
to: basicContract.target,
6884
data: BASIC_CONTRACT_PING_CALL_DATA,
6985
});
7086

@@ -74,7 +90,7 @@ describe('@release @web-socket eth_estimateGas', async function () {
7490
});
7591

7692
it('should return the code through a websocket', async () => {
77-
const tx = { to: `0x${basicContract.contractId?.toSolidityAddress()}`, data: BASIC_CONTRACT_PING_CALL_DATA };
93+
const tx = { to: basicContract.target, data: BASIC_CONTRACT_PING_CALL_DATA };
7894
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, [tx]);
7995
WsTestHelper.assertJsonRpcObject(response);
8096
expect(Number(response.result)).to.be.lessThan(currentPrice * (1 + gasPriceDeviation));

0 commit comments

Comments
 (0)