This commit is contained in:
hatim boufnichel 2024-04-23 18:13:06 +02:00
parent 08afa1db4f
commit d503d18ba3
5 changed files with 30 additions and 19 deletions

View file

@ -19,11 +19,12 @@ export default class {
settings: MainSettings settings: MainSettings
paymentManager: PaymentManager paymentManager: PaymentManager
nPubLinkingTokens = new Map<string, NsecLinkingData>(); nPubLinkingTokens = new Map<string, NsecLinkingData>();
linkingTokenInterval: NodeJS.Timeout
constructor(storage: Storage, settings: MainSettings, paymentManager: PaymentManager) { constructor(storage: Storage, settings: MainSettings, paymentManager: PaymentManager) {
this.storage = storage this.storage = storage
this.settings = settings this.settings = settings
this.paymentManager = paymentManager this.paymentManager = paymentManager
setInterval(() => { this.linkingTokenInterval = setInterval(() => {
const now = Date.now(); const now = Date.now();
for (let [token, data] of this.nPubLinkingTokens) { for (let [token, data] of this.nPubLinkingTokens) {
if (data.expiry <= now) { if (data.expiry <= now) {
@ -35,6 +36,9 @@ export default class {
} }
}, 60 * 1000); // 1 minute }, 60 * 1000); // 1 minute
} }
Stop() {
clearInterval(this.linkingTokenInterval)
}
SignAppToken(appId: string): string { SignAppToken(appId: string): string {
return jwt.sign({ appId }, this.settings.jwtSecret); return jwt.sign({ appId }, this.settings.jwtSecret);
} }

View file

@ -50,6 +50,11 @@ export default class {
this.appUserManager = new AppUserManager(this.storage, this.settings, this.applicationManager) this.appUserManager = new AppUserManager(this.storage, this.settings, this.applicationManager)
} }
Stop() {
this.lnd.Stop()
this.applicationManager.Stop()
this.paymentManager.Stop()
}
attachNostrSend(f: NostrSend) { attachNostrSend(f: NostrSend) {
this.nostrSend = f this.nostrSend = f

View file

@ -39,6 +39,7 @@ const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]`
const confInOne = 1000 * 1000 const confInOne = 1000 * 1000
const confInTwo = 100 * 1000 * 1000 const confInTwo = 100 * 1000 * 1000
export default class { export default class {
storage: Storage storage: Storage
settings: MainSettings settings: MainSettings
lnd: LightningHandler lnd: LightningHandler
@ -54,6 +55,9 @@ export default class {
this.addressPaidCb = addressPaidCb this.addressPaidCb = addressPaidCb
this.invoicePaidCb = invoicePaidCb this.invoicePaidCb = invoicePaidCb
} }
Stop() {
this.watchDog.Stop()
}
getServiceFee(action: Types.UserOperationType, amount: number, appUser: boolean): number { getServiceFee(action: Types.UserOperationType, amount: number, appUser: boolean): number {
switch (action) { switch (action) {

View file

@ -66,8 +66,7 @@ export const SetupTest = async (d: Describe): Promise<TestBase> => {
} }
export const teardown = async (T: TestBase) => { export const teardown = async (T: TestBase) => {
T.main.paymentManager.watchDog.Stop() T.main.Stop()
T.main.lnd.Stop()
T.externalAccessToMainLnd.Stop() T.externalAccessToMainLnd.Stop()
T.externalAccessToOtherLnd.Stop() T.externalAccessToOtherLnd.Stop()
T.externalAccessToThirdLnd.Stop() T.externalAccessToThirdLnd.Stop()

View file

@ -8,6 +8,16 @@ type TestModule = {
default: (T: TestBase) => Promise<void> default: (T: TestBase) => Promise<void>
} }
let failures = 0 let failures = 0
const getDescribe = (fileName: string): Describe => {
return (message, failure) => {
if (failure) {
failures++
console.error(redConsole, fileName, ": FAILURE ", message, resetConsole)
} else {
console.log(greenConsole, fileName, ":", message, resetConsole)
}
}
}
const start = async () => { const start = async () => {
const files = await globby("**/*.spec.js") const files = await globby("**/*.spec.js")
@ -19,8 +29,7 @@ const start = async () => {
if (module.dev) { if (module.dev) {
console.log("dev module found", file) console.log("dev module found", file)
if (devModule !== -1) { if (devModule !== -1) {
console.error(redConsole, "there are multiple dev modules", resetConsole) throw new Error("there are multiple dev modules")
return
} }
devModule = modules.length - 1 devModule = modules.length - 1
} }
@ -28,16 +37,15 @@ const start = async () => {
if (devModule !== -1) { if (devModule !== -1) {
console.log("running dev module") console.log("running dev module")
await runTestFile(modules[devModule].file, modules[devModule].module) await runTestFile(modules[devModule].file, modules[devModule].module)
return } else {
}
else {
console.log("running all tests") console.log("running all tests")
for (const { file, module } of modules) { for (const { file, module } of modules) {
await runTestFile(file, module) await runTestFile(file, module)
} }
} }
console.log(failures)
if (failures) { if (failures) {
console.error(redConsole, "there have been", `${failures}`, "failures in all tests", resetConsole) throw new Error("there have been " + failures + " failures in all tests")
} else { } else {
console.log(greenConsole, "there have been 0 failures in all tests", resetConsole) console.log(greenConsole, "there have been 0 failures in all tests", resetConsole)
} }
@ -69,16 +77,7 @@ const runTestFile = async (fileName: string, mod: TestModule) => {
} }
} }
const getDescribe = (fileName: string): Describe => {
return (message, failure) => {
if (failure) {
failures++
console.error(redConsole, fileName, ": FAILURE ", message, resetConsole)
} else {
console.log(greenConsole, fileName, ":", message, resetConsole)
}
}
}
const greenConsole = "\x1b[32m" const greenConsole = "\x1b[32m"
const redConsole = "\x1b[31m" const redConsole = "\x1b[31m"
const resetConsole = "\x1b[0m" const resetConsole = "\x1b[0m"