Skip to content

Commit 9d7aab2

Browse files
authored
Improve status timeout error logs (#910)
* Improve status timeout error logs * feat: changeset * Fix build error * Fix unit tests * Fix unit test error
1 parent a9e7c3b commit 9d7aab2

File tree

7 files changed

+35
-15
lines changed

7 files changed

+35
-15
lines changed

.changeset/social-tires-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@relayprotocol/relay-sdk': patch
3+
---
4+
5+
Improve SolverStatusTimeout error log
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export class DepositTransactionTimeoutError extends Error {
22
txHash: `0x${string}`
3+
requestId: string
34

4-
constructor(txHash: `0x${string}`, attemptCount: number) {
5+
constructor(txHash: `0x${string}`, requestId: string, attemptCount: number) {
56
super(
6-
`Deposit transaction with hash '${txHash}' is pending after ${attemptCount} attempt(s).`
7+
`Deposit transaction with hash '${txHash}' and request id '${requestId}' is pending after ${attemptCount} attempt(s).`
78
)
89
this.name = 'DepositTransactionTimeoutError'
910
this.txHash = txHash
11+
this.requestId = requestId
1012
}
1113
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export class SolverStatusTimeoutError extends Error {
22
txHash: `0x${string}`
3+
requestId: string
34

4-
constructor(txHash: `0x${string}`, attemptCount: number) {
5+
constructor(txHash: `0x${string}`, requestId: string, attemptCount: number) {
56
super(
6-
`Failed to receive a successful response for solver status check with hash '${txHash}' after ${attemptCount} attempt(s).`
7+
`Failed to receive a successful response for solver status check with hash '${txHash}' and request id '${requestId}' after ${attemptCount} attempt(s).`
78
)
89
this.name = 'SolverStatusTimeoutError'
910
this.txHash = txHash
11+
this.requestId = requestId
1012
}
1113
}

packages/sdk/src/utils/executeSteps/executeSteps.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const mockAxiosRequest = () => {
117117
}
118118
if (
119119
config.url?.includes('transactions/index') ||
120+
config.url?.includes('/transactions/single') ||
120121
config.url?.includes('/execute/permits')
121122
) {
122123
return Promise.resolve({
@@ -339,7 +340,7 @@ describe('Should test the executeSteps method.', () => {
339340
undefined
340341
)
341342
).rejects.toThrow(
342-
`Deposit transaction with hash '0x' is pending after 1 attempt(s).`
343+
`Deposit transaction with hash '0x' and request id '0xabc' is pending after 1 attempt(s).`
343344
)
344345
vi.spyOn(axios, 'request').mockRestore()
345346
vi.spyOn(axios, 'request').mockClear()
@@ -432,7 +433,7 @@ describe('Should test the executeSteps method.', () => {
432433
undefined
433434
)
434435
).rejects.toThrow(
435-
`Failed to receive a successful response for solver status check with hash '0x' after 1 attempt(s).`
436+
`Failed to receive a successful response for solver status check with hash '0x' and request id '0xabc' after 1 attempt(s).`
436437
)
437438

438439
vi.spyOn(axios, 'request').mockRestore()
@@ -495,6 +496,8 @@ describe('Should test the executeSteps method.', () => {
495496
it('Should handle step with id of "approve" by waiting on receipt before polling for confirmation', async () => {
496497
const axiosRequestSpy = vi.spyOn(axios, 'request')
497498

499+
client.logLevel = 4
500+
498501
await executeSteps(
499502
1,
500503
{},
@@ -506,12 +509,12 @@ describe('Should test the executeSteps method.', () => {
506509

507510
const waitForTransactionReceiptCallIndex =
508511
wallet.handleConfirmTransactionStep.mock.invocationCallOrder[0]
509-
const pollForConfirmationCallIndices = axiosRequestSpy.mock.calls
510-
.filter((call) => call[0].url?.includes('/intents/status'))
511-
.map((call, index) => axiosRequestSpy.mock.invocationCallOrder[index])
512+
const pollForConfirmationCallIndex = axiosRequestSpy.mock.calls.findIndex(
513+
(call) => call[0].url?.includes('/intents/status')
514+
)
512515

513516
expect(waitForTransactionReceiptCallIndex).toBeLessThan(
514-
Math.min(...pollForConfirmationCallIndices)
517+
axiosRequestSpy.mock.invocationCallOrder[pollForConfirmationCallIndex]
515518
)
516519
expect(wallet.handleConfirmTransactionStep).toHaveBeenCalledTimes(2)
517520
})

packages/sdk/src/utils/transaction.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,15 @@ export async function sendTransactionSafely(
347347

348348
if (attemptCount >= maximumAttempts) {
349349
if (receipt) {
350-
throw new SolverStatusTimeoutError(txHash as Address, attemptCount)
350+
throw new SolverStatusTimeoutError(
351+
txHash as Address,
352+
step.requestId ?? '',
353+
attemptCount
354+
)
351355
} else {
352356
throw new DepositTransactionTimeoutError(
353357
txHash as Address,
358+
step.requestId ?? '',
354359
attemptCount
355360
)
356361
}

packages/sdk/tests/data/executeBridge.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const executeBridge: Execute = {
2525
"method": "GET"
2626
}
2727
}
28-
]
28+
],
29+
"requestId": "0xabc"
2930
}
3031
],
3132
"fees": {

packages/sdk/tests/data/swapWithApproval.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Execute } from '../../src/types'
1+
import type { Execute } from '../../src/types'
22

33
export const swapWithApproval: Execute = {
44
steps: [
@@ -19,7 +19,8 @@ export const swapWithApproval: Execute = {
1919
chainId: 1
2020
}
2121
}
22-
]
22+
],
23+
requestId: '0xabc'
2324
},
2425
{
2526
id: 'swap',
@@ -43,7 +44,8 @@ export const swapWithApproval: Execute = {
4344
method: 'GET'
4445
}
4546
}
46-
]
47+
],
48+
requestId: '0xabc'
4749
}
4850
],
4951
fees: {

0 commit comments

Comments
 (0)