Skip to content

Commit

Permalink
test: move tests to invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Nov 15, 2023
1 parent 947f404 commit 789d657
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 68 deletions.
9 changes: 5 additions & 4 deletions core/api/test/bats/helpers/ln.bash
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ lnd_cli() {
}

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

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

lnd_stop() {
Expand Down
64 changes: 52 additions & 12 deletions core/api/test/bats/invoices.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,58 @@ setup_file() {
exec_graphql "$token_name" 'ln-usd-invoice-create' "$variables"
}

teardown_file() {
stop_trigger
stop_server
stop_ws_server
stop_exporter
}

setup() {
reset_redis
}

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

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')"
lnd_start

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
}

@test "invoices: get invoices for account" {
token_name="$ALICE_TOKEN_NAME"

Expand All @@ -65,15 +117,3 @@ setup_file() {
invoice_count="$(graphql_output '.data.me.defaultAccount.walletById.invoices.edges | length')"
[[ "$invoice_count" -eq "2" ]] || exit 1
}


teardown_file() {
stop_trigger
stop_server
stop_ws_server
stop_exporter
}

setup() {
reset_redis
}
52 changes: 0 additions & 52 deletions core/api/test/bats/ln-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -404,55 +404,3 @@ 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 789d657

Please sign in to comment.