Skip to content

Commit

Permalink
test: add alternate invoice creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Nov 9, 2023
1 parent b9028be commit 4820a7f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/api/test/bats/helpers/ln.bash
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ lnd_cli() {
$@
}

lnd_start() {
synced_to_graph() {
is_synced="$(lnd_cli getinfo | jq -r '.synced_to_graph')"
[[ "$is_synced" == "true" ]] || exit 1
}

docker start "${COMPOSE_PROJECT_NAME}-lnd1-1"
retry 10 1 synced_to_graph
}

lnd_stop() {
docker stop -t 0 "${COMPOSE_PROJECT_NAME}-lnd1-1"
}

lnd2_cli() {
docker exec "${COMPOSE_PROJECT_NAME}-lnd2-1" \
lncli \
Expand Down
52 changes: 52 additions & 0 deletions core/api/test/bats/ln-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,55 @@ usd_amount=50
# Check for settled
retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"
}

@test "ln-receive: create invoices from alternate node" {
lnd1_pubkey=$(lnd_cli getinfo | jq -r '.identity_pubkey')
lnd2_pubkey=$(lnd2_cli getinfo | jq -r '.identity_pubkey')

token_name="$ALICE_TOKEN_NAME"
btc_wallet_name="$token_name.btc_wallet_id"

# Generate invoice, it should be from lnd1
variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg amount "$btc_amount" \
'{input: {walletId: $wallet_id, amount: $amount}}'
)
exec_graphql "$token_name" 'ln-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnInvoiceCreate.invoice')"

payment_request="$(echo $invoice | jq -r '.paymentRequest')"
[[ "${payment_request}" != "null" ]] || exit 1
payment_hash="$(echo $invoice | jq -r '.paymentHash')"
[[ "${payment_hash}" != "null" ]] || exit 1

destination_node="$(lnd_cli decodepayreq $payment_request | jq -r '.destination')"
[[ "${destination_node}" == "${lnd1_pubkey}" ]] || exit 1

# Generate invoice after lnd1 stop, it should be from lnd2
lnd_stop
exec_graphql "$token_name" 'ln-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnInvoiceCreate.invoice')"

payment_request="$(echo $invoice | jq -r '.paymentRequest')"
[[ "${payment_request}" != "null" ]] || exit 1
payment_hash="$(echo $invoice | jq -r '.paymentHash')"
[[ "${payment_hash}" != "null" ]] || exit 1

destination_node="$(lnd2_cli decodepayreq $payment_request | jq -r '.destination')"
[[ "${destination_node}" == "${lnd2_pubkey}" ]] || exit 1

# Generate invoice after lnd1 start, it should be from lnd1
lnd_start
exec_graphql "$token_name" 'ln-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnInvoiceCreate.invoice')"

payment_request="$(echo $invoice | jq -r '.paymentRequest')"
[[ "${payment_request}" != "null" ]] || exit 1
payment_hash="$(echo $invoice | jq -r '.paymentHash')"
[[ "${payment_hash}" != "null" ]] || exit 1

destination_node="$(lnd_cli decodepayreq $payment_request | jq -r '.destination')"
[[ "${destination_node}" == "${lnd1_pubkey}" ]] || exit 1
}

0 comments on commit 4820a7f

Please sign in to comment.