Skip to content

Commit

Permalink
test: move ln tests to top level bats (#3719) (#3744)
Browse files Browse the repository at this point in the history
This reverts commit 2d849fd.
  • Loading branch information
vindard committed Dec 22, 2023
1 parent 4795a14 commit f1aea45
Show file tree
Hide file tree
Showing 35 changed files with 1,591 additions and 671 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
//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/**
. ./.env && nix develop -c bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/**
- name: Rename Tilt log
if: always()
run: mv bats/.e2e-tilt.log bats/e2e-tilt.log
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,48 @@
#!/usr/bin/env bats

load "helpers/setup-and-teardown"
load "helpers/ln"
load "../../helpers/callback.bash"
load "../../helpers/cli.bash"
load "../../helpers/ledger.bash"
load "../../helpers/ln.bash"
load "../../helpers/onchain.bash"
load "../../helpers/subscriber.bash"
load "../../helpers/trigger.bash"
load "../../helpers/user.bash"

setup_file() {
clear_cache

bitcoind_init
start_trigger
start_ws_server
start_server
start_exporter
start_callback
ALICE='alice'

lnds_init

login_user "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE"
add_callback "$ALICE_TOKEN_NAME"
initialize_user_from_onchain "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE"
setup_file() {
create_user "$ALICE"
add_callback "$ALICE"
fund_user_onchain "$ALICE" 'btc_wallet'

subscribe_to "$ALICE_TOKEN_NAME" my-updates-sub
sleep 3
subscribe_to "$ALICE" my-updates-sub
retry 10 1 subscriber_is_up
}

teardown_file() {
stop_trigger
stop_server
stop_ws_server
stop_exporter
stop_subscriber
stop_callback
}

setup() {
reset_redis
}

teardown() {
if [[ "$(balance_for_check)" != 0 ]]; then
fail "Error: balance_for_check failed"
fi

}

btc_amount=1000
usd_amount=50

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

# Check callback events before
exec_graphql "$token_name" 'account-details'
exec_graphql "$token_name" 'default-account'
account_id="$(graphql_output '.data.me.defaultAccount.id')"
[[ "$account_id" != "null" ]] || exit 1

num_callback_events_before=$(cat .e2e-callback.log | grep "$account_id" | wc -l)
num_callback_events_before=$(cat_callback | grep "$account_id" | wc -l)

# Generate invoice
variables=$(
Expand Down Expand Up @@ -135,15 +122,14 @@ usd_amount=50
invoice_status="$(graphql_output '.data.me.defaultAccount.walletById.invoiceByPaymentHash.paymentStatus')"
[[ "${invoice_status}" == "PAID" ]] || exit 1


# Check for callback
num_callback_events_after=$(cat .e2e-callback.log | grep "$account_id" | wc -l)
num_callback_events_after=$(cat_callback | grep "$account_id" | wc -l)
[[ "$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_TOKEN_NAME"
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

variables=$(
Expand Down Expand Up @@ -172,7 +158,7 @@ usd_amount=50
}

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

# Generate invoice
Expand Down Expand Up @@ -202,7 +188,7 @@ usd_amount=50
}

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

# Generate amountless invoice
Expand Down Expand Up @@ -248,7 +234,7 @@ usd_amount=50

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

variables=$(
Expand Down Expand Up @@ -277,11 +263,12 @@ usd_amount=50
}

@test "ln-receive: settles btc-wallet invoices created while trigger down" {
token_name="$ALICE_TOKEN_NAME"
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

# Stop trigger
stop_trigger
touch $TRIGGER_STOP_FILE
retry 10 1 trigger_is_stopped || exit 1

# Generate invoice
variables=$(
Expand All @@ -298,8 +285,8 @@ usd_amount=50
[[ "${payment_hash}" != "null" ]] || exit 1

# Start trigger
start_trigger
sleep 5
rm $TRIGGER_STOP_FILE
retry 10 1 trigger_is_started

# Pay invoice & check for settled
lnd_outside_cli payinvoice -f \
Expand All @@ -310,11 +297,12 @@ usd_amount=50
}

@test "ln-receive: settles usd-wallet invoices created while trigger down" {
token_name="$ALICE_TOKEN_NAME"
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

# Stop trigger
stop_trigger
touch $TRIGGER_STOP_FILE
retry 10 1 trigger_is_stopped || exit 1

# Generate invoice
variables=$(
Expand All @@ -331,8 +319,8 @@ usd_amount=50
[[ "${payment_hash}" != "null" ]] || exit 1

# Start trigger
start_trigger
sleep 5
rm $TRIGGER_STOP_FILE
retry 10 1 trigger_is_started

# Pay invoice & check for settled
lnd_outside_cli payinvoice -f \
Expand All @@ -343,11 +331,11 @@ usd_amount=50
}

@test "ln-receive: settles btc-wallet invoices created & paid while trigger down" {
token_name="$ALICE_TOKEN_NAME"
token_name="$ALICE"
btc_wallet_name="$token_name.btc_wallet_id"

# Stop trigger
stop_trigger
touch $TRIGGER_STOP_FILE

# Generate invoice
variables=$(
Expand All @@ -370,18 +358,18 @@ usd_amount=50
&

# Start trigger
start_trigger
rm $TRIGGER_STOP_FILE

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

@test "ln-receive: settles usd-wallet invoices created & paid while trigger down" {
token_name="$ALICE_TOKEN_NAME"
token_name="$ALICE"
usd_wallet_name="$token_name.usd_wallet_id"

# Stop trigger
stop_trigger
touch $TRIGGER_STOP_FILE

# Generate invoice
variables=$(
Expand All @@ -404,7 +392,7 @@ usd_amount=50
&

# Start trigger
start_trigger
rm $TRIGGER_STOP_FILE

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

0 comments on commit f1aea45

Please sign in to comment.