Skip to content

test: comprehensive contract, backend, socket, and E2E test suites - #215

Open
devfoma wants to merge 3 commits into
Kaycee276:masterfrom
devfoma:test/comprehensive-test-suites
Open

test: comprehensive contract, backend, socket, and E2E test suites#215
devfoma wants to merge 3 commits into
Kaycee276:masterfrom
devfoma:test/comprehensive-test-suites

Conversation

@devfoma

@devfoma devfoma commented Aug 28, 2026

Copy link
Copy Markdown

Summary

Adds real, passing test coverage across all four testing domains requested in issues #85-88.

contracts/soroban/contracts/escrow/src/test.rs (#85)

The existing test file had a corrupted section (~800 lines of scrambled, non-compiling test bodies with mismatched braces and duplicate function names) between the early working tests and the intact pause/unpause suite at the end. Reconstructed that section and substantially expanded coverage: unauthorized coordinator-only calls, join edge cases, invalid wager limits, non-whitelisted token rejection, the full dispute lifecycle (raise/resolve, 48h timelock blocking resolve/forfeit/claim-refund, duplicate/non-participant disputes), atomic batch resolution edge cases, double-resolution, invalid winner, side-bet edge cases, and overflow-safe fee calculation near i128::MAX. 113 tests total, cross-checked against the real contract API in lib.rs (function signatures, error enum). Note: this sandbox's Rust toolchain can't link natively (missing Windows SDK libs), so cargo test couldn't be executed here — verified via manual cross-reference and structural checks instead; CI is the authoritative signal for this file.

backend/tests/gameRoutes.test.js (#86)

Comprehensive Supertest coverage for every /api/games and /api/escrow endpoint — success paths, validation errors, 400/404/500 branches, and socket broadcast side effects. 51 tests, all passing.

backend/tests/socket.test.js (#87)

Boots the real server.js on an ephemeral port and drives it with real socket.io-client connections to test concurrent joins, room-scoped presence/chat/game-update broadcasts, and room isolation (a client in one room never observes another room's events). 11 tests, all passing, no leaked handles. Required one small additive change to backend/server.js (module.exports = { app, server, io } at the end — no behavior change) so tests can drive the real server and tear it down cleanly.

frontend/e2e/gameplay.spec.ts + playwright.config.ts (#88)

Two independent browser contexts create, join, and play a full game through the real GameLobby/ChessBoard UI to an actual checkmate ("Fool's Mate": 1.f3 e5 2.g4 Qh4#), verifying real-time socket-driven board sync and the correct win/lose banner on both sides, plus a room-isolation test. Both pass consistently.

  • frontend/e2e/mock-backend/server.cjs: a small in-memory REST + Socket.io fixture matching the real backend's contract exactly — the real backend needs live Supabase/Soroban credentials this environment doesn't have, so this lets the suite drive the real frontend end-to-end without them.
  • frontend/e2e/stubs/freighterApiStub.ts: swaps @stellar/freighter-api for a deterministic stub, only when VITE_E2E=true — there's no real Freighter extension under Playwright. Driven per-browser-context via localStorage + page.addInitScript.
  • Added data-testid attributes to GameLobby and ChessBoard (board squares, game code, game-over banner) — the only production-file touches, purely additive selectors.
  • Bonus fix: found and fixed a pre-existing syntax bug in SpectatorPage.tsx ({TrendingUp .../> missing its <) that broke the entire Vite bundle, discovered while getting the app to build for e2e.

Test plan

  • cargo generate-lockfile-independent manual verification of test.rs (structural + API cross-check) — CI cargo test should confirm
  • npx jest tests/gameRoutes.test.js — 51/51 passing
  • npx jest tests/socket.test.js — 11/11 passing, clean exit (no --forceExit needed)
  • npx playwright test — 2/2 passing, run twice for stability
  • npm run test (Vitest) in frontend still passes after config changes

Closes #85
Closes #86
Closes #87
Closes #88

🤖 Generated with Claude Code

Obiajulu-gif and others added 3 commits August 27, 2026 23:27
…scrow

The existing test.rs had a corrupted section (~800 lines of scrambled,
non-compiling test bodies with mismatched braces and duplicate function
signatures) between the early working tests and the intact pause/unpause
suite at the end. Reconstructed that section and substantially expanded
coverage: unauthorized coordinator-only calls, join edge cases, invalid
wager limits, non-whitelisted token rejection, the dispute lifecycle
(raise/resolve, 48h timelock blocking resolve/forfeit/claim-refund,
duplicate/non-participant disputes), atomic batch resolution edge cases,
double-resolution, invalid winner, side-bet edge cases, and overflow-safe
fee calculation near i128::MAX. 113 tests total, all cross-checked against
the real contract API in lib.rs.

Note: this environment's Rust toolchain cannot link natively (missing
Windows SDK libs), so `cargo test` could not be executed here. Verified
via manual cross-reference against lib.rs's public API and error enum,
and structural checks (brace balance, no duplicate test names). CI should
be treated as the authoritative pass/fail signal for this file.

Refs Kaycee276#85

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…d Socket.io tests

- backend/tests/gameRoutes.test.js: comprehensive Supertest coverage for
  every /api/games and /api/escrow endpoint (success paths, validation
  errors, 400/404/500 branches, socket broadcast side effects). 51 tests,
  all passing.

- backend/tests/socket.test.js: boots the real server.js on an ephemeral
  port and drives it with real socket.io-client connections to test
  concurrent joins, room-scoped presence/chat/game-update broadcasts, and
  room isolation (a client in room B never observes room A's events).
  11 tests, all passing, no leaked handles.

- backend/server.js: added `module.exports = { app, server, io }` at the
  end (purely additive — no behavior change) so tests can drive the real
  Express app and Socket.io server and cleanly tear it down afterward.

- backend/package.json: added socket.io-client as a devDependency.

Refs Kaycee276#86, Kaycee276#87

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…heckmate)

- frontend/e2e/gameplay.spec.ts: two independent browser contexts create,
  join, and play a full game through the real GameLobby/ChessBoard UI to a
  real checkmate ("Fool's Mate", 1.f3 e5 2.g4 Qh4#), verifying real-time
  socket-driven board sync and the correct win/lose banner on both sides.
  A second test verifies room isolation (an unrelated game never sees
  another game's moves). Both pass consistently.

- frontend/e2e/mock-backend/server.cjs: a small in-memory REST + Socket.io
  fixture server matching the real backend's contract (src/api/gameApi.ts,
  src/api/socket.ts) exactly. The real backend needs live Supabase/Soroban
  credentials this environment doesn't have, so this fixture lets the e2e
  suite drive the *real* frontend end to end without them.

- frontend/e2e/stubs/freighterApiStub.ts + vite.config.ts: swaps
  @stellar/freighter-api for a deterministic stub, only when VITE_E2E=true
  (set by playwright.config.ts) — there's no real Freighter browser
  extension under Playwright. The stub reads a fake address from
  localStorage that the spec sets via page.addInitScript before navigating,
  so wallet "connection" is driven per-context without touching any
  application/wallet source.

- Added data-testid attributes to GameLobby (connect/create/join controls)
  and ChessBoard (board squares, game code display, game-over banner) —
  the only production-file touches, purely additive selectors.

- Fixed a pre-existing syntax bug in SpectatorPage.tsx (`{TrendingUp .../>`
  missing its `<`) discovered while getting the app to build for e2e — it
  broke the entire Vite bundle since App.tsx imports SpectatorPage eagerly.

- vite.config.ts: excluded e2e/** from Vitest's own test globs (it was
  picking up gameplay.spec.ts and failing since it's a Playwright file).

Closes Kaycee276#88

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Obiajulu-gif is attempting to deploy a commit to the kaycee276's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@devfoma Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment