Skip to content
Merged
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
11 changes: 7 additions & 4 deletions packages/wallet/src/guardian/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,19 @@ describe('GuardianClient.evaluateEVMTransaction — 422 handling', () => {
});

describe('when Guardian returns 422 and crossSdkBridgeEnabled is false (web SDK)', () => {
it('returns confirmationRequired: true instead of throwing', async () => {
it('throws INTERNAL_ERROR; TRANSACTION_REVERTED is only used for native clients', async () => {
mockEvaluateTransaction.mockRejectedValue(
makeAxiosError(422, { message: 'execution reverted' }),
);

const client = makeClient(false);

const result = await (client as any).evaluateEVMTransaction(evalParams);

expect(result).toEqual({ confirmationRequired: true });
await expect(
(client as any).evaluateEVMTransaction(evalParams),
).rejects.toMatchObject({
code: RpcErrorCode.INTERNAL_ERROR,
message: expect.stringContaining('Transaction failed to validate with error:'),
});
});
});

Expand Down
18 changes: 8 additions & 10 deletions packages/wallet/src/guardian/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,14 @@ export default class GuardianClient {
throw new WalletError('Service unavailable', WalletErrorType.SERVICE_UNAVAILABLE_ERROR);
}

if (isAxiosError(error) && error.response?.status === 422) {
if (this.crossSdkBridgeEnabled) {
const revertReason = (error.response?.data as any)?.message ?? 'A transaction simulation reverted';
throw new JsonRpcError(
RpcErrorCode.TRANSACTION_REVERTED,
`Transaction will revert: ${revertReason}`,
);
}

return { confirmationRequired: true };
// For native clients, throw a TRANSACTION_REVERTED error if the guardian service
// responds with a 422.
if (isAxiosError(error) && error.response?.status === 422 && this.crossSdkBridgeEnabled) {
const revertReason = (error.response?.data as any)?.message ?? 'A transaction simulation reverted';
throw new JsonRpcError(
RpcErrorCode.TRANSACTION_REVERTED,
`Transaction will revert: ${revertReason}`,
);
}

const errorMessage = error instanceof Error ? error.message : String(error);
Expand Down
Loading