forked from karagozemin/OverSync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharness.ts
More file actions
160 lines (142 loc) · 6.43 KB
/
Copy pathharness.ts
File metadata and controls
160 lines (142 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* OverSync Sepolia/Stellar load-test harness.
*
* Dry-run (default — no keys or live RPC needed):
* pnpm --filter @oversync/e2e load-test
*
* Custom order count / seed:
* LOAD_TEST_ORDERS=50 LOAD_TEST_SEED=my-run pnpm --filter @oversync/e2e load-test
*
* Live testnet mode (requires SEPOLIA_RPC_URL + RESOLVER_ETH_PRIVATE_KEY):
* LOAD_TEST_LIVE=true LOAD_TEST_ORDERS=20 pnpm --filter @oversync/e2e load-test
*
* Full 1k-order soak (requires LOAD_TEST_ALLOW_LARGE=true in live mode):
* LOAD_TEST_LIVE=true LOAD_TEST_ORDERS=1000 LOAD_TEST_ALLOW_LARGE=true \
* LOAD_TEST_RATE_PER_SEC=3 pnpm --filter @oversync/e2e load-test
*
* See e2e/load-test/config.ts for the full list of env vars.
*/
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { loadConfig } from "./config.js";
import { generateOrders } from "./orders.js";
import { runOrders } from "./runner.js";
import { buildReport, writeReports } from "./report.js";
const here = dirname(fileURLToPath(import.meta.url));
function bar(filled: number, total: number, width = 30): string {
const pct = total > 0 ? filled / total : 0;
const done = Math.round(pct * width);
return `[${"#".repeat(done)}${".".repeat(width - done)}] ${(pct * 100).toFixed(0).padStart(3)} %`;
}
async function main(): Promise<void> {
// -------------------------------------------------------------------------
// 1. Load + validate config
// -------------------------------------------------------------------------
let config;
try {
config = loadConfig();
} catch (err) {
process.stderr.write(
`\n[ERROR] Configuration failure:\n ${err instanceof Error ? err.message : err}\n\n`
);
process.stderr.write(
"Run without LOAD_TEST_LIVE to use dry-run mode (no keys required).\n\n"
);
process.exit(1);
}
const mode = config.dryRun ? "DRY-RUN (simulated)" : "LIVE — Sepolia + Stellar testnet";
process.stdout.write(`\n${"═".repeat(56)}\n`);
process.stdout.write(` OverSync Load-Test Harness\n`);
process.stdout.write(`${"═".repeat(56)}\n`);
process.stdout.write(` Mode : ${mode}\n`);
process.stdout.write(` Seed : ${config.seed}\n`);
process.stdout.write(` Orders : ${config.orders}\n`);
process.stdout.write(` Concurrency : ${config.concurrency} workers\n`);
process.stdout.write(` Rate limit : ${config.rateLimitPerSec} orders / sec\n`);
process.stdout.write(` Timelock : ${config.timelockSeconds} s\n`);
if (!config.dryRun) {
process.stdout.write(` Sepolia RPC : ${config.sepoliaRpcUrl}\n`);
process.stdout.write(` Soroban RPC : ${config.sorobanRpcUrl}\n`);
}
process.stdout.write(`${"─".repeat(56)}\n\n`);
// -------------------------------------------------------------------------
// 2. Generate deterministic orders
// -------------------------------------------------------------------------
process.stdout.write(`Generating ${config.orders} deterministic orders...\n`);
const orders = generateOrders(config.seed, config.orders, config.timelockSeconds);
const ethToXlm = orders.filter((o) => o.direction === "ETH_TO_XLM").length;
const xlmToEth = orders.filter((o) => o.direction === "XLM_TO_ETH").length;
const plannedFills = orders.filter((o) => o.resolverAction === "fill").length;
const plannedTimeouts = orders.filter((o) => o.resolverAction === "timeout").length;
process.stdout.write(
` Direction mix : ${ethToXlm} ETH→XLM / ${xlmToEth} XLM→ETH\n`
);
process.stdout.write(
` Resolver plan : ${plannedFills} fills / ${plannedTimeouts} timeouts\n`
);
process.stdout.write(
` Est. RPC calls: ${plannedFills * 4 + plannedTimeouts * 3}\n\n`
);
// -------------------------------------------------------------------------
// 3. Run
// -------------------------------------------------------------------------
process.stdout.write(`Running orders...\n`);
const startMs = Date.now();
let lastPrint = 0;
const results = await runOrders(orders, config, (_result, completed, total) => {
const now = Date.now();
if (now - lastPrint >= 250 || completed === total) {
process.stdout.write(`\r ${bar(completed, total)} ${completed}/${total}`);
lastPrint = now;
}
});
const durationMs = Date.now() - startMs;
process.stdout.write(`\n\n`);
// -------------------------------------------------------------------------
// 4. Summarise to stdout
// -------------------------------------------------------------------------
const filled = results.filter((r) => r.status === "filled").length;
const timedOut = results.filter((r) => r.status === "timed-out").length;
const failed = results.filter((r) => r.status === "failed").length;
const passRate =
results.length > 0
? (((filled + timedOut) / results.length) * 100).toFixed(1)
: "0.0";
process.stdout.write(`${"─".repeat(56)}\n`);
process.stdout.write(` Filled : ${filled}\n`);
process.stdout.write(` Timed-out : ${timedOut}\n`);
process.stdout.write(` Failed : ${failed}\n`);
process.stdout.write(` Pass rate : ${passRate} %\n`);
process.stdout.write(` Duration : ${(durationMs / 1000).toFixed(2)} s\n`);
process.stdout.write(`${"─".repeat(56)}\n\n`);
if (failed > 0) {
const sample = results
.filter((r) => r.status === "failed")
.slice(0, 3);
process.stderr.write(`[WARN] ${failed} order(s) failed. First failures:\n`);
for (const f of sample) {
process.stderr.write(` #${f.index} ${f.orderId} — ${f.errorMessage}\n`);
}
if (failed > 3) {
process.stderr.write(` …and ${failed - 3} more (see JSON report).\n`);
}
process.stderr.write(`\n`);
}
// -------------------------------------------------------------------------
// 5. Write reports
// -------------------------------------------------------------------------
const report = buildReport(config, orders, results, durationMs);
const outputDir = resolve(here, config.outputDir);
const { jsonPath, mdPath } = writeReports(report, outputDir);
process.stdout.write(`Reports written:\n`);
process.stdout.write(` JSON : ${jsonPath}\n`);
process.stdout.write(` MD : ${mdPath}\n\n`);
process.stdout.write(
`Reproduce: LOAD_TEST_SEED=${config.seed} pnpm --filter @oversync/e2e load-test\n\n`
);
process.exit(failed > 0 ? 1 : 0);
}
main().catch((err) => {
process.stderr.write(`\n[FATAL] ${err instanceof Error ? err.stack : err}\n`);
process.exit(1);
});