openpondai/agents/polymarket-market-watcher
OpenTool app
1Branch0Tags
OP
OpenPond Syncsync: merge local template master into production
typescript
import { afterEach, describe, expect, mock, test } from "bun:test";
import { resolveRuntimeConfig } from "./config";
import { resolveExecutableMarketSymbol } from "./market-symbol";
const originalFetch = globalThis.fetch;
afterEach(() => {
globalThis.fetch = originalFetch;
});
describe("resolveExecutableMarketSymbol", () => {
test("returns explicit marketSymbol without gateway lookup", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
asset: "BTC",
marketSymbol: "xyz:GOLD",
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("xyz:GOLD");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("returns explicit spot pair execution symbols without gateway lookup", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
asset: "HYPE",
execution: {
enabled: false,
symbol: "HYPE-USDC",
},
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("HYPE-USDC");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("falls back to the bare asset as a perp symbol", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
asset: "eth",
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("ETH");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("rejects raw Hyperliquid spot ids", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
asset: "HYPE",
execution: {
enabled: false,
symbol: "@107",
},
});
await expect(resolveExecutableMarketSymbol(config)).rejects.toThrow(
"Do not use @index spot ids",
);
expect(fetchSpy).not.toHaveBeenCalled();
});
});