- Home
- Skills
- Dojoengine
- Book
- Dojo Test
dojo-test_skill
- TypeScript
51
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill dojoengine/book --skill dojo-test- SKILL.md8.2 KB
Overview
This skill generates comprehensive tests for Dojo models and systems using spawn_test_world, cheat codes, and assertions. It focuses on producing unit and integration tests that verify game logic, state transitions, and system behaviors in TypeScript/Cairo test environments. Use it to speed up test creation and ensure consistent test patterns.
How this skill works
The skill scaffolds test files and test functions that set up a test world with spawn_test_world, register models and systems, and sync permissions. It inserts assertions, model read/write checks, and cheat-code calls (set_caller_address, set_contract_address, set_block_timestamp, etc.) to manipulate execution context and verify state changes. It can create unit tests in model files and integration tests in a tests directory following Dojo conventions.
When to use it
- When you need unit tests for models (inline #[cfg(test)] modules).
- When writing integration tests for systems using spawn_test_world().
- To validate state transitions after system actions (moves, spawns, combat).
- When testing multi-player scenarios or permissioned interactions.
- To reproduce edge cases using cheat codes (timestamps, caller/contract addresses).
Best practices
- Keep unit tests next to model code for fast feedback and clearer context.
- Use spawn_test_world with a NamespaceDef to register only needed resources and contracts.
- Prefer world.read_model and world.write_model_test for deterministic state checks and bypassing permissions when needed.
- Use cheat codes to simulate callers, contracts, and time-based logic instead of complex setup flows.
- Assert both positive (happy path) and negative (should_panic) scenarios; test state before and after actions.
Example use cases
- Write a test verifying move system updates Position and decrements Moves remaining.
- Add unit tests for a Position model: zero-vector checks and equality helpers.
- Create integration tests that spawn players, perform actions, and assert independent player state.
- Use testing::set_block_timestamp to validate time-gated abilities or events.
- Write a should_panic test to ensure actions fail when preconditions (no moves left) are violated.
FAQ
Define a NamespaceDef with the model and event class hashes and pass [ndef].span() to spawn_test_world() to create the test world.
When should I use write_model_test vs read_model?
Use read_model for normal state inspection; use write_model_test to bypass permissions during setup or to inject specific states for edge-case tests.