Skip to content

Conversation

@MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Oct 18, 2025

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

  • New Features

    • Added a worldAddress configuration parameter for client setup.
    • Implemented consistent address formatting for world addresses across the client.
  • Dependencies

    • Added the starknet library as a dependency to support address formatting.

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Walkthrough

Adds Starknet address padding by introducing the starknet dependency and applying addAddressPadding to world addresses in client construction, SDK wiring, and address mapping; adds worldAddress: string to ToriiGrpcClientConfig and updates tests.

Changes

Cohort / File(s) Summary
Dependency Addition
packages/grpc/package.json
Adds the starknet dependency (catalog: spec) to package dependencies.
Client Configuration & Tests
packages/grpc/src/torii-client.ts, packages/grpc/src/torii-client.test.ts
Adds worldAddress: string to ToriiGrpcClientConfig; imports addAddressPadding and pads worldAddress in the constructor and tests.
SDK Integration
packages/sdk/src/createSDK.ts
Imports addAddressPadding and passes a padded worldAddress when constructing the Torii gRPC client.
Address Mapping
packages/grpc/src/mappings/query.ts
Imports addAddressPadding and applies it to world addresses before hexToBuffer in mapWorldAddresses.
Changeset
.changeset/bright-baths-itch.md
Adds a changeset entry bumping patch for @dojoengine/grpc and @dojoengine/sdk with a fix note about addAddressPadding on worldAddress.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant SDK as SDK (createSDK)
  participant Client as ToriiGrpcClient
  participant Mapping as mapWorldAddresses
  participant GRPC as gRPC service

  SDK->>Client: receive config.client.worldAddress
  Note right of Client: new: addAddressPadding(worldAddress)
  SDK->>Client: pass padded worldAddress

  Client->>Mapping: request world address conversion
  Mapping->>Mapping: addAddressPadding(address)
  Mapping->>Mapping: hexToBuffer(paddedAddress)
  Mapping->>GRPC: send buffered address
  GRPC-->>Client: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I padded each world, snug and neat,

hex bytes marching, tiny feet.
Starknet's hug around each string,
now addresses hop and sing. ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is largely incomplete and essentially consists of an unfilled template with only placeholder text. The "Closes #" line lacks an issue number, the "Introduced changes" section contains only a single dash with no actual description, and all checklist items remain unchecked. While the structure follows the required template format, the content is entirely absent—there is no substantive information about what changes were made, why they were made, or the status of any required tasks. Fill in the pull request description with actual content: specify the issue number being resolved in the "Closes #" line, provide a clear summary of the introduced changes explaining how address padding is being applied to worldAddress values across the affected files, and review or update the checklist items based on what was actually done (such as whether documentation was updated, tests were added, and self-review was performed).
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix(grpc): addAddressPadding on worldAddress" directly and clearly summarizes the primary change across the changeset. The title accurately reflects that the core modification involves adding address padding functionality to handle worldAddress values using the addAddressPadding function from starknet. The title is concise, specific, and uses the conventional "fix" prefix appropriately for a bug fix. A developer scanning the history would quickly understand the purpose of this change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/worldaddress

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9f7335 and f02b07e.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • .changeset/bright-baths-itch.md (1 hunks)
  • packages/grpc/package.json (1 hunks)
  • packages/grpc/src/mappings/query.ts (2 hunks)
  • packages/grpc/src/torii-client.test.ts (2 hunks)
  • packages/grpc/src/torii-client.ts (3 hunks)
  • packages/sdk/src/createSDK.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/sdk/src/createSDK.ts
  • packages/grpc/src/torii-client.ts
  • packages/grpc/src/torii-client.test.ts
  • packages/grpc/package.json
⏰ 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). (3)
  • GitHub Check: build-examples
  • GitHub Check: build-packages
  • GitHub Check: build
🔇 Additional comments (2)
packages/grpc/src/mappings/query.ts (1)

79-79: LGTM: Import added correctly.

The import of addAddressPadding from the starknet package is necessary for the address padding functionality.

.changeset/bright-baths-itch.md (1)

1-6: LGTM: Changeset format is correct.

The changeset properly marks both affected packages (@dojoengine/grpc and @dojoengine/sdk) for patch bumps with an appropriate fix description.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

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 (2)
packages/grpc/src/torii-client.test.ts (1)

7-7: Consider testing the address padding behavior.

The tests now include worldAddress in the config, but there's no test verifying that addAddressPadding is actually applied. Consider adding a test that checks the padded address format.

Example test to add:

it("should pad world address on construction", () => {
    const client = new ToriiGrpcClient({
        toriiUrl: "http://localhost:8080",
        worldAddress: "0x1",
    });
    // @ts-ignore - accessing private property for testing
    expect(client.worldAddress).toBe("0x0000000000000000000000000000000000000000000000000000000000000001");
});
packages/sdk/src/createSDK.ts (1)

237-237: <!-- [scratchpad_update]
[observations]

  • Web search returned general starknet.js docs but no specific info on addAddressPadding idempotency
  • The function appears in examples but implementation details not in search results
  • Need to search more specifically for the function implementation or behavior
    [actions]
  • Search for addAddressPadding source code or specific documentation
    [scratchpad_end] --><!-- [scratchpad_update]
    [observations]
  • Found starknet.js API docs confirming addAddressPadding signature
  • Doc states: "Format a hex number to '0x' and 64 characters, adding leading zeros if necessary"
  • Example shows function adds leading zeros to short addresses
  • Key: function pads with leading zeros to create 64-character format
    [analysis]
  • addAddressPadding converts any hex address to a padded format (0x + 64 chars)
  • If already padded (64 chars), adding leading zeros to a 64-char string results in same 64-char string (idempotent)
  • Example: '0x1234...' becomes '0x0000...1234...' (padded to 64), calling again should return same result
  • This means it IS idempotent - calling multiple times returns same result
    [observations_continued]
  • Script output confirms duplicate padding in the codebase
  • Review comment states it's idempotent and safe but redundant
  • Need to verify if this is truly a recommended optional refactor
    [actions]
  • Look at the actual behavior: check if function checks already-padded addresses
  • Determine if removing duplicate padding would be a clean refactor
    [scratchpad_end] -->

Based on the verified script output and documentation, I can now provide the rewritten review comment:


Remove redundant address padding in createSDK.ts.

The addAddressPadding function formats a hex number to '0x' and 64 characters, adding leading zeros if necessary, which makes it idempotent. The worldAddress is padded twice: in createSDK.ts line 237 before passing to ToriiGrpcClient, and again in ToriiGrpcClient's constructor at torii-client.ts line 253.

Remove the padding in createSDK.ts line 237 and let the ToriiGrpcClient constructor handle it.

         new ToriiGrpcClient({
             toriiUrl: config.client.toriiUrl ?? "http://localhost:8080",
-            worldAddress: addAddressPadding(config.client.worldAddress),
+            worldAddress: config.client.worldAddress,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 897c3d2 and b9f7335.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • packages/grpc/package.json (1 hunks)
  • packages/grpc/src/mappings/query.ts (2 hunks)
  • packages/grpc/src/torii-client.test.ts (2 hunks)
  • packages/grpc/src/torii-client.ts (3 hunks)
  • packages/sdk/src/createSDK.ts (2 hunks)
⏰ 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). (3)
  • GitHub Check: build-examples
  • GitHub Check: build-packages
  • GitHub Check: build
🔇 Additional comments (8)
packages/grpc/package.json (1)

40-40: LGTM! Starknet dependency added correctly.

The addition of the starknet dependency is appropriate for using addAddressPadding. The catalog: version specifier indicates proper workspace-level version management.

packages/grpc/src/mappings/query.ts (2)

79-79: LGTM! Import added correctly.


319-326: LGTM! Address padding applied correctly in query mapping.

The padding is applied before hex-to-buffer conversion, ensuring world addresses in queries are consistently formatted. This function is used throughout the query mapping logic.

packages/sdk/src/createSDK.ts (1)

3-3: LGTM! Import added correctly.

packages/grpc/src/torii-client.ts (3)

130-130: LGTM! Import added correctly.


253-253: LGTM! Address padding applied in constructor.

The worldAddress from config is padded when the client is constructed, ensuring consistent address formatting throughout the client's lifetime.


1042-1045: LGTM! Address padding applied for runtime world addresses.

The padding is correctly applied to world addresses passed dynamically to getWorlds, which is separate from the config worldAddress handled in the constructor.

packages/grpc/src/torii-client.test.ts (1)

54-54: LGTM! Test config updated with worldAddress.

The test correctly includes the new worldAddress field, maintaining backwards compatibility testing.

@MartianGreed MartianGreed merged commit 387ee18 into main Oct 19, 2025
10 checks passed
@MartianGreed MartianGreed deleted the fix/worldaddress branch October 19, 2025 07:08
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.

2 participants