Skip to content

Commit decaf36

Browse files
committed
dont swallow aborted errors in waitForTransactionReceipt
1 parent 66fbb84 commit decaf36

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/actions/public/waitForTransactionReceipt.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,54 @@ test('args: timeout', async () => {
614614
).rejects.toThrowError(WaitForTransactionReceiptTimeoutError)
615615
})
616616

617+
test('args: requestOptions.signal (already aborted)', async () => {
618+
setup()
619+
620+
const hash = await sendTransaction(client, {
621+
account: sourceAccount.address,
622+
to: targetAccount.address,
623+
value: parseEther('1'),
624+
})
625+
626+
const controller = new AbortController()
627+
controller.abort()
628+
629+
await expect(() =>
630+
waitForTransactionReceipt(client, {
631+
hash,
632+
requestOptions: { signal: controller.signal },
633+
}),
634+
).rejects.toThrow('This operation was aborted')
635+
})
636+
637+
test('args: requestOptions.signal (aborted during wait)', async () => {
638+
setup()
639+
640+
const hash = await sendTransaction(client, {
641+
account: sourceAccount.address,
642+
to: targetAccount.address,
643+
value: parseEther('1'),
644+
})
645+
646+
const controller = new AbortController()
647+
648+
const receiptPromise = waitForTransactionReceipt(client, {
649+
hash,
650+
pollingInterval: 50,
651+
timeout: 10_000,
652+
requestOptions: { signal: controller.signal },
653+
})
654+
655+
await wait(100)
656+
controller.abort()
657+
658+
const start = Date.now()
659+
await expect(() => receiptPromise).rejects.toThrow()
660+
const elapsed = Date.now() - start
661+
662+
expect(elapsed).toBeLessThan(2000)
663+
})
664+
617665
describe('errors', () => {
618666
test('throws when transaction replaced and getBlock fails', async () => {
619667
setup()

src/actions/public/waitForTransactionReceipt.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ export async function waitForTransactionReceipt<
192192
client,
193193
getTransactionReceipt,
194194
'getTransactionReceipt',
195-
)({ hash, requestOptions }).catch(() => undefined)
195+
)({ hash, requestOptions }).catch((err) => {
196+
if (err?.name === 'AbortError') throw err
197+
return undefined
198+
})
196199

197200
if (receipt && confirmations <= 1) {
198201
clearTimeout(timer)

0 commit comments

Comments
 (0)