Skip to content

Comments

Event enchasements#211

Draft
peersky wants to merge 3 commits intomainfrom
last-turn-evt
Draft

Event enchasements#211
peersky wants to merge 3 commits intomainfrom
last-turn-evt

Conversation

@peersky
Copy link
Member

@peersky peersky commented Jul 18, 2025

Summary by CodeRabbit

  • New Features

    • The game creation event now includes the number of turns, providing more detailed information when a new game is created.
  • Bug Fixes

    • Improved test coverage for the "game over" condition and verification of turn counts in game events.
  • Tests

    • Added a test to ensure the "LastTurn" event is correctly emitted when expected.

@changeset-bot
Copy link

changeset-bot bot commented Jul 18, 2025

🦋 Changeset detected

Latest commit: 5eb995a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
rankify-contracts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

Walkthrough

A new changeset was added for the rankify-contracts package to document recent updates. The gameCreated event in the IRankifyInstance interface and its emission in the main facet were modified to include a new turns parameter. Unit tests were updated to cover the "game over" condition and event emission.

Changes

File(s) Change Summary
.changeset/little-shrimps-love.md Added a changeset file documenting a patch update for unit tests and event parameter changes.
src/interfaces/IRankifyInstance.sol Updated gameCreated event signature to include a turns parameter.
src/facets/RankifyInstanceMainFacet.sol Modified gameCreated event emission to append params.nTurns as an argument.
test/RankifyInstance.ts Added a test to verify the "LastTurn" event is emitted for game ID 1.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant RankifyInstanceMainFacet
  participant IRankifyInstance (Event)

  User->>RankifyInstanceMainFacet: createGame(params)
  RankifyInstanceMainFacet->>IRankifyInstance (Event): emit gameCreated(..., votePhaseDuration, turns)
Loading

Suggested reviewers

  • theKosmoss

Poem

In code we trust, events anew,
A turn is counted, precise and true.
The tests now check, the logs reveal,
When games are over, rabbits squeal!
With every hop, a patch is spun—
Rankify’s journey has just begun.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/RankifyInstance.ts

Oops! Something went wrong! :(

ESLint: 9.18.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (2)
src/interfaces/IRankifyInstance.sol (1)

33-33: Consider type consistency between input parameter and event parameter.

There's a type inconsistency: the NewGameParamsInput.nTurns field is uint96, but the event parameter turns is uint256. While this works due to implicit upcasting, consider using consistent types for better clarity.

-        uint256 turns
+        uint96 turns

Or alternatively, update the input struct to use uint256 for consistency.

test/RankifyInstance.ts (1)

1829-1832: Strengthen the assertion by checking event payload, not just count

The test only verifies that some LastTurn event for game 1 exists.
If the event is emitted with unexpected parameters (e.g. wrong turn index, duplicated emission, wrong winner) the test would still pass.

-const evts = (await rankifyInstance.queryFilter(rankifyInstance.filters.LastTurn(1))).map(e => e.args);
-expect(evts.length).to.be.greaterThan(0);
+const evts = await rankifyInstance.queryFilter(rankifyInstance.filters.LastTurn(1));
+expect(evts).to.have.length.greaterThan(0);
+// Assert on the first (and normally only) occurrence
+const { gameId, turn } = evts[0].args;      // adapt to actual signature
+expect(gameId).to.equal(1);
+expect(turn).to.equal(await rankifyInstance.getTurn(1));

Alternatively, capture the tx that should emit the event and use expect(tx).to.emit(rankifyInstance, 'LastTurn').withArgs(1, expectedTurn), which is both clearer and faster than querying the full log history.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1964f6e and 5eb995a.

📒 Files selected for processing (4)
  • .changeset/little-shrimps-love.md (1 hunks)
  • src/facets/RankifyInstanceMainFacet.sol (1 hunks)
  • src/interfaces/IRankifyInstance.sol (1 hunks)
  • test/RankifyInstance.ts (1 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). (1)
  • GitHub Check: test
🔇 Additional comments (2)
.changeset/little-shrimps-love.md (1)

1-6: Changeset format looks good.

The changeset properly documents the update with appropriate patch-level versioning. The description accurately reflects the changes made to the event signature and test coverage.

src/facets/RankifyInstanceMainFacet.sol (1)

79-80: gameCreated event signature consistency confirmed

The gameCreated emission in src/facets/RankifyInstanceMainFacet.sol now passes the parameters in the exact order defined by the IRankifyInstance interface:

• proposingPhaseDuration → params.proposingPhaseDuration
• votePhaseDuration → params.votePhaseDuration
• turns → params.nTurns

No discrepancies found between the implementation and the interface.

Comment on lines +32 to 34
uint256 votePhaseDuration,
uint256 turns
);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Event signature change is a breaking change - verify compatibility.

The addition of the turns parameter to the gameCreated event is a breaking change that will affect any existing event listeners or indexing systems. Ensure that all dependent systems are updated to handle the new event signature.


🏁 Script executed:

#!/bin/bash
# Description: Search for gameCreated event usage across the codebase to identify potential breaking changes
# Expected: Find all places where gameCreated event is used (listeners, filters, etc.)

echo "Searching for gameCreated event usage..."
rg -A 3 -B 3 "gameCreated" --type sol
rg -A 3 -B 3 "GameCreated" --type ts --type js

Length of output: 203


🏁 Script executed:

#!/bin/bash
# Search for the `gameCreated` event declaration and any references in Solidity files
echo "➡️ Searching for `gameCreated` in Solidity files..."
rg -g '*.sol' -n -A2 -B2 "gameCreated"

# Search for any usage of `gameCreated` in TypeScript/JavaScript for listeners, filters, etc.
echo "➡️ Searching for `gameCreated` in TS/JS files..."
rg -g '*.ts' -g '*.js' -n -A2 -B2 "gameCreated"

Length of output: 2938


🚨 Update all references to match the new gameCreated signature

The gameCreated event in src/interfaces/IRankifyInstance.sol now includes two new uint256 parameters—votePhaseDuration and turns—which makes it a breaking change. You’ll need to align every declaration and emit so your mocks, facet, and tests don’t break.

Key locations to fix:

  • src/mocks/RankifyInstanceEventMock.sol
    • Line 29: Change the event gameCreated(...) declaration to include uint256 votePhaseDuration, uint256 turns in the correct order.
    • Line 72: Update the emit gameCreated(…) call to pass the new parameters (e.g. emit gameCreated(1, address(11), address(14), /*votePhaseDuration*/, /*turns*/);).

  • src/facets/RankifyInstanceMainFacet.sol
    • Lines 73–75: The current emit gameCreated(params.gameId, params.gameMaster) only passes two arguments. Add params.votePhaseDuration and params.nTurns (cast to uint256) in the correct sequence.

  • test/RankifyInstance.ts
    • Lines 544–547 and 2011–2014: If you use .withArgs(...) after .to.emit(…, 'gameCreated'), include the two new parameters. Ensure your test-setup params object includes nTurns and votePhaseDuration.

Type & naming consistency:

  • The input struct uses nTurns as uint96 but the event expects uint256 turns. To prevent truncation, consider switching nTurns to uint256.
  • Unify naming: use turns consistently instead of mixing nTurns, turns, and maxTurns.

Addressing these changes will ensure your mocks, facet emits, and tests stay in sync with the new event signature.

🤖 Prompt for AI Agents
In src/interfaces/IRankifyInstance.sol around lines 32 to 34, the gameCreated
event signature was updated to include two new uint256 parameters:
votePhaseDuration and turns. To fix this, update the event declaration in
src/mocks/RankifyInstanceEventMock.sol at line 29 to add these parameters in the
correct order, and modify the emit call at line 72 to pass appropriate values
for votePhaseDuration and turns. In src/facets/RankifyInstanceMainFacet.sol
lines 73–75, update the emit gameCreated call to include
params.votePhaseDuration and params.nTurns cast to uint256. In
test/RankifyInstance.ts at lines 544–547 and 2011–2014, update all
.withArgs(...) calls after .to.emit(..., 'gameCreated') to include the new
parameters, and ensure the test params object includes votePhaseDuration and
nTurns. Also, unify the naming by changing nTurns to turns as uint256 to
maintain consistency and prevent truncation.

@peersky peersky marked this pull request as draft October 14, 2025 03:27
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