-
Notifications
You must be signed in to change notification settings - Fork 189
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe 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
Assessment against linked issues
Ohayo, sensei! The changes in this pull request align perfectly with the objectives outlined in issue #1679. The new test functions in
These tests address both approaches mentioned in the issue description:
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 createdOhayo 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 cursorSensei, currently, the code uses
unwrap_or(0)
when fetching the head cursor, which may mask errors during database access. Consider usingunwrap()
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 abortingSensei, 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
⛔ 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 transactionsSensei, 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.
this pr fixes #1679
Summary by CodeRabbit
Style
Chores