Skip to content

Test/trading fixtures and harness#41

Merged
JustaLiang merged 9 commits intofeat/new-contractfrom
test/trading-fixtures-and-harness
Apr 17, 2026
Merged

Test/trading fixtures and harness#41
JustaLiang merged 9 commits intofeat/new-contractfrom
test/trading-fixtures-and-harness

Conversation

@do0x0ob
Copy link
Copy Markdown
Contributor

@do0x0ob do0x0ob commented Apr 17, 2026

Summary

Generalizes integration/simulate test helpers for multi-collateral (USDC / USDSUI), tightens e2e preflight/prepare flows, and removes obsolete one-off scripts.

Changes

  • TTO simulate funding: Renamed/generalized ensure-tto-usdc-coins-for-simulateensure-tto-collateral-coins-for-simulate with documented behavior (USDC auto-split vs USDSUI requiring e2e:prepare).
  • Constants: Added X_STOCK_BASES and isXStockBase() for xStock Pyth oracle / market-hours considerations.
  • E2E scripts: Updates to e2e-preflight / e2e-prepare; README touch.
  • Tests: Adjustments across scratch trading lifecycle, collateral-order / lifecycle PTB / negative simulate suites; e2e-persistent-perp-slots updates.
  • Removed: Legacy scripts check-account-usdsui, check-eth-sui-positions, close-legacy-collateral-mismatch.

Testing

  • Run relevant simulate/integration tests and e2e flows as documented in repo test README.

do0x0ob added 7 commits April 17, 2026 18:21
Introduce JSON fixtures and load/regen tooling for trading scenarios.
Add simulate tests for delegate lifecycle and permission matrix, plus
unit tests for events, SDK inputs, and size formulas. Wire integration
setup and existing simulate suites to shared helpers; extend market
params and add WLP cancel/redeem probe script.

Made-with: Cursor
- Add test/fixtures/trading/trading-config.json as single source for lifecycle
  rows, persistent perp, enabled bases, thresholds, and wallet mins; remove
  split lifecycle-markets.json and persistent-perp.json.
- Delete dead helpers (trading-fixture-harness, lifecycle-oracle-usd-prices,
  wlp-pool-price-refresh); extract SCRATCH_EXPECT to scratch-scenario-steps.ts.
- Rename execIntegrationOrSkipOracle in integration setup and scratch runner;
  align testnet/oracle comments with Pyth-only v2; trim compute-leverage-size.
- Remove scripts/debug-oracle-aggregates.ts and setup-supra-oracle.sh; mark
  clear-supra-weights.sh as legacy migration; fix setup-pyth-identifiers.sh
  base types to market_symbol::*_USD.
- Rewrite scripts/README.md; update MIGRATION.md, test docs, and preflight copy.

Made-with: Cursor
…rage sim tests

- Preflight and e2e:prepare require recent on-chain positions per activeLifecycleTestBases;
  document persistentPerp coverage for bootstrap/integration.
- trading-config: add persistentPerp rows for xStock bases so bootstrap can open slots.
- Simulate: use on-chain resize for above-max leverage tests; assertSimulateMoveAbortOneOf for 104/105.
- Docs: README and e2e helper comments for preflight vs persistentPerp.

Note: .e2e-fixed-positions.local.json left unstaged (local snapshot).
Made-with: Cursor
- Add setup-e2e-delegate script, ensure-e2e-delegate helper, and simulate coverage for delegate flows; integrate with e2e-preflight, e2e-prepare, and npm scripts.

- Update trading fixtures, load-trading-fixtures, and local e2e position metadata; refresh README notes.

- Raise unit branch coverage: rawPrice bigint path; account PTB paths for bucketAccount and receiveCoin (v1 shape, amount, empty-input error). Add e2e-delegate-helpers unit tests.

Made-with: Cursor
- Extend e2e-prepare, e2e-preflight, and bootstrap-e2e-lifecycle-positions
- Add check-account-usdsui, check-eth-sui-positions, close-legacy-collateral-mismatch
- Add e2e-tto-split-thresholds helper; update persistent state and scratch scenarios
- Refresh integration/simulate tests and trading-config fixture; update docs
- Remove scripts/clear-supra-weights.sh

Made-with: Cursor
- Generalize ensure-tto helper for USDC/USDSUI; document auto-split limits
- Add X_STOCK_BASES / isXStockBase for oracle market-hours gating
- Extend e2e preflight/prepare and scratch integration lifecycle
- Remove legacy one-off position/collateral scripts
- Harden simulate tests (collateral order, lifecycle PTB, negative cases)

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Found 1 issue:

  1. This PR is too broad for safe review/rollback and mixes unrelated change classes.

The stated scope is test fixtures/harness alignment, but this diff also changes CI workflows, CLAUDE/MIGRATION/docs, script inventory, and committed local e2e position state in one unit. That coupling increases merge risk and makes regression isolation difficult.

Please split into focused PRs at least by concern:

  • test fixtures/harness/runtime behavior
  • CI workflow trigger policy
  • script cleanup/docs
  • local e2e state snapshot updates

This makes approvals safer and rollback practical if one track regresses.

Generated with Rex via OpenClaw

Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

No issues found (>=80 confidence) after focused review on test harness changes for breaking SDK alignment.

Checked areas:

  • multi-collateral test fixture migration (trading-config.json as single source)
  • preflight/prepare behavior alignment (USDSUI + delegate + xStock oracle-hours skip semantics)
  • CI trigger scope update (PRs to any base branch)
  • simulate stability updates (order-id race retry path)

Given this PR is intentionally a one-shot breaking-test alignment, the changes are coherent and internally consistent.

🤖 Generated with Rex (OpenClaw)

Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Updated review — the PR scope expanded significantly since my first pass. This supersedes the earlier approval.

Excellent refactoring: 68 files moving hardcoded TypeScript test config into trading-config.json, generalizing USDC-only helpers to multi-collateral (USDC/USDSUI), cleaning out Supra oracle remnants, and adding solid delegate/permission test coverage. The code is remarkably well-organised for a change this size.

Highlights

  • trading-config.json as single source of truth — lifecycle rows, persistent perp, iteration order, wallet thresholds, delegate config all in one place. load-trading-fixtures.ts parser is clean.
  • Multi-collateral generalisationensureTtoCollateralCoinsForSimulate, buildDepositCollateralFromWalletTx, ensureScratchLifecycleMinCollateral, per-row collateralAsset piped through every builder call. Thorough.
  • simulatePlaceCancelSinglePtbWithRetries — much better than the old single-shot orderId prediction. Re-fetches nextOrderId on 300, configurable max attempts.
  • assertSimulateMoveAbortOneOf — handles the 104-or-105 ambiguity cleanly.
  • Delegate test suitedelegate-lifecycle-simulate, delegate-permission-matrix-simulate, e2e-delegate-simulate give good coverage of the permission system.
  • move-event-payload.ts — robust parser handling multiple JSON shapes + BCS fallback for PositionOpened.
  • Supra cleanupsetup-supra-oracle.sh, clear-supra-weights.sh, debug-oracle-aggregates.ts removed; all oracle references updated to Pyth-only v2.
  • Unit tests — good additions for event-parsing, e2e-delegate-helpers, sdk-size-formula, sdk-input-type-contracts.

Nits / questions

  1. DEEP in persistentPerp.markets but not enabledE2eBases — the JSON has a full DEEP row under persistentPerp.markets and lifecycleMarkets, but DEEP is absent from enabledE2eBases. Since activeE2ePersistentPerpBases() filters by ENABLED_E2E_BASES, the DEEP perp row is dead config. Intentional "ready when we re-enable"? If so, a brief JSON comment or _disabled suffix would make that clearer.

  2. test-cancel-redeem-wlp.ts is 435 lines — thorough documentation and three well-defined scenarios, but it's a large script to review in one shot. Consider splitting buildRequestPlusCancelAndTransferPtb into its own module if you plan to reuse it.

  3. integrationOracleSimMaxAttempts / integrationOracleSimRetryDelayMs env-var helpers in scratch-lifecycle.ts — the max/min clamping is good (Math.min(10, Math.max(1, ...))) but there's no validation logging if someone passes a non-numeric string (it falls through to default silently via !Number.isFinite(n)). Fine for dev tooling, just noting.

  4. e2eDelegate.delegateAddress hardcoded in committed fixture0xa221d2... is baked into the repo. The env override (WATERX_E2E_DELEGATE_ADDRESS) covers CI, but contributors forking the repo may get confused when preflight checks fail for this address. A note in test/README.md under the delegate section explaining this would help.

  5. .e2e-fixed-positions.local.json changes — this file is checked in (not gitignored) and the diff updates position IDs. Is this expected to be committed, or should it be in .gitignore?

None of these are blocking — this is a clean, well-thought-out refactor.

LGTM 👍

- Rename requireOracleUsdOrSkip to oracleUsdForBaseOrSkip so esbuild/Vitest
  does not treat the import as CommonJS require (fixes runtime is not a function).
- Extend bundled oracle pricing + e2e preflight, fixtures, and scratch harness.

Made-with: Cursor
@JustaLiang JustaLiang merged commit 53992e7 into feat/new-contract Apr 17, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants