better settings, 3rd node

This commit is contained in:
hatim boufnichel 2024-04-04 22:43:03 +02:00
parent a95becbfb6
commit 229cfa7a95
7 changed files with 57 additions and 19 deletions

View file

@ -44,7 +44,7 @@ export const getLogger = (params: LoggerParams): PubLogger => {
if (params.userId) {
toLog.push(params.userId)
}
const parsed = message.map(m => typeof m === 'object' ? JSON.stringify(m) : m)
const parsed = message.map(m => typeof m === 'object' ? JSON.stringify(m, (_, v) => typeof v === 'bigint' ? v.toString() : v) : m)
const final = `${toLog.join(" ")} >> ${parsed.join(" ")}`
console.log(final)
writers.forEach(w => w(final))

View file

@ -12,7 +12,7 @@ export const LoadLndSettingsFromEnv = (): LndSettings => {
const feeRateLimit = EnvMustBeInteger("OUTBOUND_MAX_FEE_BPS") / 10000
const feeFixedLimit = EnvMustBeInteger("OUTBOUND_MAX_FEE_EXTRA_SATS")
const mockLnd = EnvCanBeBoolean("MOCK_LND")
return { lndAddr, lndCertPath, lndMacaroonPath, feeRateLimit, feeFixedLimit, mockLnd, otherLndAddr: "", otherLndCertPath: "", otherLndMacaroonPath: "" }
return { mainNode: { lndAddr, lndCertPath, lndMacaroonPath }, feeRateLimit, feeFixedLimit, mockLnd }
}
export interface LightningHandler {
Stop(): void

View file

@ -40,7 +40,7 @@ export default class {
this.invoicePaidCb = invoicePaidCb
this.newBlockCb = newBlockCb
this.htlcCb = htlcCb
const { lndAddr, lndCertPath, lndMacaroonPath } = this.settings
const { lndAddr, lndCertPath, lndMacaroonPath } = this.settings.mainNode
const lndCert = fs.readFileSync(lndCertPath);
const macaroon = fs.readFileSync(lndMacaroonPath).toString('hex');
const sslCreds = credentials.createSsl(lndCert);

View file

@ -1,16 +1,17 @@
import { HtlcEvent } from "../../../proto/lnd/router"
export type LndSettings = {
export type NodeSettings = {
lndAddr: string
lndCertPath: string
lndMacaroonPath: string
}
export type LndSettings = {
mainNode: NodeSettings
feeRateLimit: number
feeFixedLimit: number
mockLnd: boolean
otherLndAddr: string
otherLndCertPath: string
otherLndMacaroonPath: string
otherNode?: NodeSettings
thirdNode?: NodeSettings
}
type TxOutput = {
hash: string

View file

@ -1,5 +1,5 @@
import { LoadStorageSettingsFromEnv, StorageSettings } from '../storage/index.js'
import { LndSettings } from '../lnd/settings.js'
import { LndSettings, NodeSettings } from '../lnd/settings.js'
import { LoadWatchdogSettingsFromEnv, WatchdogSettings } from './watchdog.js'
import { LoadLndSettingsFromEnv } from '../lnd/index.js'
import { EnvMustBeInteger, EnvMustBeNonEmptyString } from '../helpers/envParser.js'
@ -44,7 +44,7 @@ export const LoadMainSettingsFromEnv = (): MainSettings => {
}
}
export const LoadTestSettingsFromEnv = (): MainSettings => {
export const LoadTestSettingsFromEnv = (): MainSettings & { lndSettings: { otherNode: NodeSettings, thirdNode: NodeSettings } } => {
const eventLogPath = `logs/eventLogV2Test${Date.now()}.csv`
const settings = LoadMainSettingsFromEnv()
return {
@ -52,9 +52,16 @@ export const LoadTestSettingsFromEnv = (): MainSettings => {
storageSettings: { dbSettings: { ...settings.storageSettings.dbSettings, databaseFile: ":memory:", metricsDatabaseFile: ":memory:" }, eventLogPath },
lndSettings: {
...settings.lndSettings,
otherLndAddr: EnvMustBeNonEmptyString("LND_OTHER_ADDR"),
otherLndCertPath: EnvMustBeNonEmptyString("LND_OTHER_CERT_PATH"),
otherLndMacaroonPath: EnvMustBeNonEmptyString("LND_OTHER_MACAROON_PATH")
otherNode: {
lndAddr: EnvMustBeNonEmptyString("LND_OTHER_ADDR"),
lndCertPath: EnvMustBeNonEmptyString("LND_OTHER_CERT_PATH"),
lndMacaroonPath: EnvMustBeNonEmptyString("LND_OTHER_MACAROON_PATH")
},
thirdNode: {
lndAddr: EnvMustBeNonEmptyString("LND_THIRD_ADDR"),
lndCertPath: EnvMustBeNonEmptyString("LND_THIRD_CERT_PATH"),
lndMacaroonPath: EnvMustBeNonEmptyString("LND_THIRD_MACAROON_PATH")
}
},
skipSanityCheck: true
}

View file

@ -27,6 +27,7 @@ export type TestBase = {
user2: TestUserData
externalAccessToMainLnd: LND
externalAccessToOtherLnd: LND
externalAccessToThirdLnd: LND
d: Describe
}
@ -45,16 +46,21 @@ export const SetupTest = async (d: Describe): Promise<TestBase> => {
const externalAccessToMainLnd = new LND(settings.lndSettings, console.log, console.log, () => { }, () => { })
const otherLndSetting = { ...settings.lndSettings, lndCertPath: settings.lndSettings.otherLndCertPath, lndMacaroonPath: settings.lndSettings.otherLndMacaroonPath, lndAddr: settings.lndSettings.otherLndAddr }
const externalAccessToOtherLnd = new LND(otherLndSetting, console.log, console.log, () => { }, () => { })
await externalAccessToMainLnd.Warmup()
const otherLndSetting = { ...settings.lndSettings, mainNode: settings.lndSettings.otherNode }
const externalAccessToOtherLnd = new LND(otherLndSetting, console.log, console.log, () => { }, () => { })
await externalAccessToOtherLnd.Warmup()
const thirdLndSetting = { ...settings.lndSettings, mainNode: settings.lndSettings.thirdNode }
const externalAccessToThirdLnd = new LND(thirdLndSetting, console.log, console.log, () => { }, () => { })
await externalAccessToThirdLnd.Warmup()
return {
expect, main, app,
user1, user2,
externalAccessToMainLnd, externalAccessToOtherLnd,
externalAccessToMainLnd, externalAccessToOtherLnd, externalAccessToThirdLnd,
d
}
}

View file

@ -4,16 +4,36 @@ import { Describe, SetupTest, teardown, TestBase } from './testBase.js'
type TestModule = {
ignore?: boolean
dev?: boolean
default: (T: TestBase) => Promise<void>
}
let failures = 0
const start = async () => {
const files = await globby("**/*.spec.js")
const modules: { file: string, module: TestModule }[] = []
let devModule = -1
for (const file of files) {
console.log(file)
const module = await import(`./${file.slice("build/src/tests/".length)}`) as TestModule
await runTestFile(file, module)
modules.push({ module, file })
if (module.dev) {
if (devModule !== -1) {
console.error(redConsole, "there are multiple dev modules", resetConsole)
return
}
devModule = modules.length - 1
}
}
if (devModule !== -1) {
console.log("running dev module")
await runTestFile(modules[devModule].file, modules[devModule].module)
return
}
else {
console.log("running all tests")
for (const { file, module } of modules) {
await runTestFile(file, module)
}
}
if (failures) {
console.error(redConsole, "there have been", `${failures}`, "failures in all tests", resetConsole)
@ -24,11 +44,15 @@ const start = async () => {
}
const runTestFile = async (fileName: string, mod: TestModule) => {
console.log(fileName)
const d = getDescribe(fileName)
if (mod.ignore) {
d("-----ignoring file-----")
d("-----ignoring this file-----")
return
}
if (mod.dev) {
d("-----running only this file-----")
}
const T = await SetupTest(d)
try {
d("test starting")