close handing
This commit is contained in:
parent
72683a3e88
commit
2a30e656aa
6 changed files with 22 additions and 9 deletions
|
|
@ -22,6 +22,7 @@ export class LiquidityProvider {
|
||||||
latestMaxWithdrawable: number | null = null
|
latestMaxWithdrawable: number | null = null
|
||||||
invoicePaidCb: InvoicePaidCb
|
invoicePaidCb: InvoicePaidCb
|
||||||
connecting = false
|
connecting = false
|
||||||
|
readyInterval: NodeJS.Timeout
|
||||||
// make the sub process accept client
|
// make the sub process accept client
|
||||||
constructor(pubDestination: string, invoicePaidCb: InvoicePaidCb) {
|
constructor(pubDestination: string, invoicePaidCb: InvoicePaidCb) {
|
||||||
if (!pubDestination) {
|
if (!pubDestination) {
|
||||||
|
|
@ -34,14 +35,18 @@ export class LiquidityProvider {
|
||||||
retrieveNostrUserAuth: async () => this.myPub,
|
retrieveNostrUserAuth: async () => this.myPub,
|
||||||
}, this.clientSend, this.clientSub)
|
}, this.clientSend, this.clientSub)
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
this.readyInterval = setInterval(() => {
|
||||||
if (this.ready) {
|
if (this.ready) {
|
||||||
clearInterval(interval)
|
clearInterval(this.readyInterval)
|
||||||
this.Connect()
|
this.Connect()
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stop = () => {
|
||||||
|
clearInterval(this.readyInterval)
|
||||||
|
}
|
||||||
|
|
||||||
Connect = async () => {
|
Connect = async () => {
|
||||||
await new Promise(res => setTimeout(res, 2000))
|
await new Promise(res => setTimeout(res, 2000))
|
||||||
this.log("ready")
|
this.log("ready")
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ export default class {
|
||||||
}
|
}
|
||||||
Stop() {
|
Stop() {
|
||||||
this.abortController.abort()
|
this.abortController.abort()
|
||||||
|
this.liquidProvider.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
async ShouldUseLiquidityProvider(req: LiquidityRequest): Promise<boolean> {
|
async ShouldUseLiquidityProvider(req: LiquidityRequest): Promise<boolean> {
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ export default async (T: TestBase) => {
|
||||||
disableLoggers([], ["EventsLogManager", "watchdog", "htlcTracker", "debugHtlcs", "debugLndBalancev3", "metrics", "mainForTest", "main"])
|
disableLoggers([], ["EventsLogManager", "watchdog", "htlcTracker", "debugHtlcs", "debugLndBalancev3", "metrics", "mainForTest", "main"])
|
||||||
await safelySetUserBalance(T, T.user1, 2000)
|
await safelySetUserBalance(T, T.user1, 2000)
|
||||||
T.d("starting liquidityProvider tests...")
|
T.d("starting liquidityProvider tests...")
|
||||||
const { bootstrapped, bootstrappedUser } = await initBootstrappedInstance(T)
|
const { bootstrapped, bootstrappedUser, stop } = await initBootstrappedInstance(T)
|
||||||
await testInboundPaymentFromProvider(T, bootstrapped, bootstrappedUser)
|
await testInboundPaymentFromProvider(T, bootstrapped, bootstrappedUser)
|
||||||
await testOutboundPaymentFromProvider(T, bootstrapped, bootstrappedUser)
|
await testOutboundPaymentFromProvider(T, bootstrapped, bootstrappedUser)
|
||||||
|
stop()
|
||||||
await runSanityCheck(T)
|
await runSanityCheck(T)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ export const setupNetwork = async () => {
|
||||||
throw new Error("bob not synced to graph")
|
throw new Error("bob not synced to graph")
|
||||||
}
|
}
|
||||||
}, 15, 2000)
|
}, 15, 2000)
|
||||||
|
|
||||||
|
alice.Stop()
|
||||||
|
bob.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
const tryUntil = async <T>(fn: (attempt: number) => Promise<T>, maxTries: number, interval: number) => {
|
const tryUntil = async <T>(fn: (attempt: number) => Promise<T>, maxTries: number, interval: number) => {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { TestBase, TestUserData } from './testBase.js'
|
||||||
import * as Types from '../../proto/autogenerated/ts/types.js'
|
import * as Types from '../../proto/autogenerated/ts/types.js'
|
||||||
|
|
||||||
export const initBootstrappedInstance = async (T: TestBase) => {
|
export const initBootstrappedInstance = async (T: TestBase) => {
|
||||||
const requests = {}
|
|
||||||
const settings = LoadTestSettingsFromEnv()
|
const settings = LoadTestSettingsFromEnv()
|
||||||
settings.lndSettings.useOnlyLiquidityProvider = true
|
settings.lndSettings.useOnlyLiquidityProvider = true
|
||||||
settings.lndSettings.liquidityProviderPub = T.app.publicKey
|
settings.lndSettings.liquidityProviderPub = T.app.publicKey
|
||||||
|
|
@ -15,8 +14,8 @@ export const initBootstrappedInstance = async (T: TestBase) => {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
throw new Error("failed to initialize bootstrapped main handler")
|
throw new Error("failed to initialize bootstrapped main handler")
|
||||||
}
|
}
|
||||||
const { mainHandler: bootstrapped, liquidityProviderInfo, liquidityProviderApp, apps } = initialized
|
const { mainHandler: bootstrapped, liquidityProviderInfo, liquidityProviderApp } = initialized
|
||||||
T.main.attachNostrSend(async (initiator, data, r) => {
|
T.main.attachNostrSend(async (_, data, r) => {
|
||||||
if (data.type === 'event') {
|
if (data.type === 'event') {
|
||||||
throw new Error("unsupported event type")
|
throw new Error("unsupported event type")
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +26,7 @@ export const initBootstrappedInstance = async (T: TestBase) => {
|
||||||
console.log("sending new operation to provider")
|
console.log("sending new operation to provider")
|
||||||
bootstrapped.liquidProvider.onEvent(j, T.app.publicKey)
|
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)
|
const res = await handleSend(T, data)
|
||||||
if (data.type === 'event') {
|
if (data.type === 'event') {
|
||||||
throw new Error("unsupported event type")
|
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 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 }
|
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 } & (
|
type TransportRequest = { requestId: string, authIdentifier: string } & (
|
||||||
{ rpcName: 'GetUserInfo' } |
|
{ rpcName: 'GetUserInfo' } |
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
import { globby } from 'globby'
|
import { globby } from 'globby'
|
||||||
import { setupNetwork } from './networkSetup.js'
|
import { setupNetwork } from './networkSetup.js'
|
||||||
import { Describe, SetupTest, teardown, TestBase } from './testBase.js'
|
import { Describe, SetupTest, teardown, TestBase } from './testBase.js'
|
||||||
|
|
||||||
type TestModule = {
|
type TestModule = {
|
||||||
ignore?: boolean
|
ignore?: boolean
|
||||||
dev?: boolean
|
dev?: boolean
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue