Skip to content

Commit

Permalink
test: add lnd1 receive onchain e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Sep 19, 2023
1 parent 87648c9 commit 03dac92
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/bats/onchain-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,93 @@ create_new_lnd_onchain_address() {
retry 3 1 check_for_onchain_initiated_settled "$alice_token_name" "$alice_address_2" 2
retry 3 1 check_for_onchain_initiated_settled "$bob_token_name" "$bob_address_1" 1
}

@test "onchain-receive: process received batch transaction via legacy lnd" {
alice_token_name="$ALICE_TOKEN_NAME"
alice_btc_wallet_name="$alice_token_name.btc_wallet_id"
alice_usd_wallet_name="$alice_token_name.usd_wallet_id"

bob_token_name="$BOB_TOKEN_NAME"
bob_btc_wallet_name="$bob_token_name.btc_wallet_id"

amount="0.01"

# Get initial balances
lnd1_initial_balance=$(lnd_cli walletbalance | jq -r '.confirmed_balance')
bria_initial_balance=$( bria_cli wallet-balance -w dev-wallet | jq -r '.effectiveSettled')

# Create Alice addresses
alice_btc_address="$(create_new_lnd_onchain_address $alice_btc_wallet_name)"
current_btc_address_variables=$(
jq -n \
--arg wallet_id "$(read_value $alice_btc_wallet_name)" \
'{input: {walletId: $wallet_id}}'
)
exec_graphql "$alice_token_name" 'on-chain-address-current' "$current_btc_address_variables"
on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')"
[[ "${on_chain_address_current}" != "null" ]] || exit 1
[[ "${alice_btc_address}" == "${on_chain_address_current}" ]] || exit 1

alice_usd_address="$(create_new_lnd_onchain_address $alice_usd_wallet_name)"
current_usd_address_variables=$(
jq -n \
--arg wallet_id "$(read_value $alice_usd_wallet_name)" \
'{input: {walletId: $wallet_id}}'
)
exec_graphql "$alice_token_name" 'on-chain-address-current' "$current_usd_address_variables"
on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')"
[[ "${on_chain_address_current}" != "null" ]] || exit 1
[[ "${alice_usd_address}" == "${on_chain_address_current}" ]] || exit 1

# Create Bob addresses
bob_btc_address="$(create_new_lnd_onchain_address $bob_btc_wallet_name)"
current_btc_address_variables=$(
jq -n \
--arg wallet_id "$(read_value $bob_btc_wallet_name)" \
'{input: {walletId: $wallet_id}}'
)
exec_graphql "$bob_token_name" 'on-chain-address-current' "$current_btc_address_variables"
on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')"
[[ "${on_chain_address_current}" != "null" ]] || exit 1
[[ "${bob_btc_address}" == "${on_chain_address_current}" ]] || exit 1

# Create psbt & broadcast transaction
psbt_outputs=$(
jq -c -n \
--arg alice_btc_address "$alice_btc_address" \
--arg alice_usd_address "$alice_usd_address" \
--arg bob_btc_address "$bob_btc_address" \
--argjson amount "$amount" \
'{
($alice_btc_address): $amount,
($alice_usd_address): $amount,
($bob_btc_address): $amount
}'
)
unsigned_psbt=$(bitcoin_cli walletcreatefundedpsbt '[]' $psbt_outputs | jq -r '.psbt')
signed_psbt=$(bitcoin_cli walletprocesspsbt "$unsigned_psbt" | jq -r '.psbt')
tx_hex=$(bitcoin_cli finalizepsbt "$signed_psbt" | jq -r '.hex')
txid=$(bitcoin_cli sendrawtransaction "$tx_hex")

retry 15 1 check_for_broadcast "$alice_token_name" "$alice_btc_address" 10
retry 3 1 check_for_broadcast "$alice_token_name" "$alice_usd_address" 10
retry 3 1 check_for_broadcast "$bob_token_name" "$bob_btc_address" 10

# Mine transactions
# Note: subscription event operates delayed from lnd1 state
bitcoin_cli -generate 2
sleep 1
bitcoin_cli -generate 2
sleep 1
bitcoin_cli -generate 2

retry 15 1 check_for_onchain_initiated_settled "$alice_token_name" "$alice_btc_address" 10
retry 3 1 check_for_onchain_initiated_settled "$alice_token_name" "$alice_usd_address" 10
retry 3 1 check_for_onchain_initiated_settled "$bob_token_name" "$bob_btc_address" 10

# Check final balances
lnd1_final_balance=$(lnd_cli walletbalance | jq -r '.confirmed_balance')
[[ "$lnd1_final_balance" -gt "$lnd1_initial_balance" ]] || exit 1
bria_final_balance=$( bria_cli wallet-balance -w dev-wallet | jq -r '.effectiveSettled')
[[ "$bria_final_balance" == "$bria_initial_balance" ]] || exit 1
}

0 comments on commit 03dac92

Please sign in to comment.