Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

663/mk/create outgoing payment #807

Merged
merged 8 commits into from
Dec 5, 2022
Merged

Conversation

mkurapov
Copy link
Contributor

@mkurapov mkurapov commented Dec 1, 2022

Changes proposed in this pull request

  • Adding outgoingPayment.create to open payments client

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass

@github-actions github-actions bot added pkg: backend Changes in the backend package. pkg: open-payments type: source Changes business logic type: tests Testing related labels Dec 1, 2022
@@ -419,10 +419,10 @@ async function addSentAmount(
): Promise<OutgoingPayment> {
const fundingZeroOrUndefined =
payment.state === OutgoingPaymentState.Funding ? BigInt(0) : undefined
let sent = value || (await deps.accountingService.getTotalSent(payment.id))
Copy link
Contributor Author

@mkurapov mkurapov Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a guess about the desired behaviour

the main issue here was using || instead of ??. When we call this function just above:

return await addSentAmount(deps, payment, BigInt(0))

we pass in value: BigInt(0) . BigInt(0) is falsy, so we end up calling deps.accountingService.getTotalSent(payment.id)) even though we actually just wanted to set sent to be 0.

}
}

export const createOutgoingPayment = async (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the only other validation I could think of doing on a newly created outgoing payment (that wasn't already covered in validateOutgoingPayment) was checking whether sentAmount.value === 0. Feels like a weird behaviour to already start processing a payment before returning it, but does the caller care?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that does somehow seem less concerning than a non-zero receivedAmount on a new incoming payment.

Comment on lines +89 to +93
headers: accessToken
? {
Authorization: `GNAP ${accessToken}`
}
: {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was missing previously

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properly POSTs request test is failing with the addition of headers: {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, saw that, fixing.

packages/open-payments/src/client/outgoing-payment.test.ts Outdated Show resolved Hide resolved
@@ -91,6 +91,8 @@ export const mockOutgoingPayment = (
},
quoteId: uuid(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quoteId and id are supposed to be uris
https://github.com/interledger/open-payments/blob/02a6d505d79124cce776054df89e28f02c8e5d59/openapi/resource-server.yaml#L1072-L1084
Am I correct that we shouldn't be concerned about the quality of our OpenAPI validation because this package is only testing against successfulValidator/failedValidator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll make the test case a bit more realistic. But yes, in general, IMO the actual OpenAPI spec validation is a bit out of scope of the package, that responsibility is openapis

Comment on lines +89 to +93
headers: accessToken
? {
Authorization: `GNAP ${accessToken}`
}
: {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properly POSTs request test is failing with the addition of headers: {}

}
}

export const createOutgoingPayment = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that does somehow seem less concerning than a non-zero receivedAmount on a new incoming payment.

@mkurapov mkurapov requested a review from wilsonianb December 2, 2022 15:58
wilsonianb
wilsonianb previously approved these changes Dec 2, 2022
@mkurapov mkurapov requested a review from wilsonianb December 2, 2022 16:21
@mkurapov mkurapov merged commit 465b537 into main Dec 5, 2022
@mkurapov mkurapov deleted the 663/mk/create-outgoing-payment branch December 5, 2022 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants