From c2fe8f6482f120b4f7efb4c71cd36c53e29b77b5 Mon Sep 17 00:00:00 2001 From: Sandipan Dey Date: Thu, 16 Nov 2023 12:36:46 +0530 Subject: [PATCH] refactor: recieve half working --- bats/core/api/onchain-receive.bats | 343 +++++++++++++++++++ bats/gql/on-chain-address-current.gql | 8 + bats/gql/pending-transactions-by-address.gql | 56 +++ bats/gql/pending-transactions.gql | 51 +++ bats/gql/transactions-by-address.gql | 68 ++++ core/api/test/bats/onchain-receive.bats | 260 -------------- 6 files changed, 526 insertions(+), 260 deletions(-) create mode 100644 bats/core/api/onchain-receive.bats create mode 100644 bats/gql/on-chain-address-current.gql create mode 100644 bats/gql/pending-transactions-by-address.gql create mode 100644 bats/gql/pending-transactions.gql create mode 100644 bats/gql/transactions-by-address.gql diff --git a/bats/core/api/onchain-receive.bats b/bats/core/api/onchain-receive.bats new file mode 100644 index 00000000000..3c27028a863 --- /dev/null +++ b/bats/core/api/onchain-receive.bats @@ -0,0 +1,343 @@ +#!/usr/bin/env bats + +load "../../helpers/cli.bash" +load "../../helpers/user.bash" +load "../../helpers/funding/onchain.bash" +load "../../helpers/funding/wallet.bash" + +setup_file() { + create_user 'alice' + user_update_username 'alice' + fund_user_onchain 'alice' 'btc_wallet' + fund_user_onchain 'alice' 'usd_wallet' + + create_user 'bob' + user_update_username 'bob' + fund_user_onchain 'bob' 'btc_wallet' + fund_user_onchain 'bob' 'usd_wallet' +} + +@test "onchain-receive: btc wallet, can create new address if current one is unused" { + btc_wallet_name="alice.btc_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + + # Create address + exec_graphql 'alice' 'on-chain-address-create' "$variables" + on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${on_chain_address_created}" != "null" ]] || exit 1 + + # Fetch current address + exec_graphql 'alice' 'on-chain-address-current' "$variables" + on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" + [[ "${on_chain_address_current}" != "null" ]] || exit 1 + [[ "${on_chain_address_created}" == "${on_chain_address_current}" ]] || exit 1 + + # Create new address + exec_graphql 'alice' 'on-chain-address-create' "$variables" + retry_on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${retry_on_chain_address_created}" != "null" ]] || exit 1 + [[ "${on_chain_address_created}" != "${retry_on_chain_address_created}" ]] || exit 1 + + # Fetch new current address + exec_graphql 'alice' 'on-chain-address-current' "$variables" + retry_on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" + [[ "${retry_on_chain_address_current}" != "null" ]] || exit 1 + [[ "${retry_on_chain_address_created}" == "${retry_on_chain_address_current}" ]] || exit 1 +} + +@test "onchain-receive: settle onchain for BTC wallet, query by address" { + btc_wallet_name="alice.btc_wallet_id" + amount="0.01" + + # Create address and broadcast transaction 1 + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + + exec_graphql 'alice' 'on-chain-address-create' "$variables" + on_chain_address_created_1="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${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" 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" 1 + + # Check pending transactions for address 1 + address_1_pending_txns_variables=$( + jq -n \ + --arg address "$on_chain_address_created_1" \ + '{"address": $address}' + ) + exec_graphql 'alice' 'pending-transactions-by-address' "$address_1_pending_txns_variables" + pending_txns_for_address_1=$( + graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.__typename == "BTCWallet") + .pendingTransactionsByAddress' + ) + pending_txns_for_address_1_length="$(echo $pending_txns_for_address_1 | jq -r 'length')" + [[ "$pending_txns_for_address_1_length" == "1" ]] || exit 1 + address_1_from_pending_txns="$(echo $pending_txns_for_address_1 | jq -r '.[0].initiationVia.address')" + [[ "$address_1_from_pending_txns" == "$on_chain_address_created_1" ]] + + # Check pending transactions for address 2 + address_2_pending_txns_variables=$( + jq -n \ + --arg address "$on_chain_address_created_2" \ + '{"address": $address}' + ) + exec_graphql 'alice' 'pending-transactions-by-address' "$address_2_pending_txns_variables" + pending_txns_for_address_2=$( + graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.__typename == "BTCWallet") + .pendingTransactionsByAddress' + ) + pending_txns_for_address_2_length="$(echo $pending_txns_for_address_2 | jq -r 'length')" + [[ "$pending_txns_for_address_2_length" == "1" ]] || exit 1 + address_2_from_pending_txns="$(echo $pending_txns_for_address_2 | jq -r '.[0].initiationVia.address')" + [[ "$address_2_from_pending_txns" == "$on_chain_address_created_2" ]] + + # Check pending transactions for account + exec_graphql 'alice' 'pending-transactions' + pending_txns_for_account=$( + graphql_output ' + .data.me.defaultAccount.pendingTransactions' + ) + 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 15 1 check_for_onchain_initiated_settled 'alice' "$on_chain_address_created_1" 2 + retry 3 1 check_for_onchain_initiated_settled 'alice' "$on_chain_address_created_2" 2 + + # Check transactions for address 1 + address_1_variables=$( + jq -n \ + --argjson first "10" \ + --arg address "$on_chain_address_created_1" \ + '{"first": $first, "address": $address}' + ) + exec_graphql 'alice' 'transactions-by-address' "$address_1_variables" + txns_for_address_1=$( + graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.__typename == "BTCWallet") + .transactionsByAddress.edges' + ) + txns_for_address_1_length="$(echo $txns_for_address_1 | jq -r 'length')" + [[ "$txns_for_address_1_length" == "1" ]] || exit 1 + address_1_from_txns="$(echo $txns_for_address_1 | jq -r '.[0].node.initiationVia.address')" + [[ "$address_1_from_txns" == "$on_chain_address_created_1" ]] + + # Check transactions for address 2 + address_2_variables=$( + jq -n \ + --argjson first "10" \ + --arg address "$on_chain_address_created_2" \ + '{"first": $first, "address": $address}' + ) + exec_graphql 'alice' 'transactions-by-address' "$address_2_variables" + txns_for_address_2=$( + graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.__typename == "BTCWallet") + .transactionsByAddress.edges' + ) + txns_for_address_2_length="$(echo $txns_for_address_2 | jq -r 'length')" + [[ "$txns_for_address_2_length" == "1" ]] || exit 1 + address_2_from_txns="$(echo $txns_for_address_2 | jq -r '.[0].node.initiationVia.address')" + [[ "$address_2_from_txns" == "$on_chain_address_created_2" ]] + + # Ensure no pending transactions for account + exec_graphql 'alice' 'pending-transactions' + pending_txns_for_account=$( + graphql_output ' + .data.me.defaultAccount.pendingTransactions' + ) + pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')" + [[ "$pending_txns_for_account_length" == "0" ]] || exit 1 +} + +@test "onchain-receive: usd wallet, can create new address if current one is unused" { + usd_wallet_name="alice.usd_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + + # Create address + exec_graphql 'alice' 'on-chain-address-create' "$variables" + on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${on_chain_address_created}" != "null" ]] || exit 1 + + # Fetch current address + exec_graphql 'alice' 'on-chain-address-current' "$variables" + on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" + [[ "${on_chain_address_current}" != "null" ]] || exit 1 + [[ "${on_chain_address_created}" == "${on_chain_address_current}" ]] || exit 1 + + # Create new address + exec_graphql 'alice' 'on-chain-address-create' "$variables" + retry_on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${retry_on_chain_address_created}" != "null" ]] || exit 1 + [[ "${on_chain_address_created}" != "${retry_on_chain_address_created}" ]] || exit 1 + + # Fetch new current address + exec_graphql 'alice' 'on-chain-address-current' "$variables" + retry_on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" + [[ "${retry_on_chain_address_current}" != "null" ]] || exit 1 + [[ "${retry_on_chain_address_created}" == "${retry_on_chain_address_current}" ]] || exit 1 +} + +@test "onchain-receive: settle onchain for USD wallet" { + usd_wallet_name="alice.usd_wallet_id" + amount="0.01" + + # Create address + variables=$( + jq -n \ + --arg wallet_id "$(read_value $usd_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + exec_graphql 'alice' 'on-chain-address-create' "$variables" + on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${on_chain_address_created}" != "null" ]] || exit 1 + + # 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" 1 + + # Check pending transactions for address + address_pending_txns_variables=$( + jq -n \ + --arg address "$on_chain_address_created" \ + '{"address": $address}' + ) + exec_graphql 'alice' 'pending-transactions-by-address' "$address_pending_txns_variables" + pending_txns_for_address=$( + graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.__typename == "UsdWallet") + .pendingTransactionsByAddress' + ) + pending_txns_for_address_length="$(echo $pending_txns_for_address | jq -r 'length')" + [[ "$pending_txns_for_address_length" == "1" ]] || exit 1 + address_from_pending_txns="$(echo $pending_txns_for_address | jq -r '.[0].initiationVia.address')" + [[ "$address_from_pending_txns" == "$on_chain_address_created" ]] + + # Check pending transactions for account + exec_graphql 'alice' 'pending-transactions' + pending_txns_for_account=$( + graphql_output ' + .data.me.defaultAccount.pendingTransactions' + ) + pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')" + [[ "$pending_txns_for_account_length" == "1" ]] || exit 1 + + bitcoin_cli -generate 2 + retry 15 1 check_for_onchain_initiated_settled 'alice' "$on_chain_address_created" 1 + + # Ensure no pending transactions for account + exec_graphql 'alice' 'pending-transactions' + pending_txns_for_account=$( + graphql_output ' + .data.me.defaultAccount.pendingTransactions' + ) + pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')" + [[ "$pending_txns_for_account_length" == "0" ]] || exit 1 +} + +@test "onchain-receive: process received batch transaction" { + alice_btc_wallet_name="alice.btc_wallet_id" + bob_usd_wallet_name="bob.usd_wallet_id" + amount="0.01" + + # Create Alice addresses + alice_variables=$( + jq -n \ + --arg wallet_id "$(read_value $alice_btc_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + + exec_graphql 'alice' 'on-chain-address-create' "$alice_variables" + alice_address_1="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${alice_address_1}" != "null" ]] || exit 1 + + exec_graphql 'alice' 'on-chain-address-create' "$alice_variables" + alice_address_2="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${alice_address_2}" != "null" ]] || exit 1 + + # Create Bob addresses + bob_variables=$( + jq -n \ + --arg wallet_id "$(read_value $bob_usd_wallet_name)" \ + '{input: {walletId: $wallet_id}}' + ) + + exec_graphql 'bob' 'on-chain-address-create' "$bob_variables" + bob_address_1="$(graphql_output '.data.onChainAddressCreate.address')" + [[ "${bob_address_1}" != "null" ]] || exit 1 + + # Create psbt & broadcast transaction + psbt_outputs=$( + jq -c -n \ + --arg alice_address_1 "$alice_address_1" \ + --arg alice_address_2 "$alice_address_2" \ + --arg bob_address_1 "$bob_address_1" \ + --argjson amount "$amount" \ + '{ + ($alice_address_1): $amount, + ($alice_address_2): $amount, + ($bob_address_1): $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' "$alice_address_1" 2 + retry 3 1 check_for_broadcast 'alice' "$alice_address_2" 2 + retry 3 1 check_for_broadcast 'bob' "$bob_address_1" 1 + + # Check 'pendingIncomingBalance' query + exec_graphql 'alice' 'wallets-for-account' + alice_btc_pending_incoming=$(graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.walletCurrency == "BTC") + .pendingIncomingBalance + ') + [[ "$alice_btc_pending_incoming" -gt 0 ]] || exit 1 + + exec_graphql 'bob' 'wallets-for-account' + bob_usd_pending_incoming=$(graphql_output ' + .data.me.defaultAccount.wallets[] + | select(.walletCurrency == "USD") + .pendingIncomingBalance + ') + [[ "$bob_usd_pending_incoming" -gt 0 ]] || exit 1 + + # Mine transactions + bitcoin_cli -generate 2 + retry 15 1 check_for_onchain_initiated_settled 'alice' "$alice_address_1" 2 + 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 +} diff --git a/bats/gql/on-chain-address-current.gql b/bats/gql/on-chain-address-current.gql new file mode 100644 index 00000000000..f6d82f37bb1 --- /dev/null +++ b/bats/gql/on-chain-address-current.gql @@ -0,0 +1,8 @@ +mutation onChainAddressCurrent($input: OnChainAddressCurrentInput!) { + onChainAddressCurrent(input: $input) { + address + errors { + message + } + } +} diff --git a/bats/gql/pending-transactions-by-address.gql b/bats/gql/pending-transactions-by-address.gql new file mode 100644 index 00000000000..a31fa42a2a7 --- /dev/null +++ b/bats/gql/pending-transactions-by-address.gql @@ -0,0 +1,56 @@ +query pendingTransactionsByAddress($address: OnChainAddress!) { + me { + defaultAccount { + displayCurrency + wallets { + __typename + id + walletCurrency + pendingTransactionsByAddress(address: $address) { + __typename + id + status + direction + memo + createdAt + settlementAmount + settlementFee + settlementDisplayAmount + settlementDisplayFee + settlementDisplayCurrency + settlementCurrency + settlementPrice { + base + offset + } + initiationVia { + __typename + ... on InitiationViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on InitiationViaLn { + paymentHash + } + ... on InitiationViaOnChain { + address + } + } + settlementVia { + __typename + ... on SettlementViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on SettlementViaLn { + preImage + } + ... on SettlementViaOnChain { + transactionHash + } + } + } + } + } + } +} diff --git a/bats/gql/pending-transactions.gql b/bats/gql/pending-transactions.gql new file mode 100644 index 00000000000..bc26c2985a4 --- /dev/null +++ b/bats/gql/pending-transactions.gql @@ -0,0 +1,51 @@ +query pendingTransactions { + me { + defaultAccount { + displayCurrency + pendingTransactions { + __typename + id + status + direction + memo + createdAt + settlementAmount + settlementFee + settlementDisplayAmount + settlementDisplayFee + settlementDisplayCurrency + settlementCurrency + settlementPrice { + base + offset + } + initiationVia { + __typename + ... on InitiationViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on InitiationViaLn { + paymentHash + } + ... on InitiationViaOnChain { + address + } + } + settlementVia { + __typename + ... on SettlementViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on SettlementViaLn { + preImage + } + ... on SettlementViaOnChain { + transactionHash + } + } + } + } + } +} diff --git a/bats/gql/transactions-by-address.gql b/bats/gql/transactions-by-address.gql new file mode 100644 index 00000000000..00ff80989a4 --- /dev/null +++ b/bats/gql/transactions-by-address.gql @@ -0,0 +1,68 @@ +query transactionsByAddress($first: Int, $after: String, $address: OnChainAddress!) { + me { + defaultAccount { + displayCurrency + wallets { + __typename + id + walletCurrency + transactionsByAddress(first: $first, after: $after, address: $address) { + ...TransactionList + } + } + } + } +} + +fragment TransactionList on TransactionConnection { + pageInfo { + hasNextPage + } + edges { + cursor + node { + __typename + id + status + direction + memo + createdAt + settlementAmount + settlementFee + settlementDisplayAmount + settlementDisplayFee + settlementDisplayCurrency + settlementCurrency + settlementPrice { + base + offset + } + initiationVia { + __typename + ... on InitiationViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on InitiationViaLn { + paymentHash + } + ... on InitiationViaOnChain { + address + } + } + settlementVia { + __typename + ... on SettlementViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on SettlementViaLn { + preImage + } + ... on SettlementViaOnChain { + transactionHash + } + } + } + } +} diff --git a/core/api/test/bats/onchain-receive.bats b/core/api/test/bats/onchain-receive.bats index 609a44618aa..c493dc0318a 100644 --- a/core/api/test/bats/onchain-receive.bats +++ b/core/api/test/bats/onchain-receive.bats @@ -59,266 +59,6 @@ create_new_lnd_onchain_address() { echo $address } -@test "onchain-receive: btc wallet, can create new address if current one is unused" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - - # Create address - exec_graphql "$token_name" 'on-chain-address-create' "$variables" - on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" - [[ "${on_chain_address_created}" != "null" ]] || exit 1 - - # Fetch current address - exec_graphql "$token_name" 'on-chain-address-current' "$variables" - on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" - [[ "${on_chain_address_current}" != "null" ]] || exit 1 - [[ "${on_chain_address_created}" == "${on_chain_address_current}" ]] || exit 1 - - # Create new address - exec_graphql "$token_name" 'on-chain-address-create' "$variables" - retry_on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" - [[ "${retry_on_chain_address_created}" != "null" ]] || exit 1 - [[ "${on_chain_address_created}" != "${retry_on_chain_address_created}" ]] || exit 1 - - # Fetch new current address - exec_graphql "$token_name" 'on-chain-address-current' "$variables" - retry_on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" - [[ "${retry_on_chain_address_current}" != "null" ]] || exit 1 - [[ "${retry_on_chain_address_created}" == "${retry_on_chain_address_current}" ]] || exit 1 -} - -@test "onchain-receive: settle onchain for BTC wallet, query by address" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - amount="0.01" - - # Create address and broadcast transaction 1 - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - - exec_graphql "$token_name" 'on-chain-address-create' "$variables" - on_chain_address_created_1="$(graphql_output '.data.onChainAddressCreate.address')" - [[ "${on_chain_address_created_1}" != "null" ]] || exit 1 - - bitcoin_cli sendtoaddress "$on_chain_address_created_1" "$amount" - retry 15 1 check_for_broadcast "$token_name" "$on_chain_address_created_1" 1 - - # Create address and broadcast transaction 2 - exec_graphql "$token_name" '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 "$token_name" "$on_chain_address_created_2" 1 - - # Check pending transactions for address 1 - - address_1_pending_txns_variables=$( - jq -n \ - --arg address "$on_chain_address_created_1" \ - '{"address": $address}' - ) - exec_graphql "$token_name" 'pending-transactions-by-address' "$address_1_pending_txns_variables" - pending_txns_for_address_1=$( - graphql_output ' - .data.me.defaultAccount.wallets[] - | select(.__typename == "BTCWallet") - .pendingTransactionsByAddress' - ) - pending_txns_for_address_1_length="$(echo $pending_txns_for_address_1 | jq -r 'length')" - [[ "$pending_txns_for_address_1_length" == "1" ]] || exit 1 - address_1_from_pending_txns="$(echo $pending_txns_for_address_1 | jq -r '.[0].initiationVia.address')" - [[ "$address_1_from_pending_txns" == "$on_chain_address_created_1" ]] - - # Check pending transactions for address 2 - - address_2_pending_txns_variables=$( - jq -n \ - --arg address "$on_chain_address_created_2" \ - '{"address": $address}' - ) - exec_graphql "$token_name" 'pending-transactions-by-address' "$address_2_pending_txns_variables" - pending_txns_for_address_2=$( - graphql_output ' - .data.me.defaultAccount.wallets[] - | select(.__typename == "BTCWallet") - .pendingTransactionsByAddress' - ) - pending_txns_for_address_2_length="$(echo $pending_txns_for_address_2 | jq -r 'length')" - [[ "$pending_txns_for_address_2_length" == "1" ]] || exit 1 - address_2_from_pending_txns="$(echo $pending_txns_for_address_2 | jq -r '.[0].initiationVia.address')" - [[ "$address_2_from_pending_txns" == "$on_chain_address_created_2" ]] - - # Check pending transactions for account - - exec_graphql "$token_name" 'pending-transactions' - pending_txns_for_account=$( - graphql_output ' - .data.me.defaultAccount.pendingTransactions' - ) - 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 15 1 check_for_onchain_initiated_settled "$token_name" "$on_chain_address_created_1" 2 - retry 3 1 check_for_onchain_initiated_settled "$token_name" "$on_chain_address_created_2" 2 - - # Check transactions for address 1 - address_1_variables=$( - jq -n \ - --argjson first "10" \ - --arg address "$on_chain_address_created_1" \ - '{"first": $first, "address": $address}' - ) - exec_graphql "$token_name" 'transactions-by-address' "$address_1_variables" - txns_for_address_1=$( - graphql_output ' - .data.me.defaultAccount.wallets[] - | select(.__typename == "BTCWallet") - .transactionsByAddress.edges' - ) - txns_for_address_1_length="$(echo $txns_for_address_1 | jq -r 'length')" - [[ "$txns_for_address_1_length" == "1" ]] || exit 1 - address_1_from_txns="$(echo $txns_for_address_1 | jq -r '.[0].node.initiationVia.address')" - [[ "$address_1_from_txns" == "$on_chain_address_created_1" ]] - - # Check transactions for address 2 - address_2_variables=$( - jq -n \ - --argjson first "10" \ - --arg address "$on_chain_address_created_2" \ - '{"first": $first, "address": $address}' - ) - exec_graphql "$token_name" 'transactions-by-address' "$address_2_variables" - txns_for_address_2=$( - graphql_output ' - .data.me.defaultAccount.wallets[] - | select(.__typename == "BTCWallet") - .transactionsByAddress.edges' - ) - txns_for_address_2_length="$(echo $txns_for_address_2 | jq -r 'length')" - [[ "$txns_for_address_2_length" == "1" ]] || exit 1 - address_2_from_txns="$(echo $txns_for_address_2 | jq -r '.[0].node.initiationVia.address')" - [[ "$address_2_from_txns" == "$on_chain_address_created_2" ]] - - # Ensure no pending transactions for account - - exec_graphql "$token_name" 'pending-transactions' - pending_txns_for_account=$( - graphql_output ' - .data.me.defaultAccount.pendingTransactions' - ) - pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')" - [[ "$pending_txns_for_account_length" == "0" ]] || exit 1 -} - -@test "onchain-receive: usd wallet, can create new address if current one is unused" { - token_name="$ALICE_TOKEN_NAME" - usd_wallet_name="$token_name.usd_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - - # Create address - exec_graphql "$token_name" 'on-chain-address-create' "$variables" - on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" - [[ "${on_chain_address_created}" != "null" ]] || exit 1 - - # Fetch current address - exec_graphql "$token_name" 'on-chain-address-current' "$variables" - on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" - [[ "${on_chain_address_current}" != "null" ]] || exit 1 - [[ "${on_chain_address_created}" == "${on_chain_address_current}" ]] || exit 1 - - # Create new address - exec_graphql "$token_name" 'on-chain-address-create' "$variables" - retry_on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" - [[ "${retry_on_chain_address_created}" != "null" ]] || exit 1 - [[ "${on_chain_address_created}" != "${retry_on_chain_address_created}" ]] || exit 1 - - # Fetch new current address - exec_graphql "$token_name" 'on-chain-address-current' "$variables" - retry_on_chain_address_current="$(graphql_output '.data.onChainAddressCurrent.address')" - [[ "${retry_on_chain_address_current}" != "null" ]] || exit 1 - [[ "${retry_on_chain_address_created}" == "${retry_on_chain_address_current}" ]] || exit 1 -} - -@test "onchain-receive: settle onchain for USD wallet" { - token_name="$ALICE_TOKEN_NAME" - usd_wallet_name="$token_name.usd_wallet_id" - amount="0.01" - - # Create address - variables=$( - jq -n \ - --arg wallet_id "$(read_value $usd_wallet_name)" \ - '{input: {walletId: $wallet_id}}' - ) - exec_graphql "$token_name" 'on-chain-address-create' "$variables" - on_chain_address_created="$(graphql_output '.data.onChainAddressCreate.address')" - [[ "${on_chain_address_created}" != "null" ]] || exit 1 - - # Execute onchain send and check for transaction - bitcoin_cli sendtoaddress "$on_chain_address_created" "$amount" - retry 15 1 check_for_broadcast "$token_name" "$on_chain_address_created" 1 - - # Check pending transactions for address - - address_pending_txns_variables=$( - jq -n \ - --arg address "$on_chain_address_created" \ - '{"address": $address}' - ) - exec_graphql "$token_name" 'pending-transactions-by-address' "$address_pending_txns_variables" - pending_txns_for_address=$( - graphql_output ' - .data.me.defaultAccount.wallets[] - | select(.__typename == "UsdWallet") - .pendingTransactionsByAddress' - ) - pending_txns_for_address_length="$(echo $pending_txns_for_address | jq -r 'length')" - [[ "$pending_txns_for_address_length" == "1" ]] || exit 1 - address_from_pending_txns="$(echo $pending_txns_for_address | jq -r '.[0].initiationVia.address')" - [[ "$address_from_pending_txns" == "$on_chain_address_created" ]] - - # Check pending transactions for account - - exec_graphql "$token_name" 'pending-transactions' - pending_txns_for_account=$( - graphql_output ' - .data.me.defaultAccount.pendingTransactions' - ) - pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')" - [[ "$pending_txns_for_account_length" == "1" ]] || exit 1 - - bitcoin_cli -generate 2 - retry 15 1 check_for_onchain_initiated_settled "$token_name" "$on_chain_address_created" 1 - - # Ensure no pending transactions for account - - exec_graphql "$token_name" 'pending-transactions' - pending_txns_for_account=$( - graphql_output ' - .data.me.defaultAccount.pendingTransactions' - ) - pending_txns_for_account_length="$(echo $pending_txns_for_account | jq -r 'length')" - [[ "$pending_txns_for_account_length" == "0" ]] || exit 1 - -} - @test "onchain-receive: process received batch transaction" { alice_token_name="$ALICE_TOKEN_NAME" alice_btc_wallet_name="$alice_token_name.btc_wallet_id"