Skip to content

Commit 8f551e5

Browse files
authored
fix(wallet): Ensure transaction simulation throws an error for non-native clients on transaction simulation revert (#2806)
1 parent b02b4a5 commit 8f551e5

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

packages/wallet/src/guardian/index.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,19 @@ describe('GuardianClient.evaluateEVMTransaction — 422 handling', () => {
111111
});
112112

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

119119
const client = makeClient(false);
120120

121-
const result = await (client as any).evaluateEVMTransaction(evalParams);
122-
123-
expect(result).toEqual({ confirmationRequired: true });
121+
await expect(
122+
(client as any).evaluateEVMTransaction(evalParams),
123+
).rejects.toMatchObject({
124+
code: RpcErrorCode.INTERNAL_ERROR,
125+
message: expect.stringContaining('Transaction failed to validate with error:'),
126+
});
124127
});
125128
});
126129

packages/wallet/src/guardian/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,14 @@ export default class GuardianClient {
173173
throw new WalletError('Service unavailable', WalletErrorType.SERVICE_UNAVAILABLE_ERROR);
174174
}
175175

176-
if (isAxiosError(error) && error.response?.status === 422) {
177-
if (this.crossSdkBridgeEnabled) {
178-
const revertReason = (error.response?.data as any)?.message ?? 'A transaction simulation reverted';
179-
throw new JsonRpcError(
180-
RpcErrorCode.TRANSACTION_REVERTED,
181-
`Transaction will revert: ${revertReason}`,
182-
);
183-
}
184-
185-
return { confirmationRequired: true };
176+
// For native clients, throw a TRANSACTION_REVERTED error if the guardian service
177+
// responds with a 422.
178+
if (isAxiosError(error) && error.response?.status === 422 && this.crossSdkBridgeEnabled) {
179+
const revertReason = (error.response?.data as any)?.message ?? 'A transaction simulation reverted';
180+
throw new JsonRpcError(
181+
RpcErrorCode.TRANSACTION_REVERTED,
182+
`Transaction will revert: ${revertReason}`,
183+
);
186184
}
187185

188186
const errorMessage = error instanceof Error ? error.message : String(error);

0 commit comments

Comments
 (0)