From f5f8d5df8d4da613c71b64f4ef21150caf535069 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Mon, 4 Dec 2023 00:36:21 +0530 Subject: [PATCH 1/2] test: add new public-ln-receive.bats --- bats/core/api/public-ln-receive.bats | 336 +++++++++++++++++++++++++++ bats/helpers/cli.bash | 8 + 2 files changed, 344 insertions(+) create mode 100644 bats/core/api/public-ln-receive.bats diff --git a/bats/core/api/public-ln-receive.bats b/bats/core/api/public-ln-receive.bats new file mode 100644 index 0000000000..1966a8d2a5 --- /dev/null +++ b/bats/core/api/public-ln-receive.bats @@ -0,0 +1,336 @@ +#!/usr/bin/env bats + +load "../../helpers/cli.bash" +load "../../helpers/user.bash" +load "../../helpers/onchain.bash" +load "../../helpers/ln.bash" +load "../../helpers/wallet.bash" +load "../../helpers/subscriber.bash" + +setup_file() { + create_user 'alice' + user_update_username 'alice' + fund_user_onchain 'alice' 'btc_wallet' + fund_user_onchain 'alice' 'usd_wallet' +} + +btc_amount=1000 +usd_amount=50 + +@test "public-ln-receive: account details - can fetch with btc default wallet-id from username" { + btc_wallet_name="alice.btc_wallet_id" + usd_wallet_name="alice.usd_wallet_id" + + # Change default wallet to btc + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + exec_graphql 'alice' 'account-update-default-wallet-id' "$variables" + updated_wallet_id="$(graphql_output '.data.accountUpdateDefaultWalletId.account.defaultWalletId')" + [[ "$updated_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 + + # Fetch btc-wallet-id from username + variables=$( + jq -n \ + --arg username 'alice' \ + '{username: $username}' + ) + exec_graphql 'anon' 'account-default-wallet' "$variables" + receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" + [[ "$receiver_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 + + # Fetch usd-wallet-id from username + variables=$( + jq -n \ + --arg username 'alice' \ + '{username: $username, walletCurrency: "USD"}' + ) + exec_graphql 'anon' 'account-default-wallet' "$variables" + receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" + [[ "$receiver_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 +} + +@test "public-ln-receive: account details - can fetch with usd default wallet-id from username" { + btc_wallet_name="alice.btc_wallet_id" + usd_wallet_name="alice.usd_wallet_id" + + # Change default wallet to usd + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + exec_graphql 'alice' 'account-update-default-wallet-id' "$variables" + updated_wallet_id="$(graphql_output '.data.accountUpdateDefaultWalletId.account.defaultWalletId')" + [[ "$updated_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 + + # Fetch usd-wallet-id from username + variables=$( + jq -n \ + --arg username 'alice' \ + '{username: $username}' + ) + exec_graphql 'anon' 'account-default-wallet' "$variables" + receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" + [[ "$receiver_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 + + # Fetch btc-wallet-id from username + variables=$( + jq -n \ + --arg username 'alice' \ + '{username: $username, walletCurrency: "BTC"}' + ) + exec_graphql 'anon' 'account-default-wallet' "$variables" + receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" + [[ "$receiver_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 +} + +@test "public-ln-receive: account details - return error for invalid username" { + exec_graphql 'anon' 'account-default-wallet' '{"username": "incorrectly-formatted"}' + error_msg="$(graphql_output '.errors[0].message')" + [[ "$error_msg" == "Invalid value for Username" ]] || exit 1 + + exec_graphql 'anon' 'account-default-wallet' '{"username": "idontexist"}' + error_msg="$(graphql_output '.errors[0].message')" + [[ "$error_msg" == "Account does not exist for username idontexist" ]] || exit 1 +} + +@test "public-ln-receive: receive via invoice - can receive on btc invoice, with subscription" { + btc_wallet_name="alice.btc_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + --arg amount "$btc_amount" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" + invoice="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.invoice')" + + payment_request="$(echo $invoice | jq -r '.paymentRequest')" + [[ "${payment_request}" != "null" ]] || exit 1 + + # Setup subscription + variables=$( + jq -n \ + --arg payment_request "$payment_request" \ + '{"input": {"paymentRequest": $payment_request}}' + ) + subscribe_to 'anon' 'ln-invoice-payment-status-sub' "$variables" + sleep 3 + retry 10 1 grep "Data.*lnInvoicePaymentStatus.*PENDING" .e2e-subscriber.log + + # Receive payment + lnd_outside_cli payinvoice -f \ + --pay_req "$payment_request" \ + + # Check for settled with subscription + retry 10 1 grep "Data.*lnInvoicePaymentStatus.*PAID" .e2e-subscriber.log + stop_subscriber +} + +@test "public-ln-receive: receive via invoice - can receive on usd invoice" { + usd_wallet_name="alice.usd_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + --arg amount "$usd_amount" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" + invoice="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.invoice')" + + payment_request="$(echo $invoice | jq -r '.paymentRequest')" + [[ "${payment_request}" != "null" ]] || exit 1 + + # Receive payment + lnd_outside_cli payinvoice -f \ + --pay_req "$payment_request" \ + + # Check for settled with query + retry 15 1 check_ln_payment_settled "$payment_request" +} + +@test "public-ln-receive: receive via invoice - can receive on usd invoice, sats denominated" { + usd_wallet_name="alice.usd_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + --arg amount "$btc_amount" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" + invoice="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.invoice')" + + payment_request="$(echo $invoice | jq -r '.paymentRequest')" + [[ "${payment_request}" != "null" ]] || exit 1 + + # Receive payment + lnd_outside_cli payinvoice -f \ + --pay_req "$payment_request" \ + + # Check for settled with query + retry 15 1 check_ln_payment_settled "$payment_request" +} + +@test "public-ln-receive: receive via invoice - can receive on btc amountless invoice" { + btc_wallet_name="alice.btc_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + '{input: {recipientWalletId: $wallet_id}}' + ) + exec_graphql 'anon' 'ln-no-amount-invoice-create-on-behalf-of-recipient' "$variables" + invoice="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.invoice')" + + payment_request="$(echo $invoice | jq -r '.paymentRequest')" + [[ "${payment_request}" != "null" ]] || exit 1 + + # Receive payment + lnd_outside_cli payinvoice -f \ + --pay_req "$payment_request" \ + --amt "$btc_amount" + + # Check for settled with query + retry 15 1 check_ln_payment_settled "$payment_request" +} + +@test "public-ln-receive: receive via invoice - can receive on usd amountless invoice" { + usd_wallet_name="alice.usd_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + '{input: {recipientWalletId: $wallet_id}}' + ) + exec_graphql 'anon' 'ln-no-amount-invoice-create-on-behalf-of-recipient' "$variables" + invoice="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.invoice')" + + payment_request="$(echo $invoice | jq -r '.paymentRequest')" + [[ "${payment_request}" != "null" ]] || exit 1 + + # Receive payment + lnd_outside_cli payinvoice -f \ + --pay_req "$payment_request" \ + --amt "$btc_amount" + + # Check for settled with query + retry 15 1 check_ln_payment_settled "$payment_request" +} + +@test "public-ln-receive: fail to create invoice - invalid wallet-id" { + variables=$( + jq -n \ + --arg amount "$btc_amount" \ + '{input: {recipientWalletId: "does-not-exist", amount: $amount}}' + ) + exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 + exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 + exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 + + exec_graphql \ + 'anon' \ + 'ln-no-amount-invoice-create-on-behalf-of-recipient' \ + '{"input": {"recipientWalletId": "does-not-exist"}}' + error_msg="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 +} + +@test "public-ln-receive: fail to create invoice - nonexistent wallet-id" { + non_existent_wallet_id="$(random_uuid)" + + variables=$( + jq -n \ + --arg amount "$btc_amount" \ + --arg recipient_wallet_id "$non_existent_wallet_id" \ + '{input: {recipientWalletId: $recipient_wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 + exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 + exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 + + variables=$( + jq -n \ + --arg recipient_wallet_id "$non_existent_wallet_id" \ + '{input: {recipientWalletId: $recipient_wallet_id}}' + ) + exec_graphql \ + 'anon' \ + 'ln-no-amount-invoice-create-on-behalf-of-recipient' \ + "$variables" + error_msg="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 +} + +@test "public-ln-receive: fail to create invoice - negative amount" { + btc_wallet_name="alice.btc_wallet_id" + usd_wallet_name="alice.usd_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + --arg amount "-1000" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for SatAmount" ]] || exit 1 + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + --arg amount "-1000" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for CentAmount" ]] || exit 1 + exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "Invalid value for SatAmount" ]] || exit 1 +} + +@test "public-ln-receive: fail to create invoice - zero amount" { + btc_wallet_name="alice.btc_wallet_id" + usd_wallet_name="alice.usd_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + --arg amount "0" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "A valid satoshi amount is required" ]] || exit 1 + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + --arg amount "0" \ + '{input: {recipientWalletId: $wallet_id, amount: $amount}}' + ) + exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "A valid usd amount is required" ]] || exit 1 + exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" + error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" + [[ "$error_msg" == "A valid satoshi amount is required" ]] || exit 1 +} \ No newline at end of file diff --git a/bats/helpers/cli.bash b/bats/helpers/cli.bash index fecdc9fec7..10cbfffe3e 100644 --- a/bats/helpers/cli.bash +++ b/bats/helpers/cli.bash @@ -10,6 +10,14 @@ lnd_cli() { $@ } +lnd_outside_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-lnd-outside-1-1" \ + lncli \ + --macaroonpath /root/.lnd/data/chain/bitcoin/regtest/admin.macaroon \ + --tlscertpath /root/.lnd/tls.cert \ + $@ +} + bria_cli() { docker exec "${COMPOSE_PROJECT_NAME}-bria-1" bria $@ } From f9d4cb5a0dc367ba45ed13a1ce55027e8d046b61 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Tue, 5 Dec 2023 15:57:31 +0530 Subject: [PATCH 2/2] test: remove legacy public-ln-receive.bats --- bats/core/api/public-ln-receive.bats | 288 +------------- bats/gql/account-default-wallet.gql | 6 + bats/gql/account-update-default-wallet-id.gql | 7 + ...-invoice-create-on-behalf-of-recipient.gql | 13 + ...-invoice-create-on-behalf-of-recipient.gql | 13 + ...ominated-create-on-behalf-of-recipient.gql | 13 + ...-invoice-create-on-behalf-of-recipient.gql | 13 + bats/helpers/_common.bash | 2 +- bats/helpers/ln.bash | 2 +- core/api/test/bats/public-ln-receive.bats | 365 ------------------ 10 files changed, 68 insertions(+), 654 deletions(-) create mode 100644 bats/gql/account-default-wallet.gql create mode 100644 bats/gql/account-update-default-wallet-id.gql create mode 100644 bats/gql/ln-invoice-create-on-behalf-of-recipient.gql create mode 100644 bats/gql/ln-no-amount-invoice-create-on-behalf-of-recipient.gql create mode 100644 bats/gql/ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient.gql create mode 100644 bats/gql/ln-usd-invoice-create-on-behalf-of-recipient.gql delete mode 100644 core/api/test/bats/public-ln-receive.bats diff --git a/bats/core/api/public-ln-receive.bats b/bats/core/api/public-ln-receive.bats index 1966a8d2a5..3341d07dfd 100644 --- a/bats/core/api/public-ln-receive.bats +++ b/bats/core/api/public-ln-receive.bats @@ -1,11 +1,8 @@ #!/usr/bin/env bats -load "../../helpers/cli.bash" load "../../helpers/user.bash" load "../../helpers/onchain.bash" -load "../../helpers/ln.bash" -load "../../helpers/wallet.bash" -load "../../helpers/subscriber.bash" +load "../../helpers/_common.bash" setup_file() { create_user 'alice' @@ -50,287 +47,4 @@ usd_amount=50 exec_graphql 'anon' 'account-default-wallet' "$variables" receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" [[ "$receiver_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 -} - -@test "public-ln-receive: account details - can fetch with usd default wallet-id from username" { - btc_wallet_name="alice.btc_wallet_id" - usd_wallet_name="alice.usd_wallet_id" - - # Change default wallet to usd - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - exec_graphql 'alice' 'account-update-default-wallet-id' "$variables" - updated_wallet_id="$(graphql_output '.data.accountUpdateDefaultWalletId.account.defaultWalletId')" - [[ "$updated_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 - - # Fetch usd-wallet-id from username - variables=$( - jq -n \ - --arg username 'alice' \ - '{username: $username}' - ) - exec_graphql 'anon' 'account-default-wallet' "$variables" - receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" - [[ "$receiver_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 - - # Fetch btc-wallet-id from username - variables=$( - jq -n \ - --arg username 'alice' \ - '{username: $username, walletCurrency: "BTC"}' - ) - exec_graphql 'anon' 'account-default-wallet' "$variables" - receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" - [[ "$receiver_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 -} - -@test "public-ln-receive: account details - return error for invalid username" { - exec_graphql 'anon' 'account-default-wallet' '{"username": "incorrectly-formatted"}' - error_msg="$(graphql_output '.errors[0].message')" - [[ "$error_msg" == "Invalid value for Username" ]] || exit 1 - - exec_graphql 'anon' 'account-default-wallet' '{"username": "idontexist"}' - error_msg="$(graphql_output '.errors[0].message')" - [[ "$error_msg" == "Account does not exist for username idontexist" ]] || exit 1 -} - -@test "public-ln-receive: receive via invoice - can receive on btc invoice, with subscription" { - btc_wallet_name="alice.btc_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - --arg amount "$btc_amount" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Setup subscription - variables=$( - jq -n \ - --arg payment_request "$payment_request" \ - '{"input": {"paymentRequest": $payment_request}}' - ) - subscribe_to 'anon' 'ln-invoice-payment-status-sub' "$variables" - sleep 3 - retry 10 1 grep "Data.*lnInvoicePaymentStatus.*PENDING" .e2e-subscriber.log - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - - # Check for settled with subscription - retry 10 1 grep "Data.*lnInvoicePaymentStatus.*PAID" .e2e-subscriber.log - stop_subscriber -} - -@test "public-ln-receive: receive via invoice - can receive on usd invoice" { - usd_wallet_name="alice.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "$usd_amount" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: receive via invoice - can receive on usd invoice, sats denominated" { - usd_wallet_name="alice.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "$btc_amount" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: receive via invoice - can receive on btc amountless invoice" { - btc_wallet_name="alice.btc_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - '{input: {recipientWalletId: $wallet_id}}' - ) - exec_graphql 'anon' 'ln-no-amount-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - --amt "$btc_amount" - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: receive via invoice - can receive on usd amountless invoice" { - usd_wallet_name="alice.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - '{input: {recipientWalletId: $wallet_id}}' - ) - exec_graphql 'anon' 'ln-no-amount-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - --amt "$btc_amount" - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: fail to create invoice - invalid wallet-id" { - variables=$( - jq -n \ - --arg amount "$btc_amount" \ - '{input: {recipientWalletId: "does-not-exist", amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 - - exec_graphql \ - 'anon' \ - 'ln-no-amount-invoice-create-on-behalf-of-recipient' \ - '{"input": {"recipientWalletId": "does-not-exist"}}' - error_msg="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 -} - -@test "public-ln-receive: fail to create invoice - nonexistent wallet-id" { - non_existent_wallet_id="$(random_uuid)" - - variables=$( - jq -n \ - --arg amount "$btc_amount" \ - --arg recipient_wallet_id "$non_existent_wallet_id" \ - '{input: {recipientWalletId: $recipient_wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 - - variables=$( - jq -n \ - --arg recipient_wallet_id "$non_existent_wallet_id" \ - '{input: {recipientWalletId: $recipient_wallet_id}}' - ) - exec_graphql \ - 'anon' \ - 'ln-no-amount-invoice-create-on-behalf-of-recipient' \ - "$variables" - error_msg="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 -} - -@test "public-ln-receive: fail to create invoice - negative amount" { - btc_wallet_name="alice.btc_wallet_id" - usd_wallet_name="alice.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - --arg amount "-1000" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for SatAmount" ]] || exit 1 - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "-1000" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for CentAmount" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for SatAmount" ]] || exit 1 -} - -@test "public-ln-receive: fail to create invoice - zero amount" { - btc_wallet_name="alice.btc_wallet_id" - usd_wallet_name="alice.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - --arg amount "0" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "A valid satoshi amount is required" ]] || exit 1 - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "0" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "A valid usd amount is required" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "A valid satoshi amount is required" ]] || exit 1 } \ No newline at end of file diff --git a/bats/gql/account-default-wallet.gql b/bats/gql/account-default-wallet.gql new file mode 100644 index 0000000000..450bcf8aba --- /dev/null +++ b/bats/gql/account-default-wallet.gql @@ -0,0 +1,6 @@ +query accountDefaultWallet($username: Username!, $walletCurrency: WalletCurrency) { + accountDefaultWallet(username: $username, walletCurrency: $walletCurrency) { + id + walletCurrency + } +} \ No newline at end of file diff --git a/bats/gql/account-update-default-wallet-id.gql b/bats/gql/account-update-default-wallet-id.gql new file mode 100644 index 0000000000..53845378ec --- /dev/null +++ b/bats/gql/account-update-default-wallet-id.gql @@ -0,0 +1,7 @@ +mutation accountUpdateDefaultWalletId($input: AccountUpdateDefaultWalletIdInput!) { + accountUpdateDefaultWalletId(input: $input) { + account { + defaultWalletId + } + } +} \ No newline at end of file diff --git a/bats/gql/ln-invoice-create-on-behalf-of-recipient.gql b/bats/gql/ln-invoice-create-on-behalf-of-recipient.gql new file mode 100644 index 0000000000..b18e2d0c76 --- /dev/null +++ b/bats/gql/ln-invoice-create-on-behalf-of-recipient.gql @@ -0,0 +1,13 @@ +mutation lnInvoiceCreateOnBehalfOfRecipient( + $input: LnInvoiceCreateOnBehalfOfRecipientInput! +) { + lnInvoiceCreateOnBehalfOfRecipient(input: $input) { + invoice { + paymentRequest + paymentHash + } + errors { + message + } + } +} \ No newline at end of file diff --git a/bats/gql/ln-no-amount-invoice-create-on-behalf-of-recipient.gql b/bats/gql/ln-no-amount-invoice-create-on-behalf-of-recipient.gql new file mode 100644 index 0000000000..ed5790736a --- /dev/null +++ b/bats/gql/ln-no-amount-invoice-create-on-behalf-of-recipient.gql @@ -0,0 +1,13 @@ +mutation lnNoAmountInvoiceCreateOnBehalfOfRecipient( + $input: LnNoAmountInvoiceCreateOnBehalfOfRecipientInput! +) { + lnNoAmountInvoiceCreateOnBehalfOfRecipient(input: $input) { + invoice { + paymentRequest + paymentHash + } + errors { + message + } + } +} \ No newline at end of file diff --git a/bats/gql/ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient.gql b/bats/gql/ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient.gql new file mode 100644 index 0000000000..54d65233a3 --- /dev/null +++ b/bats/gql/ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient.gql @@ -0,0 +1,13 @@ +mutation lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient( + $input: LnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipientInput! +) { + lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient(input: $input) { + invoice { + paymentRequest + paymentHash + } + errors { + message + } + } +} \ No newline at end of file diff --git a/bats/gql/ln-usd-invoice-create-on-behalf-of-recipient.gql b/bats/gql/ln-usd-invoice-create-on-behalf-of-recipient.gql new file mode 100644 index 0000000000..9017e57959 --- /dev/null +++ b/bats/gql/ln-usd-invoice-create-on-behalf-of-recipient.gql @@ -0,0 +1,13 @@ +mutation lnUsdInvoiceCreateOnBehalfOfRecipient( + $input: LnUsdInvoiceCreateOnBehalfOfRecipientInput! +) { + lnUsdInvoiceCreateOnBehalfOfRecipient(input: $input) { + invoice { + paymentRequest + paymentHash + } + errors { + message + } + } +} \ No newline at end of file diff --git a/bats/helpers/_common.bash b/bats/helpers/_common.bash index bc5cb1a930..d66957d410 100644 --- a/bats/helpers/_common.bash +++ b/bats/helpers/_common.bash @@ -134,4 +134,4 @@ cache_value() { read_value() { cat ${CACHE_DIR}/$1 -} +} \ No newline at end of file diff --git a/bats/helpers/ln.bash b/bats/helpers/ln.bash index e068c3859c..939e1569d9 100644 --- a/bats/helpers/ln.bash +++ b/bats/helpers/ln.bash @@ -30,4 +30,4 @@ create_new_lnd_onchain_address() { insert_lnd1_address "$wallet_id" "$address" > /dev/null echo $address -} +} \ No newline at end of file diff --git a/core/api/test/bats/public-ln-receive.bats b/core/api/test/bats/public-ln-receive.bats deleted file mode 100644 index 9818d2d72f..0000000000 --- a/core/api/test/bats/public-ln-receive.bats +++ /dev/null @@ -1,365 +0,0 @@ -#!/usr/bin/env bats - -load "helpers/setup-and-teardown" -load "helpers/ln" - -setup_file() { - clear_cache - - bitcoind_init - start_trigger - start_server - start_ws_server - start_exporter - - lnds_init - initialize_user_from_onchain "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE" - user_update_username "$ALICE_TOKEN_NAME" -} - -teardown_file() { - stop_trigger - stop_server - stop_ws_server - stop_exporter -} - -setup() { - reset_redis -} - -teardown() { - if [[ "$(balance_for_check)" != 0 ]]; then - fail "Error: balance_for_check failed" - fi -} - -btc_amount=1000 -usd_amount=50 - -@test "public-ln-receive: account details - can fetch with btc default wallet-id from username" { - token_name=$ALICE_TOKEN_NAME - btc_wallet_name="$token_name.btc_wallet_id" - usd_wallet_name="$token_name.usd_wallet_id" - - # Change default wallet to btc - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - exec_graphql "$token_name" 'account-update-default-wallet-id' "$variables" - updated_wallet_id="$(graphql_output '.data.accountUpdateDefaultWalletId.account.defaultWalletId')" - [[ "$updated_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 - - # Fetch btc-wallet-id from username - variables=$( - jq -n \ - --arg username "$token_name" \ - '{username: $username}' - ) - exec_graphql 'anon' 'account-default-wallet' "$variables" - receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" - [[ "$receiver_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 - - # Fetch usd-wallet-id from username - variables=$( - jq -n \ - --arg username "$token_name" \ - '{username: $username, walletCurrency: "USD"}' - ) - exec_graphql 'anon' 'account-default-wallet' "$variables" - receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" - [[ "$receiver_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 -} - -@test "public-ln-receive: account details - can fetch with usd default wallet-id from username" { - token_name=$ALICE_TOKEN_NAME - btc_wallet_name="$token_name.btc_wallet_id" - usd_wallet_name="$token_name.usd_wallet_id" - - # Change default wallet to usd - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - exec_graphql "$token_name" 'account-update-default-wallet-id' "$variables" - updated_wallet_id="$(graphql_output '.data.accountUpdateDefaultWalletId.account.defaultWalletId')" - [[ "$updated_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 - - # Fetch usd-wallet-id from username - variables=$( - jq -n \ - --arg username "$token_name" \ - '{username: $username}' - ) - exec_graphql 'anon' 'account-default-wallet' "$variables" - receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" - [[ "$receiver_wallet_id" == "$(read_value $usd_wallet_name)" ]] || exit 1 - - # Fetch btc-wallet-id from username - variables=$( - jq -n \ - --arg username "$token_name" \ - '{username: $username, walletCurrency: "BTC"}' - ) - exec_graphql 'anon' 'account-default-wallet' "$variables" - receiver_wallet_id="$(graphql_output '.data.accountDefaultWallet.id')" - [[ "$receiver_wallet_id" == "$(read_value $btc_wallet_name)" ]] || exit 1 -} - -@test "public-ln-receive: account details - return error for invalid username" { - exec_graphql 'anon' 'account-default-wallet' '{"username": "incorrectly-formatted"}' - error_msg="$(graphql_output '.errors[0].message')" - [[ "$error_msg" == "Invalid value for Username" ]] || exit 1 - - exec_graphql 'anon' 'account-default-wallet' '{"username": "idontexist"}' - error_msg="$(graphql_output '.errors[0].message')" - [[ "$error_msg" == "Account does not exist for username idontexist" ]] || exit 1 -} - -@test "public-ln-receive: receive via invoice - can receive on btc invoice, with subscription" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - --arg amount "$btc_amount" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Setup subscription - variables=$( - jq -n \ - --arg payment_request "$payment_request" \ - '{"input": {"paymentRequest": $payment_request}}' - ) - subscribe_to 'anon' 'ln-invoice-payment-status-sub' "$variables" - sleep 3 - retry 10 1 grep "Data.*lnInvoicePaymentStatus.*PENDING" .e2e-subscriber.log - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - - # Check for settled with subscription - retry 10 1 grep "Data.*lnInvoicePaymentStatus.*PAID" .e2e-subscriber.log - stop_subscriber -} - -@test "public-ln-receive: receive via invoice - can receive on usd invoice" { - token_name="$ALICE_TOKEN_NAME" - usd_wallet_name="$token_name.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "$usd_amount" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: receive via invoice - can receive on usd invoice, sats denominated" { - token_name="$ALICE_TOKEN_NAME" - usd_wallet_name="$token_name.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "$btc_amount" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: receive via invoice - can receive on btc amountless invoice" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - '{input: {recipientWalletId: $wallet_id}}' - ) - exec_graphql 'anon' 'ln-no-amount-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - --amt "$btc_amount" - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: receive via invoice - can receive on usd amountless invoice" { - token_name="$ALICE_TOKEN_NAME" - usd_wallet_name="$token_name.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - '{input: {recipientWalletId: $wallet_id}}' - ) - exec_graphql 'anon' 'ln-no-amount-invoice-create-on-behalf-of-recipient' "$variables" - invoice="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.invoice')" - - payment_request="$(echo $invoice | jq -r '.paymentRequest')" - [[ "${payment_request}" != "null" ]] || exit 1 - - # Receive payment - lnd_outside_cli payinvoice -f \ - --pay_req "$payment_request" \ - --amt "$btc_amount" - - # Check for settled with query - retry 15 1 check_ln_payment_settled "$payment_request" -} - -@test "public-ln-receive: fail to create invoice - invalid wallet-id" { - variables=$( - jq -n \ - --arg amount "$btc_amount" \ - '{input: {recipientWalletId: "does-not-exist", amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 - - exec_graphql \ - 'anon' \ - 'ln-no-amount-invoice-create-on-behalf-of-recipient' \ - '{"input": {"recipientWalletId": "does-not-exist"}}' - error_msg="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for WalletId" ]] || exit 1 -} - -@test "public-ln-receive: fail to create invoice - nonexistent wallet-id" { - non_existent_wallet_id="$(random_uuid)" - - variables=$( - jq -n \ - --arg amount "$btc_amount" \ - --arg recipient_wallet_id "$non_existent_wallet_id" \ - '{input: {recipientWalletId: $recipient_wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 - - variables=$( - jq -n \ - --arg recipient_wallet_id "$non_existent_wallet_id" \ - '{input: {recipientWalletId: $recipient_wallet_id}}' - ) - exec_graphql \ - 'anon' \ - 'ln-no-amount-invoice-create-on-behalf-of-recipient' \ - "$variables" - error_msg="$(graphql_output '.data.lnNoAmountInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == *CouldNotFindWalletFromIdError* ]] || exit 1 -} - -@test "public-ln-receive: fail to create invoice - negative amount" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - usd_wallet_name="$token_name.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - --arg amount "-1000" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for SatAmount" ]] || exit 1 - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "-1000" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for CentAmount" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "Invalid value for SatAmount" ]] || exit 1 -} - -@test "public-ln-receive: fail to create invoice - zero amount" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - usd_wallet_name="$token_name.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - --arg amount "0" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "A valid satoshi amount is required" ]] || exit 1 - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - --arg amount "0" \ - '{input: {recipientWalletId: $wallet_id, amount: $amount}}' - ) - exec_graphql 'anon' 'ln-usd-invoice-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "A valid usd amount is required" ]] || exit 1 - exec_graphql 'anon' 'ln-usd-invoice-btc-denominated-create-on-behalf-of-recipient' "$variables" - error_msg="$(graphql_output '.data.lnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipient.errors[0].message')" - [[ "$error_msg" == "A valid satoshi amount is required" ]] || exit 1 -}