Skip to content

Commit

Permalink
test(core): fix trigger receive legacy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Dec 8, 2023
1 parent 8714bf9 commit a53def1
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions core/api/test/legacy-integration/app/trigger/trigger.fn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
subscribeToBlocks,
waitFor,
waitUntilSyncAll,
mineAndConfirm,
} from "test/helpers"
import { getBalanceHelper, getTransactionsForWalletId } from "test/helpers/wallet"

Expand All @@ -38,10 +39,27 @@ const phoneA = randomPhone()
const phoneD = randomPhone()
const phoneF = randomPhone()

const loadAndFundBitcoindWallet = async (walletName: string) => {
try {
await bitcoindClient.createWallet({ walletName })
} catch (err) {}
try {
await bitcoindClient.loadWallet({ filename: walletName })
} catch (err) {}

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 loadAndFundBitcoindWallet("outside")

await createUserAndWalletFromPhone(phoneA)
await createUserAndWalletFromPhone(phoneD)
Expand Down Expand Up @@ -93,11 +111,11 @@ describe("onchainBlockEventHandler", () => {
const scanDepth = (ONCHAIN_MIN_CONFIRMATIONS + 1) as ScanDepth

await mineBlockAndSyncAll()
const result = await Wallets.updateLegacyOnChainReceipt({
let updateResult = await Wallets.updateLegacyOnChainReceipt({
scanDepth,
logger: baseLogger,
})
if (result instanceof Error) throw result
if (updateResult instanceof Error) throw updateResult

const initialBlock = await bitcoindClient.getBlockCount()
let isFinalBlock = false
Expand Down Expand Up @@ -152,7 +170,7 @@ describe("onchainBlockEventHandler", () => {
await Promise.all([waitFor(() => isFinalBlock), waitUntilSyncAll()])

// this sleep seems necessary on the CI server. otherwise all the events may not have propagated
// also some event are being trigger asynchronously without an awaitt, ie the notifications
// also some event are being trigger asynchronously without an await, ie the notifications
await sleep(500)

subBlocks.removeAllListeners()
Expand Down Expand Up @@ -200,6 +218,12 @@ describe("onchainBlockEventHandler", () => {
expect(onchainAddress).not.toBe(initialState.onchainAddress)
}

updateResult = await Wallets.updateLegacyOnChainReceipt({
scanDepth,
logger: baseLogger,
})
if (updateResult instanceof Error) throw updateResult

await validateWalletState({
walletId: walletIdA,
initialState: initWalletAState,
Expand Down

0 comments on commit a53def1

Please sign in to comment.