From 11d380336d22311a24072eee9609cac1c9f318b4 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Tue, 5 Dec 2023 15:57:31 +0530 Subject: [PATCH] test: remove legacy public-ln-receive.bats --- bats/core/api/public-ln-receive.bats | 4 +- 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/ln.bash | 277 +++++++++++++ core/api/test/bats/public-ln-receive.bats | 365 ------------------ 9 files changed, 345 insertions(+), 366 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 1966a8d2a58..817898d842f 100644 --- a/bats/core/api/public-ln-receive.bats +++ b/bats/core/api/public-ln-receive.bats @@ -8,6 +8,8 @@ load "../../helpers/wallet.bash" load "../../helpers/subscriber.bash" setup_file() { + lnds_init + create_user 'alice' user_update_username 'alice' fund_user_onchain 'alice' 'btc_wallet' @@ -333,4 +335,4 @@ usd_amount=50 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 00000000000..450bcf8aba2 --- /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 00000000000..53845378ece --- /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 00000000000..b18e2d0c76c --- /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 00000000000..ed5790736ab --- /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 00000000000..54d65233a39 --- /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 00000000000..9017e57959f --- /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/ln.bash b/bats/helpers/ln.bash index e068c3859cb..6ff4c107d59 100644 --- a/bats/helpers/ln.bash +++ b/bats/helpers/ln.bash @@ -2,6 +2,41 @@ CURRENT_FILE=${BASH_SOURCE:-bats/helpers/.} source "$(dirname "$CURRENT_FILE")/_common.bash" source "$(dirname "$CURRENT_FILE")/cli.bash" +LND_FUNDING_TOKEN_NAME="lnd_funding" +LND_FUNDING_PHONE="+16505554351" + +LNDS_REST_LOG=".e2e-lnds-rest.log" + +mempool_not_empty() { + local txid="$(bitcoin_cli getrawmempool | jq -r ".[0]")" + [[ "$txid" != "null" ]] || exit 1 +} + +run_with_lnd() { + local func_name="$1" + shift # This will shift away the function name, so $1 becomes the next argument + + if [[ "$func_name" == "lnd_cli" ]]; then + lnd_cli "$@" + elif [[ "$func_name" == "lnd2_cli" ]]; then + lnd2_cli "$@" + elif [[ "$func_name" == "lnd_outside_cli" ]]; then + lnd_outside_cli "$@" + elif [[ "$func_name" == "lnd_outside_2_cli" ]]; then + lnd_outside_2_cli "$@" + else + echo "Invalid function name passed!" && return 1 + fi +} + +lnd2_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-lnd2-1" \ + lncli \ + --macaroonpath /root/.lnd/admin.macaroon \ + --tlscertpath /root/.lnd/tls.cert \ + $@ +} + create_new_lnd_onchain_address() { local wallet_name=$1 local wallet_id=$(read_value $wallet_name) @@ -31,3 +66,245 @@ create_new_lnd_onchain_address() { echo $address } + +run_with_lnd() { + local func_name="$1" + shift # This will shift away the function name, so $1 becomes the next argument + + if [[ "$func_name" == "lnd_cli" ]]; then + lnd_cli "$@" + elif [[ "$func_name" == "lnd2_cli" ]]; then + lnd2_cli "$@" + elif [[ "$func_name" == "lnd_outside_cli" ]]; then + lnd_outside_cli "$@" + elif [[ "$func_name" == "lnd_outside_2_cli" ]]; then + lnd_outside_2_cli "$@" + else + echo "Invalid function name passed!" && return 1 + fi +} + +close_partner_initiated_channels_with_external() { + close_channels_with_external() { + lnd_cli_value="$1" + lnd1_pubkey=$(lnd_cli getinfo | jq -r '.identity_pubkey') + lnd2_pubkey=$(lnd2_cli getinfo | jq -r '.identity_pubkey') + + partner_initiated_external_channel_filter=' + .channels[]? + | select(.initiator != true) + | select(.remote_pubkey != $lnd1_pubkey) + | select(.remote_pubkey != $lnd2_pubkey) + | .channel_point + ' + + run_with_lnd "$lnd_cli_value" listchannels \ + | jq -r \ + --arg lnd1_pubkey "$lnd1_pubkey" \ + --arg lnd2_pubkey "$lnd2_pubkey" \ + "$partner_initiated_external_channel_filter" \ + | while read -r channel_point; do + funding_txid="${channel_point%%:*}" + run_with_lnd "$lnd_cli_value" closechannel "$funding_txid" + done + } + + close_channels_with_external lnd_cli + close_channels_with_external lnd2_cli + close_channels_with_external lnd_outside_cli + close_channels_with_external lnd_outside_2_cli +} + +lnd_outside_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-lnd-outside-1-1" \ + lncli \ + --macaroonpath /root/.lnd/admin.macaroon \ + --tlscertpath /root/.lnd/tls.cert \ + $@ +} + +lnd_outside_2_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-lnd-outside-2-1" \ + lncli \ + --macaroonpath /root/.lnd/admin.macaroon \ + --tlscertpath /root/.lnd/tls.cert \ + $@ +} + +fund_wallet_from_lightning() { + local token_name=$1 + local wallet_id_name=$2 + local amount=$3 + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $wallet_id_name)" \ + '{input: {walletId: $wallet_id}}' + ) + exec_graphql "$token_name" 'ln-no-amount-invoice-create' "$variables" + invoice="$(graphql_output '.data.lnNoAmountInvoiceCreate.invoice')" + + payment_request="$(echo $invoice | jq -r '.paymentRequest')" + [[ "${payment_request}" != "null" ]] + payment_hash="$(echo $invoice | jq -r '.paymentHash')" + [[ "${payment_hash}" != "null" ]] + + lnd_outside_cli payinvoice -f \ + --pay_req "$payment_request" \ + --amt "$amount" + + retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash" +} + +check_for_ln_initiated_status() { + local expected_status=$1 + local token_name=$2 + local payment_hash=$3 + local first=${4:-"2"} + + variables=$( + jq -n \ + --argjson first "$first" \ + '{"first": $first}' + ) + exec_graphql "$token_name" 'transactions' "$variables" + + status="$(get_from_transaction_by_ln_hash_and_status $payment_hash $expected_status '.status')" + [[ "${status}" == "${expected_status}" ]] || return 1 +} + +check_for_ln_initiated_settled() { + check_for_ln_initiated_status "SUCCESS" "$@" +} + +check_for_ln_initiated_pending() { + check_for_ln_initiated_status "PENDING" "$@" +} + +get_from_transaction_by_ln_hash_and_status() { + payment_hash="$1" + expected_status="$2" + property_query="$3" + + jq_query=' + .data.me.defaultAccount.transactions.edges[] + | select(.node.initiationVia.paymentHash == $payment_hash) + | select(.node.status == $expected_status) + .node' + + echo $output \ + | jq -r \ + --arg payment_hash "$payment_hash" \ + --arg expected_status "$expected_status" \ + "$jq_query" \ + | jq -r "$property_query" \ + | head -n 1 +} + +check_for_ln_update() { + payment_hash=$1 + + retry 10 1 \ + grep "Data.*LnUpdate.*$payment_hash" .e2e-subscriber.log \ + | awk '{print $2}' \ + | jq -r --arg hash "$payment_hash" 'select(.data.myUpdates.update.paymentHash == $hash)' + + paid_status=$( \ + grep 'Data.*LnUpdate' .e2e-subscriber.log \ + | awk '{print $2}' \ + | jq -r --arg hash "$payment_hash" 'select(.data.myUpdates.update.paymentHash == $hash) .data.myUpdates.update.status' + ) + + [[ "$paid_status" == "PAID" ]] || exit 1 +} + +num_txns_for_hash() { + token_name="$1" + payment_hash="$2" + + first=20 + txn_variables=$( + jq -n \ + --argjson first "$first" \ + '{"first": $first}' + ) + exec_graphql "$token_name" 'transactions' "$txn_variables" > /dev/null + + jq_query=' + [ + .data.me.defaultAccount.transactions.edges[] + | select(.node.initiationVia.paymentHash == $payment_hash) + ] + | length + ' + echo $output \ + | jq -r \ + --arg payment_hash "$payment_hash" \ + "$jq_query" +} + +lnds_init() { + # Clean up any existing channels + close_partner_initiated_channels_with_external || true + + # Mine onchain balance + local amount="1" + local address="$(lnd_outside_cli newaddress p2wkh | jq -r '.address')" + local local_amount="10000000" + local push_amount="5000000" + bitcoin_cli sendtoaddress "$address" "$amount" + bitcoin_cli -generate 3 + + no_pending_channels() { + pending_channel="$(lnd_outside_cli pendingchannels | jq -r '.pending_open_channels[0]')" + if [[ "$pending_channel" != "null" ]]; then + bitcoin_cli -generate 3 + exit 1 + fi + } + + synced_to_graph() { + is_synced="$(lnd_outside_cli getinfo | jq -r '.synced_to_graph')" + [[ "$is_synced" == "true" ]] || exit 1 + } + + # Open channel from lndoutside1 -> lnd1 + pubkey="$(lnd_cli getinfo | jq -r '.identity_pubkey')" + endpoint="${COMPOSE_PROJECT_NAME}-lnd1-1:9735" + lnd_outside_cli connect "${pubkey}@${endpoint}" || true + retry 10 1 synced_to_graph + lnd_outside_cli openchannel \ + --node_key "$pubkey" \ + --local_amt "$local_amount" + + retry 10 1 mempool_not_empty + retry 10 1 no_pending_channels + + # Open channel with push from lndoutside1 -> lndoutside2 + pubkey="$(lnd_outside_2_cli getinfo | jq -r '.identity_pubkey')" + endpoint="${COMPOSE_PROJECT_NAME}-lnd-outside-2-1:9735" + lnd_outside_cli connect "${pubkey}@${endpoint}" || true + retry 10 1 synced_to_graph + lnd_outside_cli openchannel \ + --node_key "$pubkey" \ + --local_amt "$local_amount" \ + --push_amt "$push_amount" + + retry 10 1 mempool_not_empty + retry 10 1 no_pending_channels + + # FIXME: we may need some check on the graph or something else + # NB: I get randomly a "no route" error otherwise + sleep 10 + + # Fund lnd1 node with push_amount via funding user + login_user \ + "$LND_FUNDING_TOKEN_NAME" \ + "$LND_FUNDING_PHONE" \ + "$CODE" + + fund_wallet_from_lightning \ + "$LND_FUNDING_TOKEN_NAME" \ + "$LND_FUNDING_TOKEN_NAME.btc_wallet_id" \ + "$push_amount" +} \ 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 9818d2d72f2..00000000000 --- 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 -}