From 8bc7464c485c13d386230a9511e02f0342c2ee86 Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:23:19 -0400 Subject: [PATCH] chore(core): remove legacy 01-setup integration tests --- .../01-setup/01-funds-bitcoind-lnds.spec.ts | 100 ----------- .../01-setup/01-lightning-channels.spec.ts | 155 ------------------ 2 files changed, 255 deletions(-) delete mode 100644 core/api/test/legacy-integration/01-setup/01-funds-bitcoind-lnds.spec.ts delete mode 100644 core/api/test/legacy-integration/01-setup/01-lightning-channels.spec.ts diff --git a/core/api/test/legacy-integration/01-setup/01-funds-bitcoind-lnds.spec.ts b/core/api/test/legacy-integration/01-setup/01-funds-bitcoind-lnds.spec.ts deleted file mode 100644 index bd7c1fb574..0000000000 --- a/core/api/test/legacy-integration/01-setup/01-funds-bitcoind-lnds.spec.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { btc2sat, sat2btc } from "@/domain/bitcoin" -import { getFunderWalletId } from "@/services/ledger/caching" - -import { - bitcoindClient, - bitcoindSignerClient, - checkIsBalanced, - createMandatoryUsers, - createSignerWallet, - fundLnd, - fundWalletIdFromOnchain, - getChainBalance, - lnd1, - lndOutside1, - mineAndConfirm, - resetLegacyIntegrationLnds, -} from "test/helpers" -import { BitcoindWalletClient } from "test/helpers/bitcoind" - -let bitcoindOutside: BitcoindWalletClient - -beforeAll(async () => { - await createMandatoryUsers() - await resetLegacyIntegrationLnds() -}) - -afterAll(async () => { - await bitcoindClient.unloadWallet({ walletName: "outside" }) -}) - -afterEach(async () => { - await checkIsBalanced() -}) - -describe("Bitcoind", () => { - it("check no wallet", async () => { - const wallets = await bitcoindClient.listWallets() - expect(wallets.length).toBe(0) - }) - - it("create signer wallet for bria", async () => { - const walletName = "dev" - const { name } = await createSignerWallet(walletName) - expect(name).toBe(walletName) - - const wallets = await bitcoindSignerClient.listWallets() - expect(wallets).toContain(walletName) - }) - - it("create outside wallet", async () => { - const walletName = "outside" - const { name } = await bitcoindClient.createWallet({ walletName }) - expect(name).toBe(walletName) - const wallets = await bitcoindClient.listWallets() - expect(wallets).toContain(walletName) - bitcoindOutside = new BitcoindWalletClient(walletName) - }) - - it("should be funded mining 10 blocks", async () => { - const numOfBlocks = 10 - const bitcoindAddress = await bitcoindOutside.getNewAddress() - await mineAndConfirm({ - walletClient: bitcoindOutside, - numOfBlocks, - address: bitcoindAddress, - }) - const balance = await bitcoindOutside.getBalance() - expect(balance).toBeGreaterThanOrEqual(50 * numOfBlocks) - }) - - it("funds outside lnd node", async () => { - const outsideLnds = [lndOutside1] - for (const lnd of outsideLnds) { - const amount = btc2sat(1) - const { chain_balance: initialBalance } = await getChainBalance({ - lnd, - }) - const sats = initialBalance + amount - await fundLnd(lnd, sat2btc(amount)) - const { chain_balance: balance } = await getChainBalance({ lnd }) - expect(balance).toBe(sats) - } - }) - - it("funds lnd1 node", async () => { - const amount = btc2sat(1) - const { chain_balance: initialBalance } = await getChainBalance({ lnd: lnd1 }) - const sats = initialBalance + amount - - const funderWalletId = await getFunderWalletId() - await fundWalletIdFromOnchain({ - walletId: funderWalletId, - amountInBitcoin: sat2btc(amount), - lnd: lnd1, - }) - - const { chain_balance: balance } = await getChainBalance({ lnd: lnd1 }) - expect(balance).toBe(sats) - }) -}) diff --git a/core/api/test/legacy-integration/01-setup/01-lightning-channels.spec.ts b/core/api/test/legacy-integration/01-setup/01-lightning-channels.spec.ts deleted file mode 100644 index 8a999a3457..0000000000 --- a/core/api/test/legacy-integration/01-setup/01-lightning-channels.spec.ts +++ /dev/null @@ -1,155 +0,0 @@ -import { ledgerAdmin } from "@/services/mongodb" -import { sleep } from "@/utils" - -import { - checkIsBalanced, - getChannel, - getChannels, - lnd1, - lnd2, - lndOutside1, - lndOutside2, - openChannelTesting, - setChannelFees, - waitUntilSync, -} from "test/helpers" - -//this is the fixed opening and closing channel fee on devnet -const channelFee = 7700 -const lnds = [lnd1, lnd2, lndOutside1, lndOutside1] -let channelLengthMain: number, channelLengthOutside1: number - -beforeEach(async () => { - await waitUntilSync({ lnds }) - channelLengthMain = (await getChannels({ lnd: lnd1 })).channels.length - channelLengthOutside1 = (await getChannels({ lnd: lndOutside1 })).channels.length -}) - -afterEach(async () => { - await checkIsBalanced() -}) - -// Setup the next network -// lnd2 <- lnd1 <-> lndOutside1 -> lndOutside2 -// this setup avoids close channels for routing fees tests -describe("Lightning channels", () => { - it("opens channel from lnd1 to lnd2", async () => { - const socket = `lnd2:9735` - const { lndNewChannel: channel } = await openChannelTesting({ - lnd: lnd1, - lndPartner: lnd2, - socket, - }) - - const { channels } = await getChannels({ lnd: lnd1 }) - expect(channels.length).toEqual(channelLengthMain + 1) - - // @ts-ignore-next-line no-implicit-any error - await setChannelFees({ lnd: lnd1, channel, base: 0, rate: 0 }) - // @ts-ignore-next-line no-implicit-any error - await setChannelFees({ lnd: lnd2, channel, base: 0, rate: 0 }) - }) - - it("opens channel from lnd1 to lndOutside1", async () => { - const socket = `lnd-outside-1:9735` - - const initFeeInLedger = await ledgerAdmin.getBankOwnerBalance() - - const { lndNewChannel: channel } = await openChannelTesting({ - lnd: lnd1, - lndPartner: lndOutside1, - socket, - }) - - const { channels } = await getChannels({ lnd: lnd1 }) - expect(channels.length).toEqual(channelLengthMain + 1) - - const finalFeeInLedger = await ledgerAdmin.getBankOwnerBalance() - expect(finalFeeInLedger - initFeeInLedger).toBe(channelFee * -1) - - // @ts-ignore-next-line no-implicit-any error - await setChannelFees({ lnd: lnd1, channel, base: 1, rate: 0 }) - // @ts-ignore-next-line no-implicit-any error - await setChannelFees({ lnd: lndOutside1, channel, base: 1, rate: 0 }) - }) - - it("opens channel from lndOutside1 to lnd1", async () => { - const socket = `lnd1:9735` - - const { lndNewChannel: channel } = await openChannelTesting({ - lnd: lndOutside1, - lndPartner: lnd1, - socket, - }) - - const { channels } = await getChannels({ lnd: lnd1 }) - expect(channels.length).toEqual(channelLengthMain + 1) - - // @ts-ignore-next-line no-implicit-any error - await setChannelFees({ lnd: lnd1, channel, base: 1, rate: 0 }) - // @ts-ignore-next-line no-implicit-any error - await setChannelFees({ lnd: lndOutside1, channel, base: 1, rate: 0 }) - }) - - it("opens private channel from lndOutside1 to lndOutside2", async () => { - const socket = `lnd-outside-2:9735` - - const { lndNewChannel: channel } = await openChannelTesting({ - lnd: lndOutside1, - lndPartner: lndOutside2, - socket, - is_private: true, - }) - - const { channels } = await getChannels({ lnd: lndOutside1 }) - expect(channels.length).toEqual(channelLengthOutside1 + 1) - expect(channels.some((e) => e.is_private)).toBe(true) - - // Set fee policy on lndOutside1 as routing node between lnd1 and lndOutside2 - let count = 0 - let countMax = 9 - let setOnLndOutside1 - while (count < countMax && setOnLndOutside1 !== true) { - if (count > 0) await sleep(500) - count++ - - setOnLndOutside1 = await setChannelFees({ - lnd: lndOutside1, - // @ts-ignore-next-line no-implicit-any error - channel, - base: 0, - rate: 5000, - }) - } - expect(count).toBeGreaterThan(0) - expect(count).toBeLessThan(countMax) - expect(setOnLndOutside1).toBe(true) - - let policies - let errMsg: string | undefined = "FullChannelDetailsNotFound" - count = 0 - countMax = 8 - // Try to getChannel for up to 2 secs (250ms x 8) - while (count < countMax && errMsg === "FullChannelDetailsNotFound") { - count++ - await sleep(250) - try { - /* eslint @typescript-eslint/ban-ts-comment: "off" */ - // @ts-ignore-next-line no-implicit-any error - ;({ policies } = await getChannel({ id: channel.id, lnd: lndOutside1 })) - errMsg = undefined - } catch (err) { - if (Array.isArray(err)) errMsg = err[1] - } - } - expect(count).toBeGreaterThan(0) - expect(count).toBeLessThan(countMax) - expect(errMsg).not.toBe("FullChannelDetailsNotFound") - expect(policies && policies.length).toBeGreaterThan(0) - - // @ts-ignore-next-line no-implicit-any error - const { base_fee_mtokens, fee_rate } = policies[0] - expect(base_fee_mtokens).toBe("0") - expect(fee_rate).toEqual(5000) - }) -})