Skip to content
Open
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
36 changes: 34 additions & 2 deletions packages/relay/src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,40 @@ export class DebugImpl implements Debug {
throw predefined.RESOURCE_NOT_FOUND(`Failed to retrieve contract results for transaction ${transactionHash}`);
}

// return empty array if no actions
if (actionsResponse.length === 0) return null;
// If there are no actions, return a root transaction object with empty calls
if (actionsResponse.length === 0) {
const {
from,
to,
amount,
gas_limit: gas,
gas_used: gasUsed,
function_parameters: input,
call_result: output,
error_message: error,
result,
} = transactionsResponse;

const { resolvedFrom, resolvedTo } = await this.resolveMultipleAddresses(from, to, requestDetails);

const value = amount === 0 ? DebugImpl.zeroHex : numberTo0x(amount);
const errorResult = result !== constants.SUCCESS ? result : undefined;
const type = resolvedTo ? 'CALL' : 'CREATE';

return {
type,
from: resolvedFrom,
to: resolvedTo,
value,
gas: numberTo0x(gas),
gasUsed: numberTo0x(gasUsed),
input,
output: result !== constants.SUCCESS ? error : output,
...(result !== constants.SUCCESS && { error: errorResult }),
...(result !== constants.SUCCESS && { revertReason: decodeErrorMessage(error) }),
calls: [],
};
}

const { call_type: type } = actionsResponse[0];
const formattedActions = await this.formatActionsResult(actionsResponse, requestDetails);
Expand Down
22 changes: 17 additions & 5 deletions packages/relay/tests/lib/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ describe('Debug API Test Suite', async function () {
});

this.beforeEach(() => {
cacheService.clear(requestDetails);
cacheService.clear();
});

describe('debug_traceTransaction', async function () {
Expand Down Expand Up @@ -422,7 +422,7 @@ describe('Debug API Test Suite', async function () {
expect(result).to.deep.equal(expectedResult);
});

it('Should return empty array if no actions found', async function () {
it('Should return root transaction with empty calls if no actions found', async function () {
restMock.onGet(CONTARCTS_RESULTS_ACTIONS).reply(200, JSON.stringify({ actions: [] }));

const result = await debugService.traceTransaction(
Expand All @@ -431,7 +431,19 @@ describe('Debug API Test Suite', async function () {
requestDetails,
);

expect(result).to.be.null;
const expectedRoot = {
type: 'CALL',
from: accountsResult.evm_address,
to: contractResult.evm_address,
value: '0x0',
gas: '0x493e0',
gasUsed: '0x3a980',
input: '0x1',
output: '0x2',
calls: [],
};

expect(result).to.deep.equal(expectedRoot);
});
});

Expand Down Expand Up @@ -710,7 +722,7 @@ describe('Debug API Test Suite', async function () {
sinon.restore();
restMock.reset();
web3Mock.reset();
cacheService.clear(requestDetails);
cacheService.clear();
});

withOverriddenEnvsInMochaTest({ DEBUG_API_ENABLED: undefined }, () => {
Expand Down Expand Up @@ -999,7 +1011,7 @@ describe('Debug API Test Suite', async function () {
sinon.restore();
restMock.reset();
web3Mock.reset();
cacheService.clear(requestDetails);
cacheService.clear();
});

withOverriddenEnvsInMochaTest({ DEBUG_API_ENABLED: true }, () => {
Expand Down
Loading