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
paymentManager: PaymentManager
nPubLinkingTokens = new Map<string, NsecLinkingData>();
linkingTokenInterval: NodeJS.Timeout
constructor(storage: Storage, settings: MainSettings, paymentManager: PaymentManager) {
this.storage = storage
this.settings = settings
this.paymentManager = paymentManager
setInterval(() => {
this.linkingTokenInterval = setInterval(() => {
const now = Date.now();
for (let [token, data] of this.nPubLinkingTokens) {
if (data.expiry <= now) {
@ -35,6 +36,9 @@ export default class {
}
}, 60 * 1000); // 1 minute
}
Stop() {
clearInterval(this.linkingTokenInterval)
}
SignAppToken(appId: string): string {
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)
}
Stop() {
this.lnd.Stop()
this.applicationManager.Stop()
this.paymentManager.Stop()
}
attachNostrSend(f: NostrSend) {
this.nostrSend = f

View file

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

View file

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

View file

@ -8,6 +8,16 @@ type TestModule = {
default: (T: TestBase) => Promise<void>
}
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 files = await globby("**/*.spec.js")
@ -19,8 +29,7 @@ const start = async () => {
if (module.dev) {
console.log("dev module found", file)
if (devModule !== -1) {
console.error(redConsole, "there are multiple dev modules", resetConsole)
return
throw new Error("there are multiple dev modules")
}
devModule = modules.length - 1
}
@ -28,16 +37,15 @@ const start = async () => {
if (devModule !== -1) {
console.log("running dev module")
await runTestFile(modules[devModule].file, modules[devModule].module)
return
}
else {
} else {
console.log("running all tests")
for (const { file, module } of modules) {
await runTestFile(file, module)
}
}
console.log(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 {
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 redConsole = "\x1b[31m"
const resetConsole = "\x1b[0m"