Skip to content

Commit 6b8014b

Browse files
committed
fix: fixed unit tests in servers
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
1 parent f88adc2 commit 6b8014b

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

packages/relay/src/lib/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class DebugImpl implements Debug {
148148
0: { type: ParamType.BLOCK_NUMBER, required: true },
149149
1: { type: ParamType.TRACER_CONFIG_WRAPPER, required: false },
150150
})
151-
@rpcParamLayoutConfig(RPC_LAYOUT.custom((params) => [Number(params[0]), params[1]]))
151+
@rpcParamLayoutConfig(RPC_LAYOUT.custom((params) => [params[0], params[1]]))
152152
async traceBlockByNumber(
153153
blockNumber: string,
154154
tracerObject: IBlockTracerConfig,

packages/relay/tests/lib/debug.spec.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import { EvmAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositor
1818
import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository';
1919
import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository';
2020
import { DebugImpl } from '../../src/lib/debug';
21+
import { CommonService } from '../../src/lib/services';
2122
import { CacheService } from '../../src/lib/services/cacheService/cacheService';
2223
import HAPIService from '../../src/lib/services/hapiService/hapiService';
2324
import { HbarLimitService } from '../../src/lib/services/hbarLimitService';
2425
import { RequestDetails } from '../../src/lib/types';
2526
import RelayAssertions from '../assertions';
2627
import { getQueryParams, withOverriddenEnvsInMochaTest } from '../helpers';
27-
import { CommonService } from '../../src/lib/services';
2828
chai.use(chaiAsPromised);
2929

3030
const logger = pino({ level: 'silent' });
@@ -622,8 +622,7 @@ describe('Debug API Test Suite', async function () {
622622
});
623623

624624
withOverriddenEnvsInMochaTest({ DEBUG_API_ENABLED: true }, () => {
625-
it('should return empty array if block is not found', async function () {
626-
// Stub CommonService.getHistoricalBlockResponse
625+
it('should throw RESOURCE_NOT_FOUND if block is not found', async function () {
627626
const getHistoricalBlockResponseStub = sinon.stub().resolves(null);
628627
sinon.stub(CommonService.prototype, 'getHistoricalBlockResponse').callsFake(getHistoricalBlockResponseStub);
629628

@@ -641,11 +640,9 @@ describe('Debug API Test Suite', async function () {
641640
});
642641

643642
it('should return empty array if no contract results are found for the block', async function () {
644-
// Stub CommonService.getHistoricalBlockResponse
645643
const getHistoricalBlockResponseStub = sinon.stub().resolves(blockResponse);
646644
sinon.stub(CommonService.prototype, 'getHistoricalBlockResponse').callsFake(getHistoricalBlockResponseStub);
647645

648-
// Stub MirrorNodeClient.getContractResultWithRetry
649646
sinon.stub(mirrorNodeInstance, 'getContractResultWithRetry').resolves([]);
650647

651648
const result = await debugService.traceBlockByNumber(
@@ -660,11 +657,9 @@ describe('Debug API Test Suite', async function () {
660657
it('should return cached result if available', async function () {
661658
const cachedResult = [{ txHash: '0xabc123', result: callTracerResult1 }];
662659

663-
// Stub CommonService.getHistoricalBlockResponse
664660
const getHistoricalBlockResponseStub = sinon.stub().resolves(blockResponse);
665661
sinon.stub(CommonService.prototype, 'getHistoricalBlockResponse').callsFake(getHistoricalBlockResponseStub);
666662

667-
// Stub CacheService.getAsync
668663
sinon.stub(cacheService, 'getAsync').resolves(cachedResult);
669664

670665
const result = await debugService.traceBlockByNumber(
@@ -678,11 +673,9 @@ describe('Debug API Test Suite', async function () {
678673

679674
describe('with CallTracer', async function () {
680675
beforeEach(() => {
681-
// Stub CommonService.getHistoricalBlockResponse
682676
const getHistoricalBlockResponseStub = sinon.stub().resolves(blockResponse);
683677
sinon.stub(CommonService.prototype, 'getHistoricalBlockResponse').callsFake(getHistoricalBlockResponseStub);
684678

685-
// Stub CacheService methods
686679
sinon.stub(cacheService, 'getAsync').resolves(null);
687680
sinon.stub(cacheService, 'set').resolves();
688681
});
@@ -726,11 +719,9 @@ describe('Debug API Test Suite', async function () {
726719

727720
describe('with PrestateTracer', async function () {
728721
beforeEach(() => {
729-
// Stub CommonService.getHistoricalBlockResponse
730722
const getHistoricalBlockResponseStub = sinon.stub().resolves(blockResponse);
731723
sinon.stub(CommonService.prototype, 'getHistoricalBlockResponse').callsFake(getHistoricalBlockResponseStub);
732724

733-
// Stub CacheService methods
734725
sinon.stub(cacheService, 'getAsync').resolves(null);
735726
sinon.stub(cacheService, 'set').resolves();
736727
});
@@ -760,14 +751,11 @@ describe('Debug API Test Suite', async function () {
760751
});
761752

762753
it('should handle error scenarios', async function () {
763-
// Create a proper JsonRpcError
764754
const jsonRpcError = predefined.INTERNAL_ERROR('Test error');
765755

766-
// Stub CommonService.getHistoricalBlockResponse to throw error
767756
const getHistoricalBlockResponseStub = sinon.stub().throws(jsonRpcError);
768757
sinon.stub(CommonService.prototype, 'getHistoricalBlockResponse').callsFake(getHistoricalBlockResponseStub);
769758

770-
// Stub CommonService.genericErrorHandler to return the error
771759
const genericErrorHandlerStub = sinon.stub().returns(jsonRpcError);
772760
sinon.stub(CommonService.prototype, 'genericErrorHandler').callsFake(genericErrorHandlerStub);
773761

packages/server/tests/integration/server.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { MirrorNodeClient } from '@hashgraph/json-rpc-relay/dist/lib/clients';
99
import { TracerType } from '@hashgraph/json-rpc-relay/dist/lib/constants';
1010
import { DebugImpl } from '@hashgraph/json-rpc-relay/dist/lib/debug';
1111
import { CacheService } from '@hashgraph/json-rpc-relay/dist/lib/services/cacheService/cacheService';
12-
import { CommonService } from '@hashgraph/json-rpc-relay/dist/lib/services/ethService/ethCommonService';
1312
import { Validator } from '@hashgraph/json-rpc-relay/dist/lib/validators';
1413
import * as Constants from '@hashgraph/json-rpc-relay/dist/lib/validators';
14+
import { CommonService } from '@hashgraph/json-rpc-relay/src/lib/services';
1515
import Axios, { AxiosInstance } from 'axios';
1616
import { expect } from 'chai';
1717
import { Server } from 'http';
@@ -3042,7 +3042,7 @@ describe('RPC Server', function () {
30423042
await testClient.post('/', {
30433043
jsonrpc: '2.0',
30443044
method: 'debug_traceBlockByNumber',
3045-
params: [blockNumberHex],
3045+
params: ['0x999999999999'], // block number that doesn't exist
30463046
id: '2',
30473047
});
30483048

0 commit comments

Comments
 (0)