Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
boufni95 committed Apr 23, 2024
1 parent 77b6fc3 commit a59748a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/services/main/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/services/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/services/main/paymentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/tests/testBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 15 additions & 16 deletions src/tests/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -19,25 +29,23 @@ 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
}
}
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)
}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a59748a

Please sign in to comment.