Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for engine and processors #2918

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

g4titanx
Copy link
Contributor

@g4titanx g4titanx commented Jan 16, 2025

this pr fixes #1679

Summary by CodeRabbit

  • Style

    • Added trailing commas in multiple files to improve code formatting consistency
    • Removed unnecessary line breaks and adjusted indentation in several code sections
    • Updated function signatures and struct definitions to include trailing commas
  • Chores

    • Standardized syntax across various Dojo framework components
    • Enhanced code readability without changing underlying functionality
    • Prepared codebase for potential future modifications by improving formatting

@g4titanx
Copy link
Contributor Author

@glihm

Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

The pull request introduces a series of formatting and syntactical changes across multiple files in the Dojo project, primarily focusing on adding trailing commas, adjusting function signatures, and improving code consistency. These modifications span various components of the Dojo framework, including core modules, test files, and example implementations.

Changes

File Path Change Summary
crates/torii/indexer/src/test.rs Added new test functions for event processing and engine recovery
Multiple core and test files Added trailing commas to function signatures, struct definitions, and method calls
Various modules Formatting adjustments without functional changes

Assessment against linked issues

Objective Addressed Explanation
Add tests for engine and processors [#1679] New test functions added in test.rs cover event processing, engine recovery, and concurrent event handling

Ohayo, sensei! The changes in this pull request align perfectly with the objectives outlined in issue #1679. The new test functions in test.rs provide comprehensive coverage for the Torii engine and processors:

  1. test_processor_events_handling: Validates event processing for different event types
  2. test_engine_backoff_and_recovery: Checks engine initialization and cursor management
  3. test_concurrent_event_processing: Ensures system stability under concurrent transaction processing

These tests address both approaches mentioned in the issue description:

  • Mocking event processing
  • Testing event fetching and pagination logic

The implementation looks solid and should help improve the robustness of the Torii indexer.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 @coderabbitai in 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 @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 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 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. (Beta)
  • @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.

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

@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 (6)
crates/dojo/core-cairo-test/src/world.cairo (3)

109-112: Consider enhancing error handling for deploy_syscall, sensei! 🎯

While the code works, unwrapping the result directly might not provide the best error context in case of deployment failures.

Consider wrapping the error with more context:

-    let (contract, _) = starknet::syscalls::deploy_syscall(
-        class_hash.try_into().unwrap(), 0, calldata, false,
-    )
-        .unwrap();
+    let (contract, _) = starknet::syscalls::deploy_syscall(
+        class_hash.try_into().unwrap(), 0, calldata, false,
+    )
+        .expect('Failed to deploy contract');

164-176: The resource registration looks solid, sensei! But let's make it even better! 🌟

The match expression handles all resource types cleanly, but the try_into().unwrap() calls could benefit from better error handling.

Consider adding specific error messages for each conversion:

-                    world.register_event(namespace.clone(), (*ch).try_into().unwrap());
+                    world.register_event(namespace.clone(), (*ch).try_into().expect('Invalid event class hash'));

Line range hint 190-218: The permission syncing looks great, sensei! Just one suggestion! 🔐

The contract lookup error handling could be more descriptive.

Consider enhancing the error message:

-                        _ => panic!("Contract not found"),
+                        _ => panic!("Contract not found in namespace: {}", *namespace),
crates/torii/indexer/src/test.rs (3)

609-610: Strengthen the assertion to verify the exact number of entities created

Ohayo sensei! In the test, we are asserting that entity_count > 0, which verifies that at least one entity is created. To ensure that all entities are processed correctly, consider asserting the exact number of entities expected.

You can apply this diff to strengthen the assertion:

-        assert!(entity_count > 0, "Entity should be created after StoreSetRecord event");
+        assert_eq!(entity_count, EXPECTED_ENTITY_COUNT, "Unexpected number of entities created");

Replace EXPECTED_ENTITY_COUNT with the actual expected number of entities.


702-705: Handle potential errors when fetching the head cursor

Sensei, currently, the code uses unwrap_or(0) when fetching the head cursor, which may mask errors during database access. Consider using unwrap() or handling the error explicitly to ensure any issues are surfaced during the test.

You can apply this diff to handle potential errors:

-        let head: i64 = sqlx::query_scalar("SELECT MAX(value) FROM cursors WHERE key = 'head'")
-            .fetch_one(&pool)
-            .await
-            .unwrap_or(0);
+        let head: i64 = sqlx::query_scalar("SELECT MAX(value) FROM cursors WHERE key = 'head'")
+            .fetch_one(&pool)
+            .await
+            .unwrap();

709-710: Consider a graceful shutdown of the engine instead of aborting

Sensei, using engine_handle.abort() forcefully stops the engine task, which might not allow for proper cleanup. Implementing a graceful shutdown mechanism can help ensure resources are properly released.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 051e2e8 and 962bf01.

⛔ Files ignored due to path filters (5)
  • crates/torii/types-test/Scarb.lock is excluded by !**/*.lock
  • examples/simple/Scarb.lock is excluded by !**/*.lock
  • examples/spawn-and-move/Scarb.lock is excluded by !**/*.lock
  • spawn-and-move-db.tar.gz is excluded by !**/*.gz
  • types-test-db.tar.gz is excluded by !**/*.gz
📒 Files selected for processing (55)
  • crates/dojo/core-cairo-test/src/lib.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/benchmarks.cairo (12 hunks)
  • crates/dojo/core-cairo-test/src/tests/contract.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/event/event.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/helpers/event.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo (6 hunks)
  • crates/dojo/core-cairo-test/src/tests/helpers/model.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/meta/introspect.cairo (6 hunks)
  • crates/dojo/core-cairo-test/src/tests/model/model.cairo (2 hunks)
  • crates/dojo/core-cairo-test/src/tests/storage/packing.cairo (6 hunks)
  • crates/dojo/core-cairo-test/src/tests/utils/hash.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/utils/key.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/tests/utils/layout.cairo (4 hunks)
  • crates/dojo/core-cairo-test/src/tests/utils/misc.cairo (2 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/acl.cairo (9 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/contract.cairo (7 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/event.cairo (16 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/metadata.cairo (6 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/model.cairo (17 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/namespace.cairo (3 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/storage.cairo (2 hunks)
  • crates/dojo/core-cairo-test/src/tests/world/world.cairo (10 hunks)
  • crates/dojo/core-cairo-test/src/utils.cairo (1 hunks)
  • crates/dojo/core-cairo-test/src/world.cairo (7 hunks)
  • crates/dojo/core/src/contract/components/upgradeable.cairo (2 hunks)
  • crates/dojo/core/src/contract/components/world_provider.cairo (2 hunks)
  • crates/dojo/core/src/event/component.cairo (2 hunks)
  • crates/dojo/core/src/event/event.cairo (2 hunks)
  • crates/dojo/core/src/lib.cairo (3 hunks)
  • crates/dojo/core/src/meta/introspect.cairo (2 hunks)
  • crates/dojo/core/src/meta/layout.cairo (2 hunks)
  • crates/dojo/core/src/model/component.cairo (2 hunks)
  • crates/dojo/core/src/model/definition.cairo (1 hunks)
  • crates/dojo/core/src/model/metadata.cairo (2 hunks)
  • crates/dojo/core/src/model/model.cairo (2 hunks)
  • crates/dojo/core/src/model/model_value.cairo (1 hunks)
  • crates/dojo/core/src/model/storage.cairo (4 hunks)
  • crates/dojo/core/src/storage/database.cairo (1 hunks)
  • crates/dojo/core/src/storage/entity_model.cairo (6 hunks)
  • crates/dojo/core/src/storage/layout.cairo (19 hunks)
  • crates/dojo/core/src/storage/packing.cairo (7 hunks)
  • crates/dojo/core/src/storage/storage.cairo (11 hunks)
  • crates/dojo/core/src/utils/layout.cairo (2 hunks)
  • crates/dojo/core/src/utils/misc.cairo (1 hunks)
  • crates/dojo/core/src/utils/serde.cairo (1 hunks)
  • crates/dojo/core/src/utils/snf_test.cairo (2 hunks)
  • crates/dojo/core/src/world/errors.cairo (1 hunks)
  • crates/dojo/core/src/world/iworld.cairo (8 hunks)
  • crates/dojo/core/src/world/resource.cairo (1 hunks)
  • crates/dojo/core/src/world/storage.cairo (24 hunks)
  • crates/dojo/core/src/world/world_contract.cairo (43 hunks)
  • crates/torii/indexer/src/test.rs (3 hunks)
  • examples/simple/src/lib.cairo (4 hunks)
  • examples/spawn-and-move/src/actions.cairo (7 hunks)
  • examples/spawn-and-move/src/models.cairo (3 hunks)
✅ Files skipped from review due to trivial changes (49)
  • crates/dojo/core/src/utils/serde.cairo
  • crates/dojo/core-cairo-test/src/lib.cairo
  • crates/dojo/core-cairo-test/src/tests/utils/hash.cairo
  • crates/dojo/core-cairo-test/src/tests/event/event.cairo
  • crates/dojo/core/src/model/model_value.cairo
  • crates/dojo/core-cairo-test/src/tests/utils/key.cairo
  • crates/dojo/core/src/model/model.cairo
  • crates/dojo/core-cairo-test/src/utils.cairo
  • crates/dojo/core/src/model/definition.cairo
  • crates/dojo/core/src/lib.cairo
  • crates/dojo/core/src/world/resource.cairo
  • crates/dojo/core-cairo-test/src/tests/world/event.cairo
  • crates/dojo/core-cairo-test/src/tests/world/world.cairo
  • crates/dojo/core-cairo-test/src/tests/helpers/event.cairo
  • crates/dojo/core/src/utils/misc.cairo
  • crates/dojo/core-cairo-test/src/tests/helpers/model.cairo
  • crates/dojo/core-cairo-test/src/tests/meta/introspect.cairo
  • crates/dojo/core/src/meta/introspect.cairo
  • crates/dojo/core-cairo-test/src/tests/storage/packing.cairo
  • crates/dojo/core-cairo-test/src/tests/model/model.cairo
  • crates/dojo/core-cairo-test/src/tests/world/contract.cairo
  • crates/dojo/core/src/storage/database.cairo
  • crates/dojo/core/src/world/errors.cairo
  • examples/simple/src/lib.cairo
  • crates/dojo/core-cairo-test/src/tests/utils/misc.cairo
  • crates/dojo/core-cairo-test/src/tests/world/storage.cairo
  • examples/spawn-and-move/src/actions.cairo
  • crates/dojo/core/src/model/component.cairo
  • crates/dojo/core-cairo-test/src/tests/world/metadata.cairo
  • crates/dojo/core-cairo-test/src/tests/benchmarks.cairo
  • crates/dojo/core/src/event/event.cairo
  • crates/dojo/core/src/meta/layout.cairo
  • crates/dojo/core-cairo-test/src/tests/world/acl.cairo
  • crates/dojo/core/src/utils/snf_test.cairo
  • crates/dojo/core/src/utils/layout.cairo
  • crates/dojo/core-cairo-test/src/tests/world/model.cairo
  • crates/dojo/core/src/contract/components/world_provider.cairo
  • crates/dojo/core/src/model/metadata.cairo
  • examples/spawn-and-move/src/models.cairo
  • crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo
  • crates/dojo/core/src/contract/components/upgradeable.cairo
  • crates/dojo/core/src/world/storage.cairo
  • crates/dojo/core/src/storage/storage.cairo
  • crates/dojo/core/src/storage/entity_model.cairo
  • crates/dojo/core/src/world/iworld.cairo
  • crates/dojo/core/src/storage/layout.cairo
  • crates/dojo/core/src/world/world_contract.cairo
  • crates/dojo/core/src/model/storage.cairo
  • crates/dojo/core/src/storage/packing.cairo
🔇 Additional comments (9)
crates/dojo/core/src/event/component.cairo (3)

6-6: Ohayo! Nice type parameter addition, sensei! ✨

The explicit Event type parameter improves type safety and makes the relationship between the event type and its wrapper clearer.


15-15: Consistent type parameter usage, sensei! 🎯

The Event type parameter addition here maintains consistency with the IDeployedEventImpl implementation above.


Line range hint 26-26: Excellent completion of the type system improvements, sensei! 🌟

This final Event type parameter addition rounds out the changes nicely, creating a more robust and type-safe event system across all three trait implementations.

crates/dojo/core-cairo-test/src/tests/world/namespace.cairo (1)

34-34: Ohayo! Nice cleanup of panic message formatting, sensei! 🎯

The removal of trailing commas in panic message tuples makes the code more consistent and cleaner. The changes maintain the same functionality while improving code style.

Also applies to: 48-48, 73-73

crates/dojo/core-cairo-test/src/tests/contract.cairo (1)

180-180: Consistent formatting maintained here too, sensei! ✨

The panic message formatting aligns perfectly with the changes in namespace.cairo, maintaining a unified style across the codebase.

crates/dojo/core-cairo-test/src/tests/utils/layout.cairo (1)

10-11: Ohayo! Beautiful formatting improvements, sensei! 🌟

The consistent formatting of array definitions and span() method calls greatly improves code readability:

  • Moving .span() to new lines makes the code structure clearer
  • Proper indentation of closing brackets enhances visual hierarchy

This style makes the code much easier to scan and maintain!

Also applies to: 25-26, 39-40, 56-57

crates/dojo/core-cairo-test/src/world.cairo (2)

58-64: Ohayo! The ContractDef initialization looks clean, sensei! ✨

The struct initialization follows good practices with consistent formatting.


72-72: Nice error handling, sensei! 🛡️

The panic message clearly indicates why init_calldata can't be set for address descriptors.

Also applies to: 79-79

crates/torii/indexer/src/test.rs (1)

834-838: Verify the expected number of entities created matches the number of transactions

Sensei, the test sends 3 spawn transactions concurrently but asserts that only 2 entities are created. Please verify whether this is the expected behavior. If only 2 entities are created consistently, kindly add a comment explaining why this occurs.

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.

Add tests for engine and processors
1 participant