close handing

This commit is contained in:
hatim boufnichel 2024-05-23 21:56:20 +02:00
parent 72683a3e88
commit 2a30e656aa
6 changed files with 22 additions and 9 deletions

View file

@ -22,6 +22,7 @@ export class LiquidityProvider {
latestMaxWithdrawable: number | null = null
invoicePaidCb: InvoicePaidCb
connecting = false
readyInterval: NodeJS.Timeout
// make the sub process accept client
constructor(pubDestination: string, invoicePaidCb: InvoicePaidCb) {
if (!pubDestination) {
@ -34,14 +35,18 @@ export class LiquidityProvider {
retrieveNostrUserAuth: async () => this.myPub,
}, this.clientSend, this.clientSub)
const interval = setInterval(() => {
this.readyInterval = setInterval(() => {
if (this.ready) {
clearInterval(interval)
clearInterval(this.readyInterval)
this.Connect()
}
}, 1000)
}
Stop = () => {
clearInterval(this.readyInterval)
}
Connect = async () => {
await new Promise(res => setTimeout(res, 2000))
this.log("ready")

View file

@ -77,6 +77,7 @@ export default class {
}
Stop() {
this.abortController.abort()
this.liquidProvider.Stop()
}
async ShouldUseLiquidityProvider(req: LiquidityRequest): Promise<boolean> {

View file

@ -12,9 +12,10 @@ export default async (T: TestBase) => {
disableLoggers([], ["EventsLogManager", "watchdog", "htlcTracker", "debugHtlcs", "debugLndBalancev3", "metrics", "mainForTest", "main"])
await safelySetUserBalance(T, T.user1, 2000)
T.d("starting liquidityProvider tests...")
const { bootstrapped, bootstrappedUser } = await initBootstrappedInstance(T)
const { bootstrapped, bootstrappedUser, stop } = await initBootstrappedInstance(T)
await testInboundPaymentFromProvider(T, bootstrapped, bootstrappedUser)
await testOutboundPaymentFromProvider(T, bootstrapped, bootstrappedUser)
stop()
await runSanityCheck(T)
}

View file

@ -47,6 +47,9 @@ export const setupNetwork = async () => {
throw new Error("bob not synced to graph")
}
}, 15, 2000)
alice.Stop()
bob.Stop()
}
const tryUntil = async <T>(fn: (attempt: number) => Promise<T>, maxTries: number, interval: number) => {

View file

@ -6,7 +6,6 @@ import { TestBase, TestUserData } from './testBase.js'
import * as Types from '../../proto/autogenerated/ts/types.js'
export const initBootstrappedInstance = async (T: TestBase) => {
const requests = {}
const settings = LoadTestSettingsFromEnv()
settings.lndSettings.useOnlyLiquidityProvider = true
settings.lndSettings.liquidityProviderPub = T.app.publicKey
@ -15,8 +14,8 @@ export const initBootstrappedInstance = async (T: TestBase) => {
if (!initialized) {
throw new Error("failed to initialize bootstrapped main handler")
}
const { mainHandler: bootstrapped, liquidityProviderInfo, liquidityProviderApp, apps } = initialized
T.main.attachNostrSend(async (initiator, data, r) => {
const { mainHandler: bootstrapped, liquidityProviderInfo, liquidityProviderApp } = initialized
T.main.attachNostrSend(async (_, data, r) => {
if (data.type === 'event') {
throw new Error("unsupported event type")
}
@ -27,7 +26,7 @@ export const initBootstrappedInstance = async (T: TestBase) => {
console.log("sending new operation to provider")
bootstrapped.liquidProvider.onEvent(j, T.app.publicKey)
})
bootstrapped.liquidProvider.attachNostrSend(async (initiator, data, r) => {
bootstrapped.liquidProvider.attachNostrSend(async (_, data, r) => {
const res = await handleSend(T, data)
if (data.type === 'event') {
throw new Error("unsupported event type")
@ -50,7 +49,11 @@ export const initBootstrappedInstance = async (T: TestBase) => {
})
const bUser = await bootstrapped.applicationManager.AddAppUser(liquidityProviderApp.appId, { identifier: "user1_bootstrapped", balance: 0, fail_if_exists: true })
const bootstrappedUser: TestUserData = { userId: bUser.info.userId, appUserIdentifier: bUser.identifier, appId: liquidityProviderApp.appId }
return { bootstrapped, liquidityProviderInfo, liquidityProviderApp, bootstrappedUser }
return {
bootstrapped, liquidityProviderInfo, liquidityProviderApp, bootstrappedUser, stop: () => {
bootstrapped.Stop()
}
}
}
type TransportRequest = { requestId: string, authIdentifier: string } & (
{ rpcName: 'GetUserInfo' } |

View file

@ -1,7 +1,7 @@
import { globby } from 'globby'
import { setupNetwork } from './networkSetup.js'
import { Describe, SetupTest, teardown, TestBase } from './testBase.js'
type TestModule = {
ignore?: boolean
dev?: boolean