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
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,40 @@ describe('getPaymentStatus', () => {
});
});

it('should propagate RPC errors from the pending user operation lookup', async () => {
vi.mocked(fetch)
.mockResolvedValueOnce({
json: async () => ({ jsonrpc: '2.0', id: 1, result: null }),
} as Response)
.mockResolvedValueOnce({
json: async () => ({
jsonrpc: '2.0',
id: 2,
error: {
code: -32602,
message: 'Invalid user operation hash',
},
}),
} as Response);

await expect(
getPaymentStatus({
id: '0xinvalid',
testnet: false,
})
).rejects.toThrow('RPC error: Invalid user operation hash');

const { logPaymentStatusCheckCompleted, logPaymentStatusCheckError } = await import(
':core/telemetry/events/payment.js'
);
expect(logPaymentStatusCheckCompleted).not.toHaveBeenCalled();
expect(logPaymentStatusCheckError).toHaveBeenCalledWith({
testnet: false,
correlationId: 'mock-correlation-id',
errorMessage: 'RPC error: Invalid user operation hash',
});
});

it('should handle RPC errors gracefully', async () => {
vi.mocked(fetch).mockResolvedValueOnce({
json: async () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export async function getPaymentStatus(options: PaymentStatusOptions): Promise<P
}),
}).then((res) => res.json());

if (userOpResponse.error) {
const errorMessage = userOpResponse.error.message || 'Network error';
throw new Error(`RPC error: ${errorMessage}`);
}

if (userOpResponse.result) {
// UserOp exists but no receipt yet - it's pending
if (telemetry) {
Expand Down