Skip to content

Commit

Permalink
fix: debug_traceTransaction throws 500 for non-existing transaction…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
victor-yanev authored Sep 2, 2024
1 parent d0b0851 commit 5018b23
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/relay/src/lib/clients/mirrorNodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class MirrorNodeClient {
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_ENDPOINT, [404]],
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_BY_ADDRESS_ENDPOINT, [404]],
[MirrorNodeClient.GET_CONTRACT_RESULTS_ENDPOINT, [404]],
[MirrorNodeClient.GET_CONTRACTS_RESULTS_ACTIONS, [404]],
[MirrorNodeClient.GET_CONTRACTS_RESULTS_OPCODES, [404]],
[MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT, [404]],
[MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT, [404]],
Expand Down
3 changes: 3 additions & 0 deletions packages/relay/src/lib/services/debugService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ export class DebugService implements IDebugService {
this.mirrorNodeClient.getContractsResultsActions(transactionHash, requestIdPrefix),
this.mirrorNodeClient.getContractResultWithRetry(transactionHash),
]);
if (!actionsResponse || !transactionsResponse) {
throw predefined.RESOURCE_NOT_FOUND(`Failed to retrieve contract results for transaction ${transactionHash}`);
}

const { call_type: type } = actionsResponse.actions[0];
const formattedActions = await this.formatActionsResult(actionsResponse.actions, requestIdPrefix);
Expand Down
4 changes: 3 additions & 1 deletion packages/relay/tests/lib/services/debugService/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ describe('Debug API Test Suite', async function () {
});

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

await RelayAssertions.assertRejection(expectedError, debugService.debug_traceTransaction, true, debugService, [
nonExistentTransactionHash,
Expand Down
14 changes: 14 additions & 0 deletions packages/server/tests/acceptance/rpc_batch3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,20 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
});

describe('Negative scenarios', async function () {
it('should return 400 error for non-existing transaction hash', async function () {
const nonExistentTransactionHash = '0xb8a433b014684558d4154c73de3ed360bd5867725239938c2143acb7a76bca82';
const expectedError = predefined.RESOURCE_NOT_FOUND(
`Failed to retrieve contract results for transaction ${nonExistentTransactionHash}`,
);
const args = [
RelayCalls.ETH_ENDPOINTS.DEBUG_TRACE_TRANSACTION,
[nonExistentTransactionHash, { tracer: callTracer, tracerConfig: tracerConfigTrue }],
requestId,
];

await Assertions.assertPredefinedRpcError(expectedError, relay.call, false, relay, args);
});

it('should fail to debug a transaction with invalid onlyTopCall value type', async function () {
const transaction = {
...transactionTypeLegacy,
Expand Down

0 comments on commit 5018b23

Please sign in to comment.