Skip to content

Commit

Permalink
chore: address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Nov 29, 2023
1 parent 50d0dfb commit 436ece7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
18 changes: 9 additions & 9 deletions bats/core/api/onchain-receive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ setup_file() {
[[ "${on_chain_address_created_1}" != "null" ]] || exit 1

bitcoin_cli sendtoaddress "$on_chain_address_created_1" "$amount"
retry 15 1 check_for_broadcast 'alice' "$on_chain_address_created_1"
retry 15 1 check_for_incoming_broadcast 'alice' "$on_chain_address_created_1"

# Create address and broadcast transaction 2
exec_graphql 'alice' 'on-chain-address-create' "$variables"
on_chain_address_created_2="$(graphql_output '.data.onChainAddressCreate.address')"
[[ "${on_chain_address_created_2}" != "null" ]] || exit 1

bitcoin_cli sendtoaddress "$on_chain_address_created_2" "$amount"
retry 15 1 check_for_broadcast 'alice' "$on_chain_address_created_2"
retry 15 1 check_for_incoming_broadcast 'alice' "$on_chain_address_created_2"

# Check pending transactions for address 1
address_1_pending_txns_variables=$(
Expand Down Expand Up @@ -224,7 +224,7 @@ setup_file() {

# Execute onchain send and check for transaction
bitcoin_cli sendtoaddress "$on_chain_address_created" "$amount"
retry 15 1 check_for_broadcast 'alice' "$on_chain_address_created"
retry 15 1 check_for_incoming_broadcast 'alice' "$on_chain_address_created"

# Check pending transactions for address
address_pending_txns_variables=$(
Expand Down Expand Up @@ -315,9 +315,9 @@ setup_file() {
tx_hex=$(bitcoin_cli finalizepsbt "$signed_psbt" | jq -r '.hex')
txid=$(bitcoin_cli sendrawtransaction "$tx_hex")

retry 15 1 check_for_broadcast 'alice' "$alice_address_1"
retry 3 1 check_for_broadcast 'alice' "$alice_address_2"
retry 3 1 check_for_broadcast 'bob' "$bob_address_1"
retry 15 1 check_for_incoming_broadcast 'alice' "$alice_address_1"
retry 3 1 check_for_incoming_broadcast 'alice' "$alice_address_2"
retry 3 1 check_for_incoming_broadcast 'bob' "$bob_address_1"

# Check 'pendingIncomingBalance' query
exec_graphql 'alice' 'wallets-for-account'
Expand Down Expand Up @@ -406,9 +406,9 @@ setup_file() {
tx_hex=$(bitcoin_cli finalizepsbt "$signed_psbt" | jq -r '.hex')
txid=$(bitcoin_cli sendrawtransaction "$tx_hex")

retry 45 1 check_for_broadcast 'alice' "$alice_btc_address"
retry 3 1 check_for_broadcast 'alice' "$alice_usd_address"
retry 3 1 check_for_broadcast 'bob' "$bob_btc_address"
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
Expand Down
2 changes: 1 addition & 1 deletion bats/helpers/onchain.bash
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ get_from_pending_transaction_by_address() {
| jq -r "$property_query"
}

check_for_broadcast() {
check_for_incoming_broadcast() {
local token_name=$1
local address=$2

Expand Down
38 changes: 0 additions & 38 deletions core/api/test/bats/helpers/onchain.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,6 @@ get_from_pending_transaction_by_address() {
| jq -r "$property_query"
}

check_for_broadcast() {
local token_name=$1
local address=$2

exec_graphql "$token_name" 'pending-incoming-transactions'

tx="$(get_from_pending_transaction_by_address "$address" '.')"
[[ -n "${tx}" && "${tx}" != "null" ]] || exit 1
txid="$(echo $tx | jq -r '.settlementVia.transactionHash')"
[[ "${txid}" != "null" ]] || exit 1
status="$(echo $tx | jq -r '.status')"
[[ "${status}" == "PENDING" ]] || exit 1

bitcoin_cli gettransaction "$txid" || exit 1
}

check_for_outgoing_broadcast() {
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"

tx="$(get_from_transaction_by_address "$address" '.')"
[[ -n "${tx}" && "${tx}" != "null" ]] || exit 1
txid="$(echo $tx | jq -r '.settlementVia.transactionHash')"
[[ "${txid}" != "null" ]] || exit 1
status="$(echo $tx | jq -r '.status')"
[[ "${status}" == "PENDING" ]] || exit 1

bitcoin_cli gettransaction "$txid" || exit 1
}

check_for_onchain_initiated_settled() {
local token_name=$1
local address=$2
Expand Down

0 comments on commit 436ece7

Please sign in to comment.