feat: add macros and core-test crates
Add macros and core-test crates to be integrated into Dojo after bumping to Cairo 2.11.2.
Summary by CodeRabbit
-
New Features
- Introduced a comprehensive suite of procedural macros for the Dojo framework, including macros for models, events, contracts, and libraries.
- Added utility macros for byte array hashing and selector computation.
- Provided extensive test utilities and helper modules for deploying and testing contracts, models, events, and libraries within simulated environments.
-
Bug Fixes
- Improved diagnostics and error reporting for macro usage and validation.
-
Tests
- Added extensive unit and integration test suites covering models, events, contracts, storage, permissions, upgrades, metadata, and utility functions.
-
Documentation
- Enhanced inline code documentation and structured configuration files for new crates and test environments.
-
Chores
- Added new workspace dependencies and configuration files for macro and test crates.
- Updated subproject references for UI components.
Walkthrough
Ohayo sensei! This update introduces a comprehensive test infrastructure and macro system for the Dojo framework. It adds new workspace dependencies, including cairo-lang-primitive-token and a temporary git-sourced cairo-lang-macro. The dojo_macros crate is established, implementing procedural and inline macros for models, events, contracts, and libraries, as well as utility macros like bytearray_hash and selector_from_tag. The core-test crate is expanded with configuration files, utility modules, and a wide array of modular test suites covering world, model, event, storage, and contract behaviors. The macros and helpers provide structured code generation and introspection, while the tests validate the full Dojo contract lifecycle and system logic.
Changes
| File(s) / Path(s) | Change Summary |
|---|---|
Cargo.toml |
Added workspace dependencies: cairo-lang-primitive-token and cairo-lang-macro (from Scarb git, temporary). |
crates/dojo/macros/Cargo.toml, crates/dojo/macros/Scarb.toml |
Added manifest and Scarb config for the new dojo_macros crate. |
crates/dojo/macros/src/lib.rs |
Declared new macro modules: attributes, constants, derives, helpers, inlines. |
crates/dojo/macros/src/attributes/ (all files) |
Implemented procedural macros for dojo::model, dojo::event, dojo::contract, and dojo::library attributes, handling parsing, validation, code generation, and diagnostics. |
crates/dojo/macros/src/derives/ (all files) |
Added derive macros for Introspect and IntrospectPacked, including logic for struct and enum introspection, layout, size, and type metadata generation. |
crates/dojo/macros/src/inlines/ (all files) |
Implemented inline macros: bytearray_hash and selector_from_tag, with parsing, validation, and hash/selector computation. |
crates/dojo/macros/src/helpers/ (all files) |
Introduced helper utilities for parsing, formatting, diagnostics, tokenization, debugging, and unique hash computation for macro expansion. |
crates/dojo/macros/src/constants.rs |
Defined constants for macro derive names, delimiters, and function names. |
crates/dojo/core-test/Scarb.toml |
Added Scarb configuration for the core-test package, specifying dependencies, targets, and test scripts. |
crates/dojo/core-test/src/lib.cairo |
Introduced a new test module structure with public re-exports for test utilities, world simulation, and contract deployment. |
crates/dojo/core-test/src/utils.cairo |
Added utility functions and structs for gas measurement and array assertions in tests. |
crates/dojo/core-test/src/snf_utils.cairo |
Added utilities for contract declaration, deployment, and test environment manipulation (account/caller address setup). |
crates/dojo/core-test/src/world.cairo |
Introduced test world deployment utilities, resource registration, and contract permission synchronization logic. |
crates/dojo/core-test/src/tests/ (all files and subfolders) |
Added extensive modular test suites for contracts, events, models, storage, metadata, ACL, namespaces, and world state. Includes helpers for deploying worlds, models, contracts, and events, plus tests for hashing, key management, layout, and naming utilities. |
crates/katana/explorer/ui |
Updated subproject commit reference. |
Sequence Diagram(s)
sequenceDiagram
participant TestRunner
participant MacroSystem
participant DojoWorld
participant Contract
participant Event
participant Model
TestRunner->>MacroSystem: Expand #[dojo::model], #[dojo::event], etc.
MacroSystem->>Contract: Generate code (storage, events, traits)
MacroSystem->>Model: Generate introspection, serialization logic
MacroSystem->>Event: Generate event traits, serialization
TestRunner->>DojoWorld: Deploy world with resources (models, contracts, events)
TestRunner->>Contract: Deploy contract with init calldata
TestRunner->>DojoWorld: Register resource (model/event/contract)
TestRunner->>DojoWorld: Grant permissions (owner/writer)
TestRunner->>DojoWorld: Execute test (write/read/upgrade resource)
DojoWorld->>Contract: Call contract method (e.g., upgrade)
DojoWorld->>Event: Emit event
DojoWorld->>Model: Store/retrieve model data
TestRunner->>DojoWorld: Assert state, events, permissions
Possibly related PRs
- dojoengine/dojo#2337: Adds inline macros for testing that automate model class hash retrieval and test world spawning, complementing the test infrastructure and macro utilities in this PR.
- dojoengine/dojo#2946: Introduces the
bytearray_hashmacro and its tests, directly overlapping with the macro and test additions in this PR.
Suggested labels
contributor
Suggested reviewers
- glihm
[!TIP]
⚡💬 Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.