Skip to content

Commit 7974723

Browse files
authored
fix: fixes debug_traceBlockByNumber response to not be null for a transaction with no internal calls (#4440)
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
1 parent 83f2309 commit 7974723

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

packages/relay/src/lib/debug.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ export class DebugImpl implements Debug {
291291
// The actions endpoint does not return input and output for the calls so we get them from another endpoint
292292
// The first one is excluded because we take its input and output from the contracts/results/{transactionIdOrHash} endpoint
293293
const contract =
294-
index !== 0 && (
295-
action.call_operation_type === CallType.CREATE || action.call_operation_type === CallType.CREATE2
296-
) && action.to
294+
index !== 0 &&
295+
(action.call_operation_type === CallType.CREATE || action.call_operation_type === CallType.CREATE2) &&
296+
action.to
297297
? await this.mirrorNodeClient.getContract(action.to, requestDetails)
298298
: undefined;
299299

@@ -459,7 +459,7 @@ export class DebugImpl implements Debug {
459459
transactionHash: string,
460460
tracerConfig: ICallTracerConfig,
461461
requestDetails: RequestDetails,
462-
): Promise<CallTracerResult | null> {
462+
): Promise<CallTracerResult> {
463463
try {
464464
const [actionsResponse, transactionsResponse] = await Promise.all([
465465
this.mirrorNodeClient.getContractsResultsActions(transactionHash, requestDetails),
@@ -473,9 +473,6 @@ export class DebugImpl implements Debug {
473473
throw predefined.RESOURCE_NOT_FOUND(`Failed to retrieve contract results for transaction ${transactionHash}`);
474474
}
475475

476-
// return empty array if no actions
477-
if (actionsResponse.length === 0) return null;
478-
479476
const { call_type: type } = actionsResponse[0];
480477
const formattedActions = await this.formatActionsResult(actionsResponse, requestDetails);
481478

@@ -510,7 +507,7 @@ export class DebugImpl implements Debug {
510507
// if we have more than one call executed during the transactions we would return all calls
511508
// except the first one in the sub-calls array,
512509
// therefore we need to exclude the first one from the actions response
513-
calls: tracerConfig?.onlyTopCall || actionsResponse.length === 1 ? undefined : formattedActions.slice(1),
510+
calls: tracerConfig?.onlyTopCall || actionsResponse.length === 1 ? [] : formattedActions.slice(1),
514511
};
515512
} catch (e) {
516513
throw this.common.genericErrorHandler(e);

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ describe('Debug API Test Suite', async function () {
408408
gasUsed: '0x3a980',
409409
input: '0x1',
410410
output: '0x2',
411-
calls: undefined,
411+
calls: [],
412412
};
413413
const result = await debugService.traceTransaction(
414414
transactionHash,
@@ -418,17 +418,31 @@ describe('Debug API Test Suite', async function () {
418418

419419
expect(result).to.deep.equal(expectedResult);
420420
});
421-
422-
it('Should return empty array if no actions found', async function () {
423-
restMock.onGet(CONTARCTS_RESULTS_ACTIONS).reply(200, JSON.stringify({ actions: [] }));
421+
it('should return empty calls array when using callTracer with single action (no internal calls)', async function () {
422+
const singleActionResponse = {
423+
actions: [contractsResultsActionsResult.actions[0]], // Only the root action
424+
};
425+
restMock.onGet(CONTARCTS_RESULTS_ACTIONS).reply(200, JSON.stringify(singleActionResponse));
424426

425427
const result = await debugService.traceTransaction(
426428
transactionHash,
427429
tracerObjectCallTracerFalse,
428430
requestDetails,
429431
);
430432

431-
expect(result).to.be.null;
433+
const expectedResult = {
434+
type: 'CREATE',
435+
from: accountsResult.evm_address,
436+
to: contractResult.evm_address,
437+
value: '0x0',
438+
gas: '0x493e0',
439+
gasUsed: '0x3a980',
440+
input: '0x1',
441+
output: '0x2',
442+
calls: [],
443+
};
444+
445+
expect(result).to.deep.equal(expectedResult);
432446
});
433447
});
434448

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ describe('@debug API Acceptance Tests', function () {
446446
accounts[0].address,
447447
parentContractAddress,
448448
);
449-
expect(result).to.not.have.property('calls');
449+
expect(result).to.have.property('calls');
450+
expect(result.calls).to.be.an('array').that.is.empty;
450451
});
451452
});
452453

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
11981198
gasUsed: '0x249f00',
11991199
input: '',
12001200
output: '',
1201+
calls: [],
12011202
};
12021203
const successResultCreateWithDepth = {
12031204
...defaultResponseFields,
@@ -1217,6 +1218,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
12171218
const successResultCall = {
12181219
...defaultResponseFields,
12191220
type: 'CALL',
1221+
calls: [],
12201222
};
12211223
const successResultCallWithDepth = {
12221224
...successResultCall,
@@ -1238,12 +1240,14 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
12381240
error: 'CONTRACT_EXECUTION_EXCEPTION',
12391241
revertReason: 'INSUFFICIENT_STACK_ITEMS',
12401242
gasUsed: '0x2dc6c0',
1243+
calls: [],
12411244
};
12421245
const failingResultCall = {
12431246
...defaultResponseFields,
12441247
type: 'CALL',
12451248
error: 'CONTRACT_REVERT_EXECUTED',
12461249
revertReason: 'Some revert message',
1250+
calls: [],
12471251
};
12481252

12491253
describe('Test transactions of type 0', async function () {

0 commit comments

Comments
 (0)