Skip to content

Commit

Permalink
test: add test for invoice by hash
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Oct 6, 2023
1 parent 75bc1a0 commit 8f39707
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/api/src/app/wallets/get-invoice-for-wallet-by-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const getInvoiceForWalletByHash = async ({

if (walletInvoice instanceof Error) return walletInvoice

// QUESTION: Should we make the walletId part of the repository method or do this check here?
if (walletInvoice.recipientWalletDescriptor.id !== walletId) {
return new CouldNotFindWalletInvoiceError()
}
Expand Down
13 changes: 13 additions & 0 deletions core/api/test/bats/gql/invoice-for-wallet-by-hash.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query me($walletId: WalletId!, $paymentHash: PaymentHash!) {
me {
defaultAccount {
id
walletById(walletId: $walletId) {
id
invoiceByHash(paymentHash: $paymentHash) {
paymentHash
}
}
}
}
}
11 changes: 11 additions & 0 deletions core/api/test/bats/ln-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ usd_amount=50
payment_hash="$(echo $invoice | jq -r '.paymentHash')"
[[ "${payment_hash}" != "null" ]] || exit 1

# Get invoice by hash
invoice_for_wallet_by_hash_variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg payment_hash "$payment_hash" \
'{walletId: $wallet_id, paymentHash: $payment_hash}'
)
exec_graphql "$token_name" 'invoice-for-wallet-by-hash' "$invoice_for_wallet_by_hash_variables"
query_payment_hash="$(graphql_output '.data.me.defaultAccount.walletById.invoiceByHash.paymentHash')"
[[ "${query_payment_hash}" == "${payment_hash}" ]] || exit 1

# Receive payment
lnd_outside_cli payinvoice -f \
--pay_req "$payment_request"
Expand Down

0 comments on commit 8f39707

Please sign in to comment.