Skip to content

Commit

Permalink
feat(backend): Check quote expiry in outgoing payment worker (#3141) (#…
Browse files Browse the repository at this point in the history
…3173)

* feat(backend):Check quote expiry in outgoing payment worker (#3141)

* feat:add test to quote expiry check

* feat:run code pnpm format
  • Loading branch information
CollinsMunene authored Feb 17, 2025
1 parent 26aa818 commit 308ed37
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,8 @@ export enum LifecycleError {
MissingBalance = 'MissingBalance',
MissingQuote = 'MissingQuote',
MissingExpiration = 'MissingExpiration',
Unauthorized = 'Unauthorized'
Unauthorized = 'Unauthorized',

// To be thrown when a Quote has expired
QuoteExpired = 'QuoteExpired'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export async function handleSending(
): Promise<void> {
if (!payment.quote) throw LifecycleError.MissingQuote

// Check if the current time is greater than or equal to when the Quote should be expiring
if (Date.now() >= payment.quote.expiresAt.getTime()) {
throw LifecycleError.QuoteExpired
}

const receiver = await deps.receiverService.get(payment.receiver)

// TODO: Query TigerBeetle transfers by code to distinguish sending debits from withdrawals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,25 @@ describe('OutgoingPaymentService', (): void => {
LifecycleError.DestinationAssetConflict
)
})

test('QuoteExpired (current time is greater than the payment quote expiration time)', async (): Promise<void> => {
const createdPayment = await setup({
receiver,
debitAmount,
method: 'ilp'
})

// Test case for `expiresAt` in the past (greater than current time)
await createdPayment.quote.$query(knex).patch({
expiresAt: new Date(Date.now() - 60 * 60 * 1000) // 1 hour ago
})

await processNext(
createdPayment.id,
OutgoingPaymentState.Failed,
LifecycleError.QuoteExpired
)
})
})

describe('fund', (): void => {
Expand Down

0 comments on commit 308ed37

Please sign in to comment.