Testing and the browser
Tests
Tic-tac-toe's tests use MockCtx (crates/dg-games/src/mock.rs), a fake Ctx with balances, height and
events, so a test is a few lines:
ctx.submit(&TicTacToe, ALICE, json!({"kind": "create", "stake": "100"}))?;
Write a test for every op and every failure path. Tic-tac-toe covers: a win takes the pot, a draw refunds both players, a free game moves no GOLD, only the player to move may move, bad or occupied cells, invited opponents, cancel (refund, only while open), timeout after 150 blocks, joining without enough GOLD, bad ops, and the views.
Rust is built on the build host, never on a laptop: scripts/remote-test.sh test -p dg-games.
The browser game
web/play/tictactoe is a plain page: no framework, no build step. It uses the SDK, web/sdk/divigames.js:
- Create or load a key,
new Chain()for the node. signTx(key, {nonce, action: {type:"game", game:"tictactoe", op:{...}}}), thenchain.submit(tx).- Read the receipt, and redraw from
tictactoe.*events arriving on/v1/ws.
Amounts are decimal strings of base units; use formatAmount(units, 2) to show GOLD.
Checklist for your own game
- [ ] one file in
crates/dg-games/src/and one line inall(), - [ ] ops, state keys, events and views documented at the top,
- [ ] deterministic: heights and
public_random, no clocks, floats or hash-map order, - [ ] every op and failure path tested,
- [ ] every stake leaves escrow again on every ending (win, draw, cancel, timeout).