Skip to content

Commit

Permalink
waitForIndexedHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Dec 11, 2023
1 parent b475a6b commit 41ac0c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions apps/whale-api/src/e2e.defid.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { v4 as uuidv4 } from 'uuid'
import fs from 'fs'
import { ChildProcess, spawn } from 'child_process'
import { RegTestFoundationKeys } from '@defichain/jellyfish-network'
import { MasterNodeRegTestContainer } from '@defichain/testcontainers/dist/index'

const PORT = 3002
const ENDPOINT = `http://127.0.0.1:${PORT}`
Expand Down Expand Up @@ -274,6 +275,7 @@ export class DefidBin {
binary: ChildProcess | null = null

public constructor (
readonly container: MasterNodeRegTestContainer,
readonly addressController: DAddressController,
readonly blockController: DBlockController
) {
Expand Down
20 changes: 12 additions & 8 deletions apps/whale-api/src/e2e.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DefidBin, DAddressController, DBlockController } from './e2e.defid.modu
export async function createTestingApp (container: MasterNodeRegTestContainer): Promise<NestFastifyApplication | DefidBin> {
if (process.env.DEFID !== undefined) {
const defid = new DefidBin(
container,
new DAddressController(),
new DBlockController()
)
Expand Down Expand Up @@ -114,15 +115,18 @@ export async function waitForIndexedHeightLatest (app: NestFastifyApplication, c
export async function waitForIndexedHeight (app: NestFastifyApplication | DefidBin, height: number, timeout: number = 30000): Promise<void> {
if (app instanceof DefidBin) {
await waitForExpect(async () => {
// get index from DefidBin
})
return
// TODO(): maybe get index from DefidBin
const count = await app.container.getBlockCount()
await expect(count).toBeGreaterThan(height)
await await app.container.generate(1)
}, timeout)
} else {
const blockMapper = app.get(BlockMapper)
await waitForExpect(async () => {
const block = await blockMapper.getHighest()
await expect(block?.height).toBeGreaterThan(height)
}, timeout)
}
const blockMapper = app.get(BlockMapper)
await waitForExpect(async () => {
const block = await blockMapper.getHighest()
await expect(block?.height).toBeGreaterThan(height)
}, timeout)
await new Promise((resolve) => setTimeout(resolve, 1000))
}

Expand Down

0 comments on commit 41ac0c3

Please sign in to comment.