feat(dojo-core): add WORLD_VERSION in cairo module and IWorldDispatcher - #3357
Conversation
|
ohayo sensei, WalkthroughIntroduces a WORLD_VERSION constant and a world_version getter in the Cairo world contract and trait, exposes corresponding Rust abigen calls, adds tests verifying version consistency with Cargo package version and at runtime, configures release-time version replacement in Cargo.toml, and updates an example world address. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as Client App
participant Reader as WorldContractReader
participant Prov as Provider
participant World as World Contract
App->>Reader: world_version()
Reader->>Prov: call(FunctionCall{name:"world_version", calldata:[]})
Prov->>World: invoke world_version()
World-->>Prov: return WORLD_VERSION
Prov-->>Reader: Felt(WORLD_VERSION)
Reader-->>App: Felt(WORLD_VERSION)
note over World: WORLD_VERSION is a pub const in contract
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/dojo/core/Cargo.toml (1)
12-12: Add max = 1 to pre-release replacement for safety.
Ohayo, sensei. Guard against accidental multiple matches during release.Apply:
- { file = "src/world/world_contract.cairo", search = "^\\s*pub const WORLD_VERSION: felt252 = '.*';$", replace = " pub const WORLD_VERSION: felt252 = '{{version}}';", min = 1 }, + { file = "src/world/world_contract.cairo", search = "^\\s*pub const WORLD_VERSION: felt252 = '.*';$", replace = " pub const WORLD_VERSION: felt252 = '{{version}}';", min = 1, max = 1 },
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
spawn-and-move-db.tar.gzis excluded by!**/*.gz
📒 Files selected for processing (7)
crates/dojo/core-tests/src/tests/world/world.cairo(1 hunks)crates/dojo/core/Cargo.toml(1 hunks)crates/dojo/core/src/lib.rs(1 hunks)crates/dojo/core/src/world/iworld.cairo(1 hunks)crates/dojo/core/src/world/world_contract.cairo(2 hunks)crates/dojo/world/src/contracts/abigen/world.rs(2 hunks)examples/spawn-and-move/dojo_dev.toml(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-05T04:29:12.288Z
Learnt from: glihm
PR: dojoengine/dojo#2633
File: crates/dojo/core/src/world/storage.cairo:484-0
Timestamp: 2024-11-05T04:29:12.288Z
Learning: In the Cairo codebase for the Dojo project, within `crates/dojo/core/src/world/storage.cairo`, length checks between `entity_ids` and `values` are not required in test API functions like `write_values_from_ids_test`.
Applied to files:
crates/dojo/core-tests/src/tests/world/world.cairo
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: fmt
🔇 Additional comments (8)
crates/dojo/core/src/world/world_contract.cairo (2)
373-375: world_version getter is correct and ABI-friendly.
Ohayo, sensei. View method returns the constant without storage reads; good gas behavior.
57-57: Approve addition of WORLD_VERSION
Ohayo, sensei — semver as a short-string felt252 is spot-on and the release regex matches. Ensure tooling stays in sync with Cargo.toml.crates/dojo/core-tests/src/tests/world/world.cairo (1)
73-81: Test asserting runtime value equals the constant is solid.
Ohayo, sensei. This covers the on-chain getter against the module constant; pairs well with the Rust-side Cargo version check.crates/dojo/core/src/lib.rs (1)
3-30: Compile-time workspace/version parity test is concise and effective.
Ohayo, sensei. The scan/split approach is robust to indentation and formatting changes around the constant.examples/spawn-and-move/dojo_dev.toml (1)
72-72: Ensure example world_address consistency
Ohayo, sensei. Only two hardcoded addresses remain in examples/spawn-and-move:dojo_dev.toml(updated) anddojo_release.toml. Confirm the release address is correct or update it to match.crates/dojo/world/src/contracts/abigen/world.rs (2)
4142-4153: ohayo sensei – world_version call wiring looks solidThe new getter mirrors the existing pattern, keeps calldata empty, and routes through
FCallas expected.
5154-5167: ohayo sensei – reader side keeps the version query consistentMirrors the account-backed variant precisely, so downstream consumers can retrieve the version in read-only contexts too.
crates/dojo/core/src/world/iworld.cairo (1)
29-31: ohayo sensei – glad to see world_version exposed at the interfaceThis pairs cleanly with the contract implementation and keeps ABI consumers aligned.
This PR adds a
WORLD_VERSIONconstant accessible from Cairo module directly.This constant is also exposed with a
world_versionentrypoint when using theIWorldDispatcherinterface.To ensure the
WORLD_VERSIONis always matching theCargo.tomlfile, thecargo releasewill automatically update the version.A test was added to ensure the version matching.
Summary by CodeRabbit
New Features
Tests
Chores