Skip to content

Commit

Permalink
temp: debug callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Dec 18, 2023
1 parent ef66d34 commit 50bb7f7
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 140 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
uses: DeterminateSystems/nix-installer-action@v4
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Buck2 build
run: |
nix develop -c buck2 build //core/api //core/api-ws-server \
//core/api-keys //apps/dashboard //apps/consent //apps/pay
# - name: Buck2 build
# run: |
# nix develop -c buck2 build //core/api //core/api-ws-server \
# //core/api-keys //apps/dashboard //apps/consent //apps/pay
- name: Run bats tests
run: |
nix develop -c bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/**
nix develop -c bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/api/ln-receive.bats
- name: Upload Tilt log
if: always()
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion bats/ci_setup_suite.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "${REPO_ROOT}/bats/helpers/_common.bash"
TILT_PID_FILE="${BATS_ROOT_DIR}/.tilt_pid"

setup_suite() {
background buck2 run //dev:up -- --bats=True > "${REPO_ROOT}/bats/.e2e-tilt.log"
background buck2 run //dev:up > "${REPO_ROOT}/bats/.e2e-tilt.log"
echo $! > "$TILT_PID_FILE"
await_api_is_up
await_api_keys_is_up
Expand Down
268 changes: 134 additions & 134 deletions bats/core/api/ln-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -125,137 +125,137 @@ usd_amount=50
[[ "$num_callback_events_after" -gt "$num_callback_events_before" ]] || exit 1
}

@test "ln-receive: settle via ln for USD wallet, invoice with amount" {
# Generate invoice
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg amount "$usd_amount" \
'{input: {walletId: $wallet_id, amount: $amount}}'
)
exec_graphql "$token_name" 'ln-usd-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnUsdInvoiceCreate.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

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

# Check for settled
retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"

# Check for subscriber event
check_for_ln_update "$payment_hash" || exit 1
}

@test "ln-receive: settle via ln for BTC wallet, amountless invoice" {
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

# Generate invoice
variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_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" ]] || exit 1
payment_hash="$(echo $invoice | jq -r '.paymentHash')"
[[ "${payment_hash}" != "null" ]] || exit 1

# Receive payment
lnd_outside_cli payinvoice -f \
--pay_req "$payment_request" \
--amt "$btc_amount"

# Check for settled
retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"

# Check for subscriber event
check_for_ln_update "$payment_hash" || exit 1
}

@test "ln-receive: handle less-than-1-sat ln payment for BTC wallet" {
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

# Generate amountless invoice
invoice_variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
'{input: {walletId: $wallet_id}}'
)
exec_graphql "$token_name" 'ln-no-amount-invoice-create' "$invoice_variables"
invoice="$(graphql_output '.data.lnNoAmountInvoiceCreate.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

# Check that invoice is retrievable from lnd1
invoice_from_lnd=$(lnd_cli lookupinvoice "$payment_hash")
[[ -n $invoice_from_lnd ]] || exit 1

# Receive less-than-1-sat payment
pay_variables=$(
jq -n \
--arg payment_request "$payment_request" \
--arg amt_msat "995" \
--arg timeout_seconds "5" \
'{payment_request: $payment_request, amt_msat: $amt_msat, timeout_seconds: $timeout_seconds}'\
| tr -d '[:space:]')
lnd_outside_rest "v2/router/send" "$pay_variables"

# Check that payment fails
response=$(tail -n 1 "$LNDS_REST_LOG")
[[ -n $response ]] || exit 1
pay_status=$(echo $response | jq -r '.result.status')
[[ "$pay_status" == "FAILED" ]] || exit 1
failure_reason=$(echo $response | jq -r '.result.failure_reason')
[[ "$failure_reason" == "FAILURE_REASON_INCORRECT_PAYMENT_DETAILS" ]] || exit 1

# Check that invoice is removed from lnd1
invoice_from_lnd=$(lnd_cli lookupinvoice "$payment_hash") || true
[[ -z $invoice_from_lnd ]] || exit 1
}

@test "ln-receive: settle via ln for USD wallet, amountless invoice" {
# Generate invoice
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_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" ]] || exit 1
payment_hash="$(echo $invoice | jq -r '.paymentHash')"
[[ "${payment_hash}" != "null" ]] || exit 1

# Receive payment
lnd_outside_cli payinvoice -f \
--pay_req "$payment_request" \
--amt "$btc_amount"

# Check for settled
retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"

# Check for subscriber event
check_for_ln_update "$payment_hash" || exit 1
}
# @test "ln-receive: settle via ln for USD wallet, invoice with amount" {
# # Generate invoice
# token_name="$ALICE"
# usd_wallet_name="$token_name.usd_wallet_id"

# variables=$(
# jq -n \
# --arg wallet_id "$(read_value $usd_wallet_name)" \
# --arg amount "$usd_amount" \
# '{input: {walletId: $wallet_id, amount: $amount}}'
# )
# exec_graphql "$token_name" 'ln-usd-invoice-create' "$variables"
# invoice="$(graphql_output '.data.lnUsdInvoiceCreate.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

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

# # Check for settled
# retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"

# # Check for subscriber event
# check_for_ln_update "$payment_hash" || exit 1
# }

# @test "ln-receive: settle via ln for BTC wallet, amountless invoice" {
# token_name="$ALICE"
# btc_wallet_name="$token_name.btc_wallet_id"

# # Generate invoice
# variables=$(
# jq -n \
# --arg wallet_id "$(read_value $btc_wallet_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" ]] || exit 1
# payment_hash="$(echo $invoice | jq -r '.paymentHash')"
# [[ "${payment_hash}" != "null" ]] || exit 1

# # Receive payment
# lnd_outside_cli payinvoice -f \
# --pay_req "$payment_request" \
# --amt "$btc_amount"

# # Check for settled
# retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"

# # Check for subscriber event
# check_for_ln_update "$payment_hash" || exit 1
# }

# @test "ln-receive: handle less-than-1-sat ln payment for BTC wallet" {
# token_name="$ALICE"
# btc_wallet_name="$token_name.btc_wallet_id"

# # Generate amountless invoice
# invoice_variables=$(
# jq -n \
# --arg wallet_id "$(read_value $btc_wallet_name)" \
# '{input: {walletId: $wallet_id}}'
# )
# exec_graphql "$token_name" 'ln-no-amount-invoice-create' "$invoice_variables"
# invoice="$(graphql_output '.data.lnNoAmountInvoiceCreate.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

# # Check that invoice is retrievable from lnd1
# invoice_from_lnd=$(lnd_cli lookupinvoice "$payment_hash")
# [[ -n $invoice_from_lnd ]] || exit 1

# # Receive less-than-1-sat payment
# pay_variables=$(
# jq -n \
# --arg payment_request "$payment_request" \
# --arg amt_msat "995" \
# --arg timeout_seconds "5" \
# '{payment_request: $payment_request, amt_msat: $amt_msat, timeout_seconds: $timeout_seconds}'\
# | tr -d '[:space:]')
# lnd_outside_rest "v2/router/send" "$pay_variables"

# # Check that payment fails
# response=$(tail -n 1 "$LNDS_REST_LOG")
# [[ -n $response ]] || exit 1
# pay_status=$(echo $response | jq -r '.result.status')
# [[ "$pay_status" == "FAILED" ]] || exit 1
# failure_reason=$(echo $response | jq -r '.result.failure_reason')
# [[ "$failure_reason" == "FAILURE_REASON_INCORRECT_PAYMENT_DETAILS" ]] || exit 1

# # Check that invoice is removed from lnd1
# invoice_from_lnd=$(lnd_cli lookupinvoice "$payment_hash") || true
# [[ -z $invoice_from_lnd ]] || exit 1
# }

# @test "ln-receive: settle via ln for USD wallet, amountless invoice" {
# # Generate invoice
# token_name="$ALICE"
# usd_wallet_name="$token_name.usd_wallet_id"

# variables=$(
# jq -n \
# --arg wallet_id "$(read_value $usd_wallet_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" ]] || exit 1
# payment_hash="$(echo $invoice | jq -r '.paymentHash')"
# [[ "${payment_hash}" != "null" ]] || exit 1

# # Receive payment
# lnd_outside_cli payinvoice -f \
# --pay_req "$payment_request" \
# --amt "$btc_amount"

# # Check for settled
# retry 15 1 check_for_ln_initiated_settled "$token_name" "$payment_hash"

# # Check for subscriber event
# check_for_ln_update "$payment_hash" || exit 1
# }

0 comments on commit 50bb7f7

Please sign in to comment.