Skip to content

Commit 5018b23

Browse files
authored
fix: debug_traceTransaction throws 500 for non-existing transaction hashes (#2915)
* fix: `debug_traceTransaction` throws internal server error 500 for non-exising tx hashes Signed-off-by: Victor Yanev <[email protected]> * fix: debug.spec.ts Signed-off-by: Victor Yanev <[email protected]> * test: add acceptance test in rpc_batch3.spec.ts Signed-off-by: Victor Yanev <[email protected]> --------- Signed-off-by: Victor Yanev <[email protected]>
1 parent d0b0851 commit 5018b23

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

packages/relay/src/lib/clients/mirrorNodeClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class MirrorNodeClient {
9797
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_ENDPOINT, [404]],
9898
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_BY_ADDRESS_ENDPOINT, [404]],
9999
[MirrorNodeClient.GET_CONTRACT_RESULTS_ENDPOINT, [404]],
100+
[MirrorNodeClient.GET_CONTRACTS_RESULTS_ACTIONS, [404]],
100101
[MirrorNodeClient.GET_CONTRACTS_RESULTS_OPCODES, [404]],
101102
[MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT, [404]],
102103
[MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT, [404]],

packages/relay/src/lib/services/debugService/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ export class DebugService implements IDebugService {
299299
this.mirrorNodeClient.getContractsResultsActions(transactionHash, requestIdPrefix),
300300
this.mirrorNodeClient.getContractResultWithRetry(transactionHash),
301301
]);
302+
if (!actionsResponse || !transactionsResponse) {
303+
throw predefined.RESOURCE_NOT_FOUND(`Failed to retrieve contract results for transaction ${transactionHash}`);
304+
}
302305

303306
const { call_type: type } = actionsResponse.actions[0];
304307
const formattedActions = await this.formatActionsResult(actionsResponse.actions, requestIdPrefix);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ describe('Debug API Test Suite', async function () {
501501
});
502502

503503
it('test case for non-existing transaction hash', async function () {
504-
const expectedError = predefined.INTERNAL_ERROR('Not found');
504+
const expectedError = predefined.RESOURCE_NOT_FOUND(
505+
`Failed to retrieve contract results for transaction ${nonExistentTransactionHash}`,
506+
);
505507

506508
await RelayAssertions.assertRejection(expectedError, debugService.debug_traceTransaction, true, debugService, [
507509
nonExistentTransactionHash,

packages/server/tests/acceptance/rpc_batch3.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,20 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
19001900
});
19011901

19021902
describe('Negative scenarios', async function () {
1903+
it('should return 400 error for non-existing transaction hash', async function () {
1904+
const nonExistentTransactionHash = '0xb8a433b014684558d4154c73de3ed360bd5867725239938c2143acb7a76bca82';
1905+
const expectedError = predefined.RESOURCE_NOT_FOUND(
1906+
`Failed to retrieve contract results for transaction ${nonExistentTransactionHash}`,
1907+
);
1908+
const args = [
1909+
RelayCalls.ETH_ENDPOINTS.DEBUG_TRACE_TRANSACTION,
1910+
[nonExistentTransactionHash, { tracer: callTracer, tracerConfig: tracerConfigTrue }],
1911+
requestId,
1912+
];
1913+
1914+
await Assertions.assertPredefinedRpcError(expectedError, relay.call, false, relay, args);
1915+
});
1916+
19031917
it('should fail to debug a transaction with invalid onlyTopCall value type', async function () {
19041918
const transaction = {
19051919
...transactionTypeLegacy,

0 commit comments

Comments
 (0)