Skip to content

Commit

Permalink
test: updated test
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
  • Loading branch information
quiet-node committed May 10, 2024
1 parent 6919a31 commit ed09fbc
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 90 deletions.
20 changes: 2 additions & 18 deletions packages/ws-server/tests/acceptance/blockNumber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import { WsTestConstant, WsTestHelper } from '../helper';

describe('@release @web-socket-batch-1 eth_blockNumber', async function () {
const METHOD_NAME = 'eth_blockNumber';
const INVALID_PARAMS = [
['hedera', 'hbar'],
['websocket', 'rpc', 'invalid'],
];

let ethersWsProvider: WebSocketProvider;

Expand All @@ -46,13 +42,7 @@ describe('@release @web-socket-batch-1 eth_blockNumber', async function () {
});

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_blockNumber on Standard Web Socket and handle valid requests correctly`, async () => {
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, []);
WsTestHelper.assertJsonRpcObject(response);
expect(Number(response.result)).to.gte(0);
Expand All @@ -61,13 +51,7 @@ describe('@release @web-socket-batch-1 eth_blockNumber', async function () {
});

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and handle valid requests correctly`, async () => {
it(`Should execute eth_blockNumber on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const response = await ethersWsProvider.send(METHOD_NAME, []);
expect(Number(response)).to.gte(0);
expect(response.startsWith('0x')).to.be.true;
Expand Down
14 changes: 7 additions & 7 deletions packages/ws-server/tests/acceptance/call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { expect } from 'chai';
import { ethers, WebSocketProvider } from 'ethers';
import { WsTestConstant, WsTestHelper } from '../helper';
import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils';
import ERC20MockJson from '@hashgraph/json-rpc-server/tests/contracts/ERC20Mock.json';
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount';
import ERC20MockJson from '@hashgraph/json-rpc-server/tests/contracts/ERC20Mock.json';

describe('@release @web-socket-batch-1 eth_call', async function () {
const METHOD_NAME = 'eth_call';
Expand Down Expand Up @@ -109,21 +109,21 @@ describe('@release @web-socket-batch-1 eth_call', async function () {

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_call on Standard Web Socket and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

for (const params of INVALID_TX_INFO) {
it(`Should fail ${METHOD_NAME} on ${
it(`Should fail eth_call on ${
WsTestConstant.STANDARD_WEB_SOCKET
} and handle invalid TX_INFO. params=[${JSON.stringify(params)}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

for (const data of VALID_DATA) {
it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_call on Standard Web Socket and handle valid requests correctly`, async () => {
const tx = {
to: erc20TokenAddr,
data: data.sighash,
Expand All @@ -143,13 +143,13 @@ describe('@release @web-socket-batch-1 eth_call', async function () {

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_call on Ethers Web Socket Provider and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

for (const params of INVALID_TX_INFO) {
it(`Should fail ${METHOD_NAME} on ${
it(`Should fail eth_call on ${
WsTestConstant.ETHERS_WS_PROVIDER
} and handle invalid TX_INFO. params=[${JSON.stringify(params)}]`, async () => {
try {
Expand All @@ -165,7 +165,7 @@ describe('@release @web-socket-batch-1 eth_call', async function () {
}

for (const data of VALID_DATA) {
it(`Should execute ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and handle valid requests correctly`, async () => {
it(`Should execute eth_call on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const tx = {
to: erc20TokenAddr,
data: data.sighash,
Expand Down
6 changes: 3 additions & 3 deletions packages/ws-server/tests/acceptance/estimateGas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

// external resources
import { expect } from 'chai';
import { Contract, ethers, WebSocketProvider } from 'ethers';
import { ethers, WebSocketProvider } from 'ethers';
import { WsTestConstant, WsTestHelper } from '../helper';
import basicContractJson from '@hashgraph/json-rpc-server/tests/contracts/Basic.json';
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount';
import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils';
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount';
import basicContractJson from '@hashgraph/json-rpc-server/tests/contracts/Basic.json';

describe('@release @web-socket-batch-1 eth_estimateGas', async function () {
const METHOD_NAME = 'eth_estimateGas';
Expand Down
20 changes: 2 additions & 18 deletions packages/ws-server/tests/acceptance/gasPrice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import { WsTestConstant, WsTestHelper } from '../helper';

describe('@release @web-socket-batch-1 eth_gasPrice', async function () {
const METHOD_NAME = 'eth_gasPrice';
const INVALID_PARAMS = [
['hedera', 'hbar'],
['websocket', 'rpc', 'invalid'],
];

let ethersWsProvider: WebSocketProvider;

Expand All @@ -46,13 +42,7 @@ describe('@release @web-socket-batch-1 eth_gasPrice', async function () {
});

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_gasPrice on Standard Web Socket and handle valid requests correctly`, async () => {
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, []);
WsTestHelper.assertJsonRpcObject(response);
const expectedResult = await global.relay.call(METHOD_NAME, []);
Expand All @@ -61,13 +51,7 @@ describe('@release @web-socket-batch-1 eth_gasPrice', async function () {
});

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

it('Should handle valid requests correctly', async () => {
it(`Should execute eth_gasPrice on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const result = await ethersWsProvider.send(METHOD_NAME, []);
const expectedResult = await global.relay.call(METHOD_NAME, []);
expect(result).to.eq(expectedResult);
Expand Down
8 changes: 4 additions & 4 deletions packages/ws-server/tests/acceptance/getBalance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ describe('@release @web-socket-batch-1 eth_getBalance', async function () {

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getBalance on Standard Web Socket and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_getBalance on Standard Web Socket and handle valid requests correctly`, async () => {
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, [accounts[0].address, 'latest']);
WsTestHelper.assertJsonRpcObject(response);

Expand All @@ -92,12 +92,12 @@ describe('@release @web-socket-batch-1 eth_getBalance', async function () {

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getBalance on Ethers Web Socket Provider and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and handle valid requests correctly`, async () => {
it(`Should execute eth_getBalance on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const expectedResult = await global.relay.call(METHOD_NAME, [accounts[0].address, 'latest']);
const result = await ethersWsProvider.send(METHOD_NAME, [accounts[0].address, 'latest']);
expect(result).to.eq(expectedResult);
Expand Down
8 changes: 4 additions & 4 deletions packages/ws-server/tests/acceptance/getBlockByHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ describe('@release @web-socket-batch-1 eth_getBlockByHash', async function () {

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getBlockByHash on Standard Web Socket and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_getBlockByHash on Standard Web Socket and handle valid requests correctly`, async () => {
const expectedResult = await global.relay.call('eth_getBlockByNumber', ['latest', true]);
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, [expectedResult.hash, true]);
WsTestHelper.assertJsonRpcObject(response);
Expand All @@ -68,12 +68,12 @@ describe('@release @web-socket-batch-1 eth_getBlockByHash', async function () {

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getBlockByHash on Ethers Web Socket Provider and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and handle valid requests correctly`, async () => {
it(`Should execute eth_getBlockByHash on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const expectedResult = await global.relay.call('eth_getBlockByNumber', ['latest', true]);
const result = await ethersWsProvider.send(METHOD_NAME, [expectedResult.hash, true]);
expect(result).to.deep.eq(expectedResult);
Expand Down
8 changes: 4 additions & 4 deletions packages/ws-server/tests/acceptance/getBlockByNumber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ describe('@release @web-socket-batch-1 eth_getBlockByNumber', async function ()

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getBlockByNumber on Standard Web Socket and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_getBlockByNumber on Standard Web Socket and handle valid requests correctly`, async () => {
const expectedResult = await global.relay.call(METHOD_NAME, ['latest', false]);
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, [expectedResult.number, true]);
WsTestHelper.assertJsonRpcObject(response);
Expand All @@ -68,12 +68,12 @@ describe('@release @web-socket-batch-1 eth_getBlockByNumber', async function ()

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getBlockByNumber on Ethers Web Socket Provider and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and handle valid requests correctly`, async () => {
it(`Should execute eth_getBlockByNumber on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const expectedResult = await global.relay.call(METHOD_NAME, ['latest', false]);
const result = await ethersWsProvider.send(METHOD_NAME, [expectedResult.number, true]);
expect(result).to.deep.eq(expectedResult);
Expand Down
6 changes: 2 additions & 4 deletions packages/ws-server/tests/acceptance/getCode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@

// external resources
import { expect } from 'chai';
import { ethers, WebSocketProvider } from 'ethers';
import { WsTestConstant, WsTestHelper } from '../helper';
import { ethers, JsonRpcProvider, WebSocketProvider } from 'ethers';
import basicContractJson from '@hashgraph/json-rpc-server/tests/contracts/Basic.json';
import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils';
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount';
import basicContractJson from '@hashgraph/json-rpc-server/tests/contracts/Basic.json';

describe('@release @web-socket-batch-2 eth_getCode', async function () {
const RELAY_URL = `${process.env.RELAY_ENDPOINT}`;
const METHOD_NAME = 'eth_getCode';

let basicContract: ethers.Contract,
basicContractAddress: string,
codeFromRPC: string,
provider: JsonRpcProvider,
ethersWsProvider: WebSocketProvider;

before(async () => {
Expand Down
17 changes: 10 additions & 7 deletions packages/ws-server/tests/acceptance/getLogs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
import { expect } from 'chai';
import { ethers, WebSocketProvider } from 'ethers';
import { WsTestConstant, WsTestHelper } from '../helper';
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount';
import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils';
import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount';

describe('@release @web-socket-batch-2 eth_getLogs', async function () {
const EXPECTED_VALUE = 7;
const METHOD_NAME = 'eth_getLogs';
const INVALID_PARAMS = [
[],
[{}, ''],
[{}, '0xhbar', false],
[
{
address: '0xhedera',
Expand Down Expand Up @@ -127,16 +125,19 @@ describe('@release @web-socket-batch-2 eth_getLogs', async function () {

describe(WsTestConstant.STANDARD_WEB_SOCKET, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getLogs on Standard Web Socket and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${JSON.stringify(
params,
)}]`, async () => {
await WsTestHelper.assertFailInvalidParamsStandardWebSocket(METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.STANDARD_WEB_SOCKET} and handle valid requests correctly`, async () => {
it(`Should execute eth_getLogs on Standard Web Socket and handle valid requests correctly`, async () => {
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, [wsFilterObj]);
WsTestHelper.assertJsonRpcObject(response);

const logs = response.result;

expect(logs[0].address.toLowerCase()).to.eq(wsFilterObj.address.toLowerCase());
expect(logs[0].logIndex).to.eq('0x0'); // the event has only one input
expect(parseInt(logs[0].data)).to.eq(EXPECTED_VALUE);
Expand All @@ -145,12 +146,14 @@ describe('@release @web-socket-batch-2 eth_getLogs', async function () {

describe(WsTestConstant.ETHERS_WS_PROVIDER, () => {
for (const params of INVALID_PARAMS) {
it(`Should fail ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${params}]`, async () => {
it(`Should fail eth_getLogs on Ethers Web Socket Provider and throw predefined.INVALID_PARAMETERS if the request's params variable is invalid. params=[${JSON.stringify(
params,
)}]`, async () => {
await WsTestHelper.assertFailInvalidParamsEthersWsProvider(ethersWsProvider, METHOD_NAME, params);
});
}

it(`Should execute ${METHOD_NAME} on ${WsTestConstant.ETHERS_WS_PROVIDER} and handle valid requests correctly`, async () => {
it(`Should execute eth_getLogs on Ethers Web Socket Provider and handle valid requests correctly`, async () => {
const logs = await ethersWsProvider.send(METHOD_NAME, [wsFilterObj]);

expect(logs[0].address.toLowerCase()).to.eq(wsFilterObj.address.toLowerCase());
Expand Down
Loading

0 comments on commit ed09fbc

Please sign in to comment.