From bde0f1360d3df2f2ce3c91cbc63c841606ad4875 Mon Sep 17 00:00:00 2001 From: Arvin <17693119+vindard@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:09:27 -0400 Subject: [PATCH] test: move bria integration (#3617) --- .../services/bria.spec.ts} | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) rename core/api/test/{legacy-integration/02-user-wallet/02-bria.spec.ts => integration/services/bria.spec.ts} (85%) diff --git a/core/api/test/legacy-integration/02-user-wallet/02-bria.spec.ts b/core/api/test/integration/services/bria.spec.ts similarity index 85% rename from core/api/test/legacy-integration/02-user-wallet/02-bria.spec.ts rename to core/api/test/integration/services/bria.spec.ts index 06087bb9eb..7c4ed789cf 100644 --- a/core/api/test/legacy-integration/02-user-wallet/02-bria.spec.ts +++ b/core/api/test/integration/services/bria.spec.ts @@ -10,13 +10,14 @@ import { GrpcStreamClient, timeoutWithCancel } from "@/utils" import { bitcoindClient, bitcoindOutside, - checkIsBalanced, createMandatoryUsers, createUserAndWalletFromPhone, getDefaultWalletIdByPhone, + mineAndConfirm, randomPhone, sendToAddressAndConfirm, } from "test/helpers" +import { BitcoindWalletClient } from "test/helpers/bitcoind" let walletIdA: WalletId @@ -24,19 +25,45 @@ const TIMEOUT_BRIA_EVENT = 60_000 const phone = randomPhone() +const loadBitcoindWallet = async (walletName: string) => { + const wallets = await bitcoindClient.listWallets() + if (!wallets.includes(walletName)) { + try { + await bitcoindClient.createWallet({ walletName }) + } catch (err) { + const error = err as Error + if (error.message.includes("Database already exists")) { + await bitcoindClient.loadWallet({ filename: walletName }) + } + } + } +} + +const fundOutsideOnChainWallet = async () => { + // Setup outside bitcoind + const walletName = "outside" + const bitcoindOutside = new BitcoindWalletClient(walletName) + + // Fund outside bitcoind + const numOfBlocks = 10 + const bitcoindAddress = await bitcoindOutside.getNewAddress() + await mineAndConfirm({ + walletClient: bitcoindOutside, + numOfBlocks, + address: bitcoindAddress, + }) +} + beforeAll(async () => { await createMandatoryUsers() - await bitcoindClient.loadWallet({ filename: "outside" }) + await loadBitcoindWallet("outside") + await fundOutsideOnChainWallet() await createUserAndWalletFromPhone(phone) walletIdA = await getDefaultWalletIdByPhone(phone) }) -afterEach(async () => { - await checkIsBalanced() -}) - afterAll(async () => { jest.restoreAllMocks() await bitcoindClient.unloadWallet({ walletName: "outside" })