Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(core): move 01-setup steps to hedge tests #3711

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/api/test/helpers/bitcoin-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,17 @@ const getBitcoindSignerClient = (walletName?: string) => {
walletName,
})
}

export 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 })
}
}
}
}
15 changes: 1 addition & 14 deletions core/api/test/integration/services/bria.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createMandatoryUsers,
createUserAndWalletFromPhone,
getDefaultWalletIdByPhone,
loadBitcoindWallet,
mineAndConfirm,
randomPhone,
sendToAddressAndConfirm,
Expand All @@ -25,20 +26,6 @@ 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"
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@ import {
paymentAmountFromNumber,
WalletCurrency,
} from "@/domain/shared"
import { getFunderWalletId } from "@/services/ledger/caching"
import { baseLogger } from "@/services/logger"
import { AccountsRepository, WalletsRepository } from "@/services/mongoose"

import { createAccount, fundWallet, getBalanceHelper } from "test/helpers"
import {
bitcoindClient,
bitcoindOutside,
createAccount,
createMandatoryUsers,
fundLnd,
fundWallet,
fundWalletIdFromOnchain,
getBalanceHelper,
lnd1,
lndOutside1,
loadBitcoindWallet,
mineAndConfirm,
openChannelTesting,
resetLegacyIntegrationLnds,
} from "test/helpers"

class ZeroAmountForUsdRecipientError extends Error {}

Expand Down Expand Up @@ -42,6 +58,54 @@ type AccountAndWallets = {
newAccount: Account
}

beforeAll(async () => {
await createMandatoryUsers()
await loadBitcoindWallet("outside")
await resetLegacyIntegrationLnds()
await bootstrapLndNodes()
})

afterAll(async () => {
await bitcoindClient.unloadWallet({ walletName: "outside" })
})

const bootstrapLndNodes = async () => {
// Fund outside wallet to fund lnd nodes
const numOfBlocks = 10
const bitcoindAddress = await bitcoindOutside.getNewAddress()
await mineAndConfirm({
walletClient: bitcoindOutside,
numOfBlocks,
address: bitcoindAddress,
})

// Fund lndOutside1 node, open lndOutside1 -> lnd1 channel
const amountInBitcoin = 1
await fundLnd(lndOutside1, amountInBitcoin)

const lnd1Socket = `lnd1:9735`
await openChannelTesting({
lnd: lndOutside1,
lndPartner: lnd1,
socket: lnd1Socket,
})

// Fund lnd1 node, open lnd1 -> lndOutside1 channel
const funderWalletId = await getFunderWalletId()
await fundWalletIdFromOnchain({
walletId: funderWalletId,
amountInBitcoin,
lnd: lnd1,
})

const lndOutside1socket = `lnd-outside-1:9735`
await openChannelTesting({
lnd: lnd1,
lndPartner: lndOutside1,
socket: lndOutside1socket,
})
}

const btcAmountFromUsdNumber = async (
centsAmount: number | bigint,
): Promise<BtcPaymentAmount> => {
Expand Down
5 changes: 4 additions & 1 deletion core/api/test/legacy-integration/services/lnd/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ describe("lndUtils", () => {
}
})

it("sets routing fee correctly", async () => {
it.skip("sets routing fee correctly", async () => {
// Skipped because this test is already broken. lndOutside1 and lndOutside2
// are directly connected and routing fees are 0.

const { request } = await createInvoice({ lnd: lndOutside2, tokens: 10000 })

const initBalance = await ledgerAdmin.getBankOwnerBalance()
Expand Down
Loading