Skip to content

Commit

Permalink
test(core): move rest of external-settled ln-send bats tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Dec 19, 2023
1 parent 094cb69 commit ff4e04f
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 254 deletions.
256 changes: 256 additions & 0 deletions bats/core/api/ln-send.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load "../../helpers/ledger.bash"
load "../../helpers/ln.bash"
load "../../helpers/onchain.bash"
load "../../helpers/user.bash"
load "../../helpers/wallet.bash"

ALICE='alice'

Expand All @@ -17,6 +18,7 @@ setup_file() {

create_user "$ALICE"
fund_user_onchain "$ALICE" 'btc_wallet'
fund_user_onchain "$ALICE" 'usd_wallet'
}

teardown() {
Expand Down Expand Up @@ -67,3 +69,257 @@ usd_amount=50
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" == "$btc_amount" ]] || exit 1
}

@test "ln-send: lightning settled - lnInvoicePaymentSend from btc, no fee probe" {
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice --amt $btc_amount)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg payment_request "$payment_request" \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request}}'
)

exec_graphql "$token_name" 'ln-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

transaction_payment_hash="$(graphql_output '.data.lnInvoicePaymentSend.transaction.initiationVia.paymentHash')"
[[ "${transaction_payment_hash}" == "${payment_hash}" ]] || exit 1

transaction_payment_request="$(graphql_output '.data.lnInvoicePaymentSend.transaction.initiationVia.paymentRequest')"
[[ "${transaction_payment_request}" == "${payment_request}" ]] || exit 1

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

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" == "$btc_amount" ]] || exit 1
}

@test "ln-send: lightning settled - lnInvoicePaymentSend from usd" {
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice --amt $btc_amount)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg payment_request "$payment_request" \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request}}'
)

exec_graphql "$token_name" 'ln-usd-invoice-fee-probe' "$variables"
fee_amount="$(graphql_output '.data.lnUsdInvoiceFeeProbe.amount')"
[[ "${fee_amount}" = "0" ]] || exit 1

exec_graphql "$token_name" 'ln-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

transaction_payment_hash="$(graphql_output '.data.lnInvoicePaymentSend.transaction.initiationVia.paymentHash')"
[[ "${transaction_payment_hash}" == "${payment_hash}" ]] || exit 1

transaction_payment_request="$(graphql_output '.data.lnInvoicePaymentSend.transaction.initiationVia.paymentRequest')"
[[ "${transaction_payment_request}" == "${payment_request}" ]] || exit 1

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

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" == "$btc_amount" ]] || exit 1
}

@test "ln-send: lightning settled - lnInvoicePaymentSend from usd, no fee probe" {
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice --amt $btc_amount)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg payment_request "$payment_request" \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request}}'
)

exec_graphql "$token_name" 'ln-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

transaction_payment_hash="$(graphql_output '.data.lnInvoicePaymentSend.transaction.initiationVia.paymentHash')"
[[ "${transaction_payment_hash}" == "${payment_hash}" ]] || exit 1

transaction_payment_request="$(graphql_output '.data.lnInvoicePaymentSend.transaction.initiationVia.paymentRequest')"
[[ "${transaction_payment_request}" == "${payment_request}" ]] || exit 1

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

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" == "$btc_amount" ]] || exit 1
}

@test "ln-send: lightning settled - lnNoAmountInvoicePaymentSend" {
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg payment_request "$payment_request" \
--arg amount $btc_amount \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request, amount: $amount}}'
)

exec_graphql "$token_name" 'ln-no-amount-invoice-fee-probe' "$variables"
fee_amount="$(graphql_output '.data.lnNoAmountInvoiceFeeProbe.amount')"
[[ "${fee_amount}" = "0" ]] || exit 1

exec_graphql "$token_name" 'ln-no-amount-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnNoAmountInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

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

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" == "$btc_amount" ]] || exit 1
}

@test "ln-send: lightning settled - lnNoAmountInvoicePaymentSend, no fee probe" {
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg payment_request "$payment_request" \
--arg amount $btc_amount \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request, amount: $amount}}'
)

exec_graphql "$token_name" 'ln-no-amount-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnNoAmountInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

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

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" == "$btc_amount" ]] || exit 1
}

@test "ln-send: lightning settled - lnNoAmountUsdInvoicePaymentSend" {
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

initial_balance="$(balance_for_wallet $token_name 'USD')"
initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg payment_request "$payment_request" \
--arg amount $usd_amount \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request, amount: $amount}}'
)

exec_graphql "$token_name" 'ln-no-amount-usd-invoice-fee-probe' "$variables"
fee_amount="$(graphql_output '.data.lnNoAmountUsdInvoiceFeeProbe.amount')"
[[ "${fee_amount}" = "0" ]] || exit 1

exec_graphql "$token_name" 'ln-no-amount-usd-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnNoAmountUsdInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

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

final_balance="$(balance_for_wallet $token_name 'USD')"
wallet_diff="$(( $initial_balance - $final_balance ))"
[[ "$wallet_diff" == "$usd_amount" ]] || exit 1

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" -gt "0" ]] || exit 1
}

@test "ln-send: lightning settled - lnNoAmountUsdInvoicePaymentSend, no fee probe" {
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

initial_balance="$(balance_for_wallet $token_name 'USD')"
initial_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')

invoice_response="$(lnd_outside_cli addinvoice)"
payment_request="$(echo $invoice_response | jq -r '.payment_request')"
payment_hash=$(echo $invoice_response | jq -r '.r_hash')
[[ "${payment_request}" != "null" ]] || exit 1

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg payment_request "$payment_request" \
--arg amount $usd_amount \
'{input: {walletId: $wallet_id, paymentRequest: $payment_request, amount: $amount}}'
)

exec_graphql "$token_name" 'ln-no-amount-usd-invoice-payment-send' "$variables"
send_status="$(graphql_output '.data.lnNoAmountUsdInvoicePaymentSend.status')"
[[ "${send_status}" = "SUCCESS" ]] || exit 1

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

final_balance="$(balance_for_wallet $token_name 'USD')"
wallet_diff="$(( $initial_balance - $final_balance ))"
[[ "$wallet_diff" == "$usd_amount" ]] || exit 1

final_lnd1_balance=$(lnd_cli channelbalance | jq -r '.balance')
lnd1_diff="$(( $initial_lnd1_balance - $final_lnd1_balance ))"
[[ "$lnd1_diff" -gt "0" ]] || exit 1
}
8 changes: 8 additions & 0 deletions bats/gql/ln-no-amount-invoice-fee-probe.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation lnNoAmountInvoiceFeeProbe($input: LnNoAmountInvoiceFeeProbeInput!) {
lnNoAmountInvoiceFeeProbe(input: $input) {
errors {
message
}
amount
}
}
8 changes: 8 additions & 0 deletions bats/gql/ln-no-amount-invoice-payment-send.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation lnNoAmountInvoicePaymentSend($input: LnNoAmountInvoicePaymentInput!) {
lnNoAmountInvoicePaymentSend(input: $input) {
errors {
message
}
status
}
}
8 changes: 8 additions & 0 deletions bats/gql/ln-no-amount-usd-invoice-fee-probe.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation lnNoAmountUsdInvoiceFeeProbe($input: LnNoAmountUsdInvoiceFeeProbeInput!) {
lnNoAmountUsdInvoiceFeeProbe(input: $input) {
errors {
message
}
amount
}
}
8 changes: 8 additions & 0 deletions bats/gql/ln-no-amount-usd-invoice-payment-send.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation lnNoAmountUsdInvoicePaymentSend($input: LnNoAmountUsdInvoicePaymentInput!) {
lnNoAmountUsdInvoicePaymentSend(input: $input) {
errors {
message
}
status
}
}
8 changes: 8 additions & 0 deletions bats/gql/ln-usd-invoice-fee-probe.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation lnUsdInvoiceFeeProbe($input: LnUsdInvoiceFeeProbeInput!) {
lnUsdInvoiceFeeProbe(input: $input) {
errors {
message
}
amount
}
}
Loading

0 comments on commit ff4e04f

Please sign in to comment.