Skip to content

Commit

Permalink
test: move bria integration (#3617)
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard authored Nov 29, 2023
1 parent 0fca95b commit bde0f13
Showing 1 changed file with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,60 @@ 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

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" })
Expand Down

0 comments on commit bde0f13

Please sign in to comment.