Commit a6e91cf
Edward (OpenClaw)
test(defi/clob): replace JS tests with LiteSVM Rust, align with repo conventions
Bring the CLOB example in line with the repo's Anchor 1.0 + LiteSVM Rust
test convention established by tokens/escrow and defi/asset-leasing.
Previously CLOB shipped a TypeScript suite backed by Codama-generated
clients and @solana/kit, which was a one-off in the current examples
set.
Why:
- Every other defi/*/anchor and the tokens/escrow example now uses
LiteSVM-driven Rust tests that `include_bytes!` the built .so,
share a common test-stack (litesvm + solana-kite + solana-signer),
and run under a plain `cargo test`. Contributors moving between
examples had to relearn the CLOB harness (Codama client generation,
surfpool-vs-legacy validator selection, tsx + node:test runner).
- The JS suite also required `anchor test --validator legacy` because
Anchor 1.0's default surfpool validator does not expose the
websocket RPC methods Kit uses for confirmation. Switching to
LiteSVM Rust sidesteps that entirely — no validator at all.
Changes:
- Anchor.toml: drop anchor_version, package_manager, [hooks], [test]
blocks. Set `[scripts] test = "cargo test"` matching asset-leasing.
Keep solana_version = 3.1.8 pinned so BPF toolchain stays in lock-step.
- programs/clob/Cargo.toml: add [dev-dependencies] for litesvm 0.11,
solana-signer 3.0, solana-keypair 3.0.1, solana-kite 0.3. Versions
match the rest of the repo to avoid drift.
- programs/clob/tests/test_clob.rs: 13 LiteSVM tests covering
initialize_market (happy path + zero-tick + oversized-fee rejection),
create_user_account, place_order (bid locks quote, ask locks base,
zero-price / unaligned-tick / below-min rejections), cancel_order
(owner refund credited to unsettled, non-owner rejected), and
settle_funds (drains unsettled balance from vault to user ATA for
both an ask cancel and a bid cancel + full refund round-trip).
- programs/clob/src/lib.rs and instructions/*.rs: rename the verbose
`*AccountConstraints` struct suffix to the plain `InitializeMarket`,
`PlaceOrder`, etc. naming that every other Anchor example in the
repo uses. Rename handler functions from bare `initialize_market` to
`handle_initialize_market` to match escrow and asset-leasing.
- README.md: replace the TS/Codama test instructions with the Rust
LiteSVM flow; drop the surfpool caveat (no longer relevant).
- Remove tests/clob.test.ts, package.json, tsconfig.json: no JS/TS
scaffolding needed now that testing is pure Rust.
- .gitignore: drop the now-unused `dist` entry (the Codama client
output directory).
Scope note carried into the tests: the program does not run a
matching engine, it only keeps the book and escrow the funds. The
test file's header comment calls this out so the reader does not
look for cross-order settlement tests that cannot exist yet.
Test result: `anchor build && cargo test` → 13 passed, 0 failed.1 parent ee1c84f commit a6e91cf
14 files changed
Lines changed: 946 additions & 556 deletions
File tree
- defi/clob/anchor
- programs/clob
- src
- instructions
- tests
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 40 | + | |
43 | 41 | | |
44 | 42 | | |
45 | 43 | | |
46 | | - | |
| 44 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
27 | 36 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
0 commit comments