Skip to content

Commit

Permalink
test(core): move 01-setup steps to hedge tests (#3711)
Browse files Browse the repository at this point in the history
* test(core): add bootstrap steps to hedge tests

* test(core): remove non-needed bootstrap deps from hedge test

* chore(core): remove legacy 01-setup integration tests

* refactor(core): make hedge tests re-runnable

* test(core): skip non-effective routing fees test
  • Loading branch information
vindard authored Jan 2, 2024
1 parent bd2aa4e commit df2f480
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 271 deletions.
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

0 comments on commit df2f480

Please sign in to comment.