Skip to content

Commit

Permalink
chore: update flake and onchain receive bats
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Sep 26, 2024
1 parent f94c16a commit d464380
Show file tree
Hide file tree
Showing 6 changed files with 18,051 additions and 16,267 deletions.
176 changes: 88 additions & 88 deletions bats/core/api/onchain-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,92 @@ teardown() {
fi
}

@test "onchain-receive: process received batch transaction via legacy lnd" {
alice_btc_wallet_name="alice.btc_wallet_id"
alice_usd_wallet_name="alice.usd_wallet_id"
bob_btc_wallet_name="bob.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' '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' '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' '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 45 1 check_for_incoming_broadcast 'alice' "$alice_btc_address"
retry 3 1 check_for_incoming_broadcast 'alice' "$alice_usd_address"
retry 3 1 check_for_incoming_broadcast 'bob' "$bob_btc_address"

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

retry 45 1 check_for_onchain_initiated_settled 'alice' "$alice_btc_address" 10
retry 3 1 check_for_onchain_initiated_settled 'alice' "$alice_usd_address" 10
retry 3 1 check_for_onchain_initiated_settled 'bob' "$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
}

@test "onchain-receive: btc wallet, can create new address if current one is unused" {
btc_wallet_name="alice.btc_wallet_id"

Expand Down Expand Up @@ -128,7 +214,7 @@ teardown() {
)
pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')"
[[ "$pending_txns_for_account_length" == "2" ]] || exit 1

# Mine transactions
bitcoin_cli -generate 2
retry 30 1 check_for_onchain_initiated_settled 'alice' "$on_chain_address_created_1" 2
Expand Down Expand Up @@ -270,7 +356,7 @@ teardown() {
.data.me.defaultAccount.pendingIncomingTransactions'
)
pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')"
[[ "$pending_txns_for_account_length" == "0" ]] || exit 1
[[ "$pending_txns_for_account_length" == "0" ]] || exit 1
}

@test "onchain-receive: process received batch transaction" {
Expand Down Expand Up @@ -349,89 +435,3 @@ teardown() {
retry 3 1 check_for_onchain_initiated_settled 'alice' "$alice_address_2" 2
retry 3 1 check_for_onchain_initiated_settled 'bob' "$bob_address_1" 1
}

@test "onchain-receive: process received batch transaction via legacy lnd" {
alice_btc_wallet_name="alice.btc_wallet_id"
alice_usd_wallet_name="alice.usd_wallet_id"
bob_btc_wallet_name="bob.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' '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' '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' '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 45 1 check_for_incoming_broadcast 'alice' "$alice_btc_address"
retry 3 1 check_for_incoming_broadcast 'alice' "$alice_usd_address"
retry 3 1 check_for_incoming_broadcast 'bob' "$bob_btc_address"

# Mine transactions
# Note: subscription event operates in a delayed way 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' "$alice_btc_address" 10
retry 3 1 check_for_onchain_initiated_settled 'alice' "$alice_usd_address" 10
retry 3 1 check_for_onchain_initiated_settled 'bob' "$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
}
16 changes: 0 additions & 16 deletions bats/helpers/onchain.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ fund_user_onchain() {
retry 30 1 check_for_onchain_initiated_settled "$token_name" "$address"
}

check_for_onchain_initiated_settled() {
local token_name=$1
local address=$2
local first=${3:-"1"}

variables=$(
jq -n \
--argjson first "$first" \
'{"first": $first}'
)
exec_graphql "$token_name" 'transactions' "$variables"

settled_status="$(get_from_transaction_by_address $address '.status')"
[[ "${settled_status}" = "SUCCESS" ]] || exit 1
}

get_from_transaction_by_address() {
property_query=$2

Expand Down
27 changes: 12 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (system: let
# Define pkgs first before applying overlays
basePkgs = import nixpkgs { system = system; };

overlays = [
(self: super: {
nodejs = super.nodejs_20;
pnpm = super.nodePackages.pnpm;
nodejs = basePkgs.nodejs_20; # Reference nodejs from basePkgs to avoid recursion
pnpm = basePkgs.nodePackages.pnpm;
})
(import rust-overlay)
];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"engines": {
"node": "20",
"pnpm": "8"
"pnpm": "9"
},
"resolutions": {
"@types/ws": "^8.5.12",
Expand Down
Loading

0 comments on commit d464380

Please sign in to comment.