Skip to content

feat(dojo-core): add WORLD_VERSION in cairo module and IWorldDispatcher - #3357

Merged
glihm merged 1 commit into
mainfrom
feat/world-version
Sep 26, 2025
Merged

feat(dojo-core): add WORLD_VERSION in cairo module and IWorldDispatcher#3357
glihm merged 1 commit into
mainfrom
feat/world-version

Conversation

@glihm

@glihm glihm commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

This PR adds a WORLD_VERSION constant accessible from Cairo module directly.

This constant is also exposed with a world_version entrypoint when using the IWorldDispatcher interface.

To ensure the WORLD_VERSION is always matching the Cargo.toml file, the cargo release will automatically update the version.

A test was added to ensure the version matching.

Summary by CodeRabbit

  • New Features

    • Exposes the World contract version for querying, with client bindings updated to support reading it.
  • Tests

    • Adds end-to-end and unit tests validating that the on-chain version matches the package version and expected constant.
  • Chores

    • Automates version stamping during release to keep the contract’s reported version in sync with the package version.
    • Updates example configuration with a new world address.

@coderabbitai

coderabbitai Bot commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

ohayo sensei,

Walkthrough

Introduces 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

Cohort / File(s) Summary
World contract version API (Cairo)
crates/dojo/core/src/world/iworld.cairo, crates/dojo/core/src/world/world_contract.cairo
Added IWorld::world_version() signature and World impl returning new pub const WORLD_VERSION: felt252 = '1.7.1'.
Rust client bindings (abigen)
crates/dojo/world/src/contracts/abigen/world.rs
Added world_version() calls on WorldContract and WorldContractReader, constructing FunctionCall and returning Felt via provider.
Tests
crates/dojo/core-tests/src/tests/world/world.cairo, crates/dojo/core/src/lib.rs
New runtime test asserting dispatcher.world_version() equals WORLD_VERSION; new unit test parsing Cairo file to ensure WORLD_VERSION matches CARGO_PKG_VERSION.
Release config
crates/dojo/core/Cargo.toml
Added pre-release-replacements to set WORLD_VERSION in world_contract.cairo to {{version}} during release.
Example config
examples/spawn-and-move/dojo_dev.toml
Updated [env].world_address to a new value.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title highlights the addition of WORLD_VERSION and an interface but misnames the interface as IWorldDispatcher instead of referring to the new world_version method on the IWorld trait, which makes it unclear. It does not succinctly capture the primary change of exposing the version entrypoint and could confuse teammates reviewing history. Because of this mismatch, the title does not accurately summarize the main functionality added. Please update the title to something clear and specific, for example “feat(dojo-core): add WORLD_VERSION constant and world_version method to IWorld trait” so it accurately reflects the main changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/world-version

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3e3aef and 245c232.

⛔ Files ignored due to path filters (1)
  • spawn-and-move-db.tar.gz is 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) and dojo_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 solid

The new getter mirrors the existing pattern, keeps calldata empty, and routes through FCall as expected.


5154-5167: ohayo sensei – reader side keeps the version query consistent

Mirrors 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 interface

This pairs cleanly with the contract implementation and keeps ABI consumers aligned.

@glihm
glihm merged commit 958c62b into main Sep 26, 2025
10 checks passed
@glihm
glihm deleted the feat/world-version branch September 26, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant