Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added the web3_clientVersion to the websocket server. #2486

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/ws-server/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ const handleSendingRequestsToRelay = async ({

try {
const resolvedParams = resolveParams(method, params);
const txRes = await relay.eth()[method.split('_')[1]](...resolvedParams, requestIdPrefix);
const [service, methodName] = method.split('_');

// Call the relay method with the resolved parameters.
// Method will be validated by "verifySupportedMethod" before reaching this point.
const txRes = await relay[service]()[methodName](...resolvedParams, requestIdPrefix);
Nana-EC marked this conversation as resolved.
Show resolved Hide resolved

if (!txRes) {
logger.trace(
`${connectionIdPrefix} ${requestIdPrefix}: Fail to retrieve result for request=${JSON.stringify(
Expand Down
1 change: 1 addition & 0 deletions packages/ws-server/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ export const WS_CONSTANTS = {
ETH_GETTRANSACTIONBYHASH: 'eth_getTransactionByHash',
ETH_GETTRANSACTIONRECEIPT: 'eth_getTransactionReceipt',
ETH_MAXPRIORITYFEEPERGAS: 'eth_maxPriorityFeePerGas',
WEB3_CLIENTVERSION: 'web3_clientVersion',
},
};
45 changes: 45 additions & 0 deletions packages/ws-server/tests/acceptance/web3ClientVersion.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// external resources
import { expect } from 'chai';
import { WsTestHelper } from '../helper';
import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils';

describe('@web-socket-batch-2 web3_clientVersion', async function () {
const METHOD_NAME = 'web3_clientVersion';

let requestId: string;

// @ts-ignore
const { relay } = global;

before(async () => {
requestId = Utils.generateRequestId();
});

it(`Should execute web3_clientVersion on Standard Web Socket and handle valid requests correctly`, async () => {
const response = await WsTestHelper.sendRequestToStandardWebSocket(METHOD_NAME, []);
expect(response.result).to.exist;
expect(response.result).to.be.a('string');
quiet-node marked this conversation as resolved.
Show resolved Hide resolved
const clientVersion = await relay.call('web3_clientVersion', [], requestId);
expect(response.result).to.equal(clientVersion);
});
});
Loading