Skip to content

Commit

Permalink
test: clean up onchain-fee legacy integration tests (#3273)
Browse files Browse the repository at this point in the history
* test: add onchain fee bats tests

* test: remove redundant onchain-fee success tests

* test: move remaining onchain-fee tests to new integration
  • Loading branch information
vindard authored Sep 28, 2023
1 parent f0e66c7 commit c2858eb
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 345 deletions.
5 changes: 5 additions & 0 deletions test/bats/gql/on-chain-tx-fee.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query onChainTxFee($walletId: WalletId!, $address: OnChainAddress!, $amount: SatAmount!) {
onChainTxFee(walletId: $walletId, address: $address, amount: $amount) {
amount
}
}
13 changes: 13 additions & 0 deletions test/bats/gql/on-chain-usd-tx-fee-as-btc-denominated.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query onChainUsdTxFeeAsBtcDenominated(
$walletId: WalletId!
$address: OnChainAddress!
$amount: SatAmount!
) {
onChainUsdTxFeeAsBtcDenominated(
walletId: $walletId
address: $address
amount: $amount
) {
amount
}
}
9 changes: 9 additions & 0 deletions test/bats/gql/on-chain-usd-tx-fee.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query onChainUsdTxFee(
$walletId: WalletId!
$address: OnChainAddress!
$amount: CentAmount!
) {
onChainUsdTxFee(walletId: $walletId, address: $address, amount: $amount) {
amount
}
}
111 changes: 111 additions & 0 deletions test/bats/onchain-send.bats
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,114 @@ teardown() {
retry 3 1 check_for_onchain_initiated_settled "$token_name" "$on_chain_usd_payment_send_address" 4
retry 3 1 check_for_onchain_initiated_settled "$token_name" "$on_chain_payment_send_address" 4
}

@test "onchain-send: get fee for external address" {
token_name="$ALICE_TOKEN_NAME"
btc_wallet_name="$token_name.btc_wallet_id"
usd_wallet_name="$token_name.usd_wallet_id"

# EXECUTE GQL FEE ESTIMATES
# ----------

address=$(bitcoin_cli getnewaddress)
[[ "${address}" != "null" ]] || exit 1

# mutation: onChainTxFee
variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg address "$address" \
--arg amount 12345 \
'{walletId: $wallet_id, address: $address, amount: $amount}'
)
exec_graphql "$token_name" 'on-chain-tx-fee' "$variables"
amount="$(graphql_output '.data.onChainTxFee.amount')"
[[ "${amount}" -gt 0 ]] || exit 1

# mutation: onChainUsdTxFee
variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg address "$address" \
--arg amount 200 \
'{walletId: $wallet_id, address: $address, amount: $amount}'
)
exec_graphql "$token_name" 'on-chain-usd-tx-fee' "$variables"
amount="$(graphql_output '.data.onChainUsdTxFee.amount')"
[[ "${amount}" -gt 0 ]] || exit 1

# mutation: onChainUsdTxFeeAsBtcDenominated
variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg address "$address" \
--arg amount 12345 \
'{walletId: $wallet_id, address: $address, amount: $amount}'
)
exec_graphql "$token_name" 'on-chain-usd-tx-fee-as-btc-denominated' "$variables"
amount="$(graphql_output '.data.onChainUsdTxFeeAsBtcDenominated.amount')"
[[ "${amount}" -gt 0 ]] || exit 1
}

@test "onchain-send: get fee for internal address" {
token_name="$ALICE_TOKEN_NAME"
btc_wallet_name="$token_name.btc_wallet_id"
usd_wallet_name="$token_name.usd_wallet_id"

# EXECUTE GQL FEE ESTIMATES
# ----------

recipient_token_name="user_$RANDOM"
recipient_phone="$(random_phone)"
login_user \
"$recipient_token_name" \
"$recipient_phone" \
"$CODE"
user_update_username "$recipient_token_name"
btc_recipient_wallet_name="$recipient_token_name.btc_wallet_id"

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_recipient_wallet_name)" \
'{input: {walletId: $wallet_id}}'
)
exec_graphql "$recipient_token_name" 'on-chain-address-create' "$variables"
address="$(graphql_output '.data.onChainAddressCreate.address')"
[[ "${address}" != "null" ]] || exit 1

# mutation: onChainTxFee
variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg address "$address" \
--arg amount 12345 \
'{walletId: $wallet_id, address: $address, amount: $amount}'
)
exec_graphql "$token_name" 'on-chain-tx-fee' "$variables"
amount="$(graphql_output '.data.onChainTxFee.amount')"
[[ "${amount}" == 0 ]] || exit 1

# mutation: onChainUsdTxFee
variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg address "$address" \
--arg amount 200 \
'{walletId: $wallet_id, address: $address, amount: $amount}'
)
exec_graphql "$token_name" 'on-chain-usd-tx-fee' "$variables"
amount="$(graphql_output '.data.onChainUsdTxFee.amount')"
[[ "${amount}" == 0 ]] || exit 1

# mutation: onChainUsdTxFeeAsBtcDenominated
variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg address "$address" \
--arg amount 12345 \
'{walletId: $wallet_id, address: $address, amount: $amount}'
)
exec_graphql "$token_name" 'on-chain-usd-tx-fee-as-btc-denominated' "$variables"
amount="$(graphql_output '.data.onChainUsdTxFeeAsBtcDenominated.amount')"
[[ "${amount}" == 0 ]] || exit 1
}
57 changes: 57 additions & 0 deletions test/integration/app/wallets/get-on-chain-fee.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Wallets } from "@app"

import { getOnChainWalletConfig } from "@config"

import { PayoutSpeed } from "@domain/bitcoin/onchain"
import { LessThanDustThresholdError } from "@domain/errors"

import { AccountsRepository } from "@services/mongoose"

import { createRandomUserAndWallets } from "test/helpers"

let outsideAddress: OnChainAddress

beforeAll(async () => {
outsideAddress = "bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw" as OnChainAddress
})

const amountBelowDustThreshold = getOnChainWalletConfig().dustThreshold - 1

describe("onChainPay", () => {
describe("settles onchain", () => {
it("fails to fetch fee for dust amount", async () => {
const { btcWalletDescriptor, usdWalletDescriptor } =
await createRandomUserAndWallets()
const account = await AccountsRepository().findById(btcWalletDescriptor.accountId)
if (account instanceof Error) throw account

const resultBtcWallet = await Wallets.getOnChainFeeForBtcWallet({
walletId: btcWalletDescriptor.id,
account,
address: outsideAddress,
amount: amountBelowDustThreshold,
speed: PayoutSpeed.Fast,
})
expect(resultBtcWallet).toBeInstanceOf(LessThanDustThresholdError)

const resultUsdWallet = await Wallets.getOnChainFeeForUsdWallet({
walletId: usdWalletDescriptor.id,
account,
address: outsideAddress,
amount: 1,
speed: PayoutSpeed.Fast,
})
expect(resultUsdWallet).toBeInstanceOf(LessThanDustThresholdError)

const resultUsdWalletAndBtcAmount =
await Wallets.getOnChainFeeForUsdWalletAndBtcAmount({
walletId: usdWalletDescriptor.id,
account,
address: outsideAddress,
amount: amountBelowDustThreshold,
speed: PayoutSpeed.Fast,
})
expect(resultUsdWalletAndBtcAmount).toBeInstanceOf(LessThanDustThresholdError)
})
})
})
Loading

0 comments on commit c2858eb

Please sign in to comment.