61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { loadConfig } from "../src/config.js";
|
|
|
|
test("loadConfig parses relay input and ignores invalid entries", () => {
|
|
const config = loadConfig({
|
|
RELAYS: "wss://offchain.pub,not-a-url",
|
|
WRITE_CHECK_ENABLED: "false",
|
|
});
|
|
|
|
assert.equal(config.relays.length, 1);
|
|
assert.equal(config.relays[0]?.relay, "wss://offchain.pub/");
|
|
assert.equal(config.writeCheck.enabled, false);
|
|
assert.equal(config.probeIntervalMs, 0);
|
|
assert.ok(config.warnings.some((w) => w.includes("Ignoring invalid relay URL")));
|
|
});
|
|
|
|
test("loadConfig generates write-check private key when missing", () => {
|
|
const config = loadConfig({
|
|
RELAYS: "wss://offchain.pub",
|
|
WRITE_CHECK_ENABLED: "true",
|
|
});
|
|
|
|
assert.equal(config.writeCheck.enabled, true);
|
|
assert.match(config.writeCheck.privkey ?? "", /^[0-9a-f]{64}$/i);
|
|
assert.ok(
|
|
config.warnings.some((w) => w.includes("generated ephemeral write-check key")),
|
|
"expected warning about generated write-check key",
|
|
);
|
|
});
|
|
|
|
test("loadConfig generates write-check private key when configured key is invalid", () => {
|
|
const config = loadConfig({
|
|
RELAYS: "wss://offchain.pub",
|
|
WRITE_CHECK_ENABLED: "true",
|
|
WRITE_CHECK_PRIVKEY: "not-a-valid-key",
|
|
});
|
|
|
|
assert.equal(config.writeCheck.enabled, true);
|
|
assert.match(config.writeCheck.privkey ?? "", /^[0-9a-f]{64}$/i);
|
|
assert.notEqual(config.writeCheck.privkey, "not-a-valid-key");
|
|
assert.ok(
|
|
config.warnings.some((w) => w.includes("WRITE_CHECK_PRIVKEY invalid")),
|
|
"expected warning about invalid configured key",
|
|
);
|
|
});
|
|
|
|
test("loadConfig sets write-check read verification flag", () => {
|
|
const defaultConfig = loadConfig({
|
|
RELAYS: "wss://offchain.pub",
|
|
});
|
|
assert.equal(defaultConfig.writeCheck.verifyRead, true);
|
|
|
|
const verifyConfig = loadConfig({
|
|
RELAYS: "wss://offchain.pub",
|
|
WRITE_CHECK_VERIFY_READ: "false",
|
|
});
|
|
assert.equal(verifyConfig.writeCheck.verifyRead, false);
|
|
});
|