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
5 changes: 5 additions & 0 deletions .changeset/shiny-laws-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

feat: ensure that undecodable logs no longer throw
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ export function getAllDecodedLogs<T = unknown>(opts: {
? new BigNumberCoder('u64').encode(receipt.ra)
: receipt.data;

const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
logs.push(decodedLog);
let logEntry: unknown;

try {
[logEntry] = interfaceToUse.decodeLog(data, receipt.rb.toString());
} catch (error) {
logEntry = { __decoded: false, data, logId: receipt.rb.toString() };
}

logs.push(logEntry as T);
// eslint-disable-next-line no-param-reassign
groupedLogs[receipt.id] = [...(groupedLogs[receipt.id] || []), decodedLog];
groupedLogs[receipt.id] = [...(groupedLogs[receipt.id] || []), logEntry as T];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ export function getDecodedLogs<T = unknown>(
? new BigNumberCoder('u64').encode(receipt.ra)
: receipt.data;

const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
logs.push(decodedLog);
let logEntry: unknown;

try {
[logEntry] = interfaceToUse.decodeLog(data, receipt.rb.toString());
} catch (error) {
logEntry = { __decoded: false, data, logId: receipt.rb.toString() };
}

logs.push(logEntry as T);
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/account/src/providers/utils/extract-tx-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,9 @@ export const extractTxError = (params: IExtractTxError): FuelError => {
if (isPanic) {
return assemblePanicError(statusReason, metadata);
}
return assembleRevertError(receipts, logs, metadata, statusReason, abis);
const decodedLogs = logs.filter((l: unknown) => {
const log = l as unknown as { __decoded: boolean };
return !(typeof log === 'object' && '__decoded' in log && log.__decoded === false);
});
return assembleRevertError(receipts, decodedLogs, metadata, statusReason, abis);
};
69 changes: 67 additions & 2 deletions packages/fuel-gauge/src/advanced-logging.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { FuelError } from '@fuel-ts/errors';
import { bn, ZeroBytes32 } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';
import { bn, Contract, ErrorCode, type JsonAbi, ZeroBytes32 } from 'fuels';
import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils';

import {
AdvancedLoggingOtherContractFactory,
AdvancedLoggingFactory,
CallTestContractFactory,
ConfigurableContractFactory,
CoverageContractFactory,
AbiContractFactory,
} from '../test/typegen/contracts';
import { ScriptCallContract, ScriptCallLoggingContracts } from '../test/typegen/scripts';

Expand Down Expand Up @@ -505,5 +506,69 @@ describe('Advanced Logging', () => {
],
});
});

it('should not throw when unable to decode a log with a missing JSON ABI', async () => {
using launched = await launchTestNode({
contractsConfigs: [{ factory: AbiContractFactory }],
});
const {
wallets: [wallet],
contracts: [originalContract],
} = launched;
const abiWithoutLogs: JsonAbi = {
...originalContract.interface.jsonAbi,
loggedTypes: [],
};
const contract = new Contract(originalContract.id, abiWithoutLogs, wallet);

const { waitForResult } = await contract.functions.types_u8(8).call();
const { logs, groupedLogs } = await waitForResult();

const expectedLogEntry = {
__decoded: false,
data: '0xff',
logId: '14454674236531057292',
};
expect(logs).toStrictEqual([expectedLogEntry]);
expect(groupedLogs).toStrictEqual({
[originalContract.id.toB256()]: [expectedLogEntry],
});
});

it('should not display undecoded logs in the error message', async () => {
using launched = await launchTestNode({
contractsConfigs: [{ factory: AbiContractFactory }],
});
const {
wallets: [wallet],
contracts: [originalContract],
} = launched;
const abiWithoutLogs: JsonAbi = {
...originalContract.interface.jsonAbi,
loggedTypes: [],
};
const contract = new Contract(originalContract.id, abiWithoutLogs, wallet);

const call = () => contract.functions.types_u8(255).call();

await expectToThrowFuelError(call, {
code: ErrorCode.SCRIPT_REVERTED,
message: 'The transaction reverted because of an "assert_eq" statement.',
metadata: {
logs: [
{
__decoded: false,
data: '0xff',
logId: '14454674236531057292',
},
{
__decoded: false,
data: '0x08',
logId: '14454674236531057292',
},
],
},
});
});
});
});
Loading