mirror of
https://github.com/Routstr/routstrd.git
synced 2026-10-05 12:28:23 +00:00
The external `cocod` binary was replaced by the in-process Coco wallet long ago, but its HTTP/unix-socket client kept shipping ~280 lines of unreachable code next to the wallet contract. Remove it: - delete `createCocodClient` (spawns `cocod init`, talks over a unix socket, takes a cross-process startup lock) and its helpers `resolveCocodExecutable`, `isCocodInstalled`, `normalizeBalances` and `CocodBalanceOutput`. None of them are reachable from production or from tests; `isCocodInstalled` had no callers at all. - drop the `options.walletClient || createCocodClient(...)` fallback in `createWalletAdapter`. The daemon always passes the in-process client built by `createCocoClient()`, so `walletClient` is now required and the adapter can no longer silently spawn an external binary. - drop the vestigial `cocodPath` config key, which only ever fed that fallback. - delete the "legacy cocod client NPC passthroughs" test block, which covered only the deleted client. The shared wallet contract moves from `cocod-client.ts` to `wallet-client.ts` and loses its `Cocod` prefixes (`WalletClient`, `WalletRuntimeState`, `WalletHttpError`) — none of it describes cocod any more. `WalletRuntimeState` avoids colliding with the existing `WalletState` in `wallet-state.ts`. Legacy cocod *migration* code is deliberately untouched: `stopLegacyCocod`, `assertLegacyCocodNotRunning`, `claimLegacyCocodPidFile`, `migration.ts` and the `legacyCocod*` paths still migrate an existing `~/.cocod` wallet and fence off a running external daemon. Net -456 lines. Existing configs that still contain `cocodPath` load unchanged (unknown keys are ignored) — the key is just no longer written.
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
getDaemonBaseUrl,
|
|
urlHost,
|
|
urlHosts,
|
|
} from "../../src/utils/daemon-client";
|
|
import type { RoutstrdConfig } from "../../src/utils/config";
|
|
|
|
function config(host: string): RoutstrdConfig {
|
|
return {
|
|
port: 8008,
|
|
host,
|
|
provider: null,
|
|
};
|
|
}
|
|
|
|
describe("daemon URL host formatting", () => {
|
|
test("prefers IPv4 loopback for an IPv4 wildcard", () => {
|
|
expect(urlHosts("0.0.0.0")).toEqual(["127.0.0.1", "[::1]"]);
|
|
expect(getDaemonBaseUrl(config("0.0.0.0"))).toBe("http://127.0.0.1:8008");
|
|
});
|
|
|
|
test("prefers IPv6 loopback for an IPv6 wildcard", () => {
|
|
expect(urlHosts("::")).toEqual(["[::1]", "127.0.0.1"]);
|
|
expect(getDaemonBaseUrl(config("::"))).toBe("http://[::1]:8008");
|
|
});
|
|
|
|
test("brackets IPv6 literals", () => {
|
|
expect(urlHost("2001:db8::1")).toBe("[2001:db8::1]");
|
|
expect(getDaemonBaseUrl(config("2001:db8::1"))).toBe(
|
|
"http://[2001:db8::1]:8008",
|
|
);
|
|
});
|
|
|
|
test("does not bracket an already-bracketed IPv6 literal twice", () => {
|
|
expect(urlHost("[::1]")).toBe("[::1]");
|
|
});
|
|
|
|
test("escapes an IPv6 zone identifier for use in a URL", () => {
|
|
expect(urlHost("fe80::1%en0")).toBe("[fe80::1%25en0]");
|
|
});
|
|
|
|
test("leaves IPv4 addresses and hostnames unchanged", () => {
|
|
expect(urlHost("127.0.0.1")).toBe("127.0.0.1");
|
|
expect(urlHost("localhost")).toBe("localhost");
|
|
});
|
|
|
|
test("uses the default loopback when the host is absent", () => {
|
|
expect(urlHost()).toBe("127.0.0.1");
|
|
});
|
|
|
|
test("preserves an explicitly configured daemon URL", () => {
|
|
expect(
|
|
getDaemonBaseUrl({
|
|
...config("::"),
|
|
daemonUrl: "https://daemon.example/",
|
|
}),
|
|
).toBe("https://daemon.example");
|
|
});
|
|
});
|