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

tests: add tests for migration #2614

Merged
merged 7 commits into from
Nov 2, 2024
Merged

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Nov 1, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced migration process with improved UI feedback for contract initialization.
    • Added new event handling and contract definitions in the manifest.
  • Bug Fixes

    • Clarified error messages for missing world contracts and improved comments for better understanding.
  • Documentation

    • Updated comments and error handling for various methods to improve clarity.
  • Chores

    • Removed outdated configuration files and redundant dependencies to streamline the project structure.

Copy link

coderabbitai bot commented Nov 1, 2024

Walkthrough

Ohayo, sensei! This pull request introduces several changes across multiple files, primarily focusing on the migration process and UI enhancements. Key modifications include updating the MigrationUi spinner to accept an optional message, refining error handling in event processing, and restructuring migration tests for better clarity and organization. Additionally, several configuration files related to Dojo and armory models have been removed, indicating a significant cleanup of unused or outdated definitions. The changes aim to streamline the migration workflow and enhance the overall code structure.

Changes

File Path Change Summary
bin/sozo/src/commands/migrate.rs Updated MigrateArgs::run to instantiate MigrationUi with an Option<String> instead of a string.
crates/dojo/world/src/remote/events_to_remote.rs Clarified error handling in from_events method; corrected comments. No logic changes.
crates/sozo/ops/Cargo.toml Added new dependencies: tokio.workspace, scarb.workspace, sozo-scarbext.workspace.
crates/sozo/ops/src/migrate/mod.rs Modified initialize_contracts to check invoker.calls for contract initialization; updated UI feedback accordingly.
crates/sozo/ops/src/migration_ui.rs Changed MigrationUi::new method to accept Option<&'static str> instead of &'static str.
crates/sozo/ops/src/tests/migration.rs Restructured migration tests; added setup_migration, migrate_spawn_and_move, migrate_no_change, etc.
crates/sozo/ops/src/tests/mod.rs Uncommented mod migration; to include migration tests in the module structure.
crates/torii/types-test/overlays/dev/records.toml Removed configuration for types test records, including writable entities.
examples/game-lib/armory/manifests/dev/base/abis/dojo-base.json Deleted file defining Dojo framework components, including interfaces and events.
examples/game-lib/armory/manifests/dev/base/abis/dojo-world.json Deleted file containing definitions for the Dojo world framework.
examples/game-lib/armory/manifests/dev/base/abis/models/armory-ModelA-19290fb7.json Deleted model definitions and interfaces for armory module.
examples/game-lib/armory/manifests/dev/base/dojo-base.toml Removed class configuration for Dojo entity.
examples/game-lib/armory/manifests/dev/base/dojo-world.toml Removed class configuration for Dojo world entity.
examples/game-lib/armory/manifests/dev/base/models/armory-ModelA-19290fb7.toml Deleted model configuration for armory model.
examples/spawn-and-move/manifest_dev.json Modified manifest structure, added new contract and updated event definitions.
examples/spawn-and-move/manifests/dev/deployment/manifest.toml Removed comprehensive configuration for worlds, contracts, and models.
examples/spawn-and-move/overlays/dev/actions.toml Removed configuration for dojo actions.
examples/spawn-and-move/overlays/dev/mock_token.toml Removed configuration for mock token.
examples/spawn-and-move/overlays/dev/others.toml Removed configuration for others module.
examples/spawn-and-move/overlays/saya/actions.toml Removed configuration for dojo actions in the saya overlay.
examples/spawn-and-move/overlays/saya/others.toml Removed configuration for others in the saya overlay.
examples/spawn-and-move/src/others.cairo Renamed event struct from ContractInitialized to MyInit.
scripts/rebuild_test_artifacts.sh Updated generate-test-db command to include KATANA_RUNNER_BIN environment variable.
xtask/generate-test-db/src/main.rs Changed MigrationUi instantiation from MigrationUi::new("") to MigrationUi::new(None) in migration methods.
bin/sozo/tests/test_data/policies.json Updated target address for the "upgrade" method.

Possibly related PRs

Suggested reviewers

  • kariy

🪧 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 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: 4

🧹 Outside diff range and nitpick comments (5)
crates/sozo/ops/src/tests/mod.rs (1)

1-5: Ohayo sensei! Consider tracking these TODOs as GitHub issues.

These TODO comments indicate several test modules that need to be implemented. To better track and prioritize this work, it would be helpful to create GitHub issues for each pending module.

Would you like me to help create GitHub issues for tracking these pending test modules (auth, call, model, utils)?

examples/spawn-and-move/src/others.cairo (1)

Line range hint 8-12: Ohayo sensei! Consider a more descriptive event name.

While the implementation is correct, the name MyInit is quite generic. Consider a more descriptive name that reflects its purpose, such as OthersModuleInitialized or OthersContractInitialized.

crates/sozo/ops/src/migration_ui.rs (1)

24-32: Clean implementation with thoughtful defaults!

The implementation elegantly handles both cases:

  • When text is provided: Animated frames with shorter duration (500ms) for visual feedback
  • When None: Single empty frame with longer duration (5000ms) for minimal overhead

However, consider extracting the magic numbers (500, 5000) into named constants for better maintainability.

Apply this improvement:

 pub struct MigrationUi {
     spinner: Spinner,
     default_frames: SpinnerFrames,
     silent: bool,
 }

+const ANIMATED_FRAME_DURATION_MS: u64 = 500;
+const EMPTY_FRAME_DURATION_MS: u64 = 5000;
+
 impl MigrationUi {
     pub fn new(text: Option<&'static str>) -> Self {
         if let Some(text) = text {
-            let frames = spinner!(["⛩️ ", "🎃", "👻", "🧟", "💀"], 500);
+            let frames = spinner!(["⛩️ ", "🎃", "👻", "🧟", "💀"], ANIMATED_FRAME_DURATION_MS);
             let spinner = Spinner::new(frames.clone(), text, None);
             Self { spinner, default_frames: frames, silent: false }
         } else {
-            let frames = spinner!([""], 5000);
+            let frames = spinner!([""], EMPTY_FRAME_DURATION_MS);
             let spinner = Spinner::new(frames.clone(), "", None);
             Self { spinner, default_frames: frames, silent: false }
         }
     }
crates/dojo/world/src/remote/events_to_remote.rs (1)

Line range hint 189-199: Ohayo sensei! The logging improvements look great!

The added trace logging for contract initialization events enhances observability. The implementation is sound with proper error handling and safe unwraps.

Consider using the debug format specifier {:?} for the selector as well, to maintain consistency with the init_calldata formatting:

-    selector = format!("{:#066x}", e.selector),
+    selector = format!("{:?}", e.selector),
crates/sozo/ops/src/migrate/mod.rs (1)

214-216: Consider simplifying the string formatting, sensei!

The multi-line string formatting could be more concise.

-                let ui_text =
-                    format!("Initializing {} contracts (sequentially)...", invoker.calls.len());
+                let ui_text = format!("Initializing {} contracts (sequentially)...", invoker.calls.len());
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 05fb95b and 28a4f10.

⛔ Files ignored due to path filters (3)
  • Cargo.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 (25)
  • bin/sozo/src/commands/execute.rs (1 hunks)
  • bin/sozo/src/commands/migrate.rs (1 hunks)
  • crates/dojo/world/src/remote/events_to_remote.rs (1 hunks)
  • crates/sozo/ops/Cargo.toml (1 hunks)
  • crates/sozo/ops/src/migrate/mod.rs (1 hunks)
  • crates/sozo/ops/src/migration_ui.rs (1 hunks)
  • crates/sozo/ops/src/tests/migration.rs (1 hunks)
  • crates/sozo/ops/src/tests/mod.rs (1 hunks)
  • crates/torii/types-test/overlays/dev/records.toml (0 hunks)
  • examples/game-lib/armory/manifests/dev/base/abis/dojo-base.json (0 hunks)
  • examples/game-lib/armory/manifests/dev/base/abis/dojo-world.json (0 hunks)
  • examples/game-lib/armory/manifests/dev/base/abis/models/armory-ModelA-19290fb7.json (0 hunks)
  • examples/game-lib/armory/manifests/dev/base/dojo-base.toml (0 hunks)
  • examples/game-lib/armory/manifests/dev/base/dojo-world.toml (0 hunks)
  • examples/game-lib/armory/manifests/dev/base/models/armory-ModelA-19290fb7.toml (0 hunks)
  • examples/spawn-and-move/manifest_dev.json (6 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.toml (0 hunks)
  • examples/spawn-and-move/overlays/dev/actions.toml (0 hunks)
  • examples/spawn-and-move/overlays/dev/mock_token.toml (0 hunks)
  • examples/spawn-and-move/overlays/dev/others.toml (0 hunks)
  • examples/spawn-and-move/overlays/saya/actions.toml (0 hunks)
  • examples/spawn-and-move/overlays/saya/others.toml (0 hunks)
  • examples/spawn-and-move/src/others.cairo (2 hunks)
  • scripts/rebuild_test_artifacts.sh (1 hunks)
  • xtask/generate-test-db/src/main.rs (2 hunks)
💤 Files with no reviewable changes (13)
  • crates/torii/types-test/overlays/dev/records.toml
  • examples/game-lib/armory/manifests/dev/base/abis/dojo-base.json
  • examples/game-lib/armory/manifests/dev/base/abis/dojo-world.json
  • examples/game-lib/armory/manifests/dev/base/abis/models/armory-ModelA-19290fb7.json
  • examples/game-lib/armory/manifests/dev/base/dojo-base.toml
  • examples/game-lib/armory/manifests/dev/base/dojo-world.toml
  • examples/game-lib/armory/manifests/dev/base/models/armory-ModelA-19290fb7.toml
  • examples/spawn-and-move/manifests/dev/deployment/manifest.toml
  • examples/spawn-and-move/overlays/dev/actions.toml
  • examples/spawn-and-move/overlays/dev/mock_token.toml
  • examples/spawn-and-move/overlays/dev/others.toml
  • examples/spawn-and-move/overlays/saya/actions.toml
  • examples/spawn-and-move/overlays/saya/others.toml
🔇 Additional comments (19)
crates/sozo/ops/src/tests/mod.rs (1)

7-7: LGTM! The migration module inclusion aligns with the PR objective.

The uncommented migration module makes perfect sense as it supports the PR's goal of adding migration tests.

Let's verify the migration test file exists:

✅ Verification successful

Migration test file exists as expected

The verification confirms the presence of migration.rs at the expected location: crates/sozo/ops/src/tests/migration.rs, which aligns perfectly with the module inclusion.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the migration test file exists
fd --type f "migration.rs$" "crates/sozo/ops/src/tests"

Length of output: 94

examples/spawn-and-move/src/others.cairo (1)

17-17: Verify event consumers are updated.

The event rename from ContractInitialized to MyInit looks good, but we should ensure all consumers are updated.

crates/sozo/ops/Cargo.toml (1)

39-41: Ohayo! These dependency additions look perfect, sensei! ٩(◕‿◕。)۶

The new workspace dependencies align perfectly with the migration testing objectives:

  • tokio for handling async operations
  • scarb for package management
  • sozo-scarbext for Scarb extensions
scripts/rebuild_test_artifacts.sh (1)

Line range hint 1-43: Verify script execution directory assumptions, sensei!

The script uses several relative paths and assumes it's being run from the repository root.

Let's verify if there are any other scripts that might call this one from a different directory:

✅ Verification successful

Ohayo! The script's directory assumptions are safe, sensei!

The script is only referenced in the DEVELOPMENT.md documentation, which explicitly instructs users to run it with bash scripts/rebuild_test_artifacts.sh from the repository root. No other scripts or workflows call this script, making its relative path assumptions safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any references to rebuild_test_artifacts.sh
rg -l "rebuild_test_artifacts.sh"

# Check if this script is referenced in any GitHub Actions workflows
fd -e yml -e yaml . .github/workflows/ --exec grep -l "rebuild_test_artifacts.sh" {} \;

Length of output: 139


Script:

#!/bin/bash
# Let's check the content of DEVELOPMENT.md to see how this script is referenced
cat DEVELOPMENT.md

# Let's also check if there are any other shell scripts that might be sourcing this one
fd -e sh . --exec grep -l "source.*rebuild_test_artifacts.sh" {} \;
fd -e sh . --exec grep -l "\. .*rebuild_test_artifacts.sh" {} \;

# Check for any shell scripts that might be executing this script
fd -e sh . --exec grep -l "bash.*rebuild_test_artifacts.sh" {} \;
fd -e sh . --exec grep -l "./scripts/rebuild_test_artifacts.sh" {} \;

Length of output: 3078

crates/sozo/ops/src/migration_ui.rs (1)

23-23: Ohayo! Nice API improvement, sensei!

The change to Option<&'static str> makes the API more explicit and flexible by allowing callers to clearly indicate when no text is needed.

bin/sozo/src/commands/migrate.rs (2)

51-51: Ohayo sensei! The change to Option looks good, but let's verify consistency.

The modification to use Some("Evaluating world diff...") aligns well with making the UI messages optional. This change improves flexibility by allowing the UI to handle cases where no message is needed.

Let's check if this pattern is consistently applied across the codebase:

✅ Verification successful

Ohayo sensei! The Option change is consistently implemented across the codebase!

All instances of MigrationUi::new are using the Option parameter correctly:

  • xtask/generate-test-db/src/main.rs: Uses None with silent mode
  • crates/sozo/ops/src/tests/migration.rs: Uses None for tests
  • bin/sozo/src/commands/migrate.rs: Uses Some("Evaluating world diff...")
  • bin/sozo/src/commands/execute.rs: Uses None with silent mode

The change is properly aligned across all usages, with each context appropriately choosing between Some and None based on its UI needs.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify MigrationUi::new usage pattern across the codebase
# Expected: All instances should use Option<String> parameter

# Search for all MigrationUi::new usages
ast-grep --pattern 'MigrationUi::new($_)'

Length of output: 1143


Script:

#!/bin/bash
# Let's try a different approach using ripgrep to find MigrationUi::new usages
rg "MigrationUi::new" -A 2 -B 2

Length of output: 1679


51-51: Consider adding tests for the new Option behavior.

Given that this PR's objective is to add tests for migration, we should ensure the new optional message behavior is properly tested.

Let's check if there are any existing tests for this functionality:

Would you like me to help generate test cases for the optional message behavior in MigrationUi?

bin/sozo/src/commands/execute.rs (1)

83-83: Ohayo! The MigrationUi initialization looks good, sensei!

The change from empty string to None improves type safety and makes the intent clearer.

xtask/generate-test-db/src/main.rs (2)

59-59: Ohayo! The migration UI change looks good, sensei!

The transition from an empty string to None aligns well with the new optional message approach in MigrationUi. The with_silent() chaining maintains the existing behavior while using the new API.


106-106: The same clean migration UI update here too, sensei!

Consistent with the previous change, maintaining uniformity across both test migrations.

crates/sozo/ops/src/migrate/mod.rs (2)

207-209: Ohayo! The UI feedback for multicall initialization looks good, sensei!

The code provides clear feedback about the number of contracts being initialized in multicall mode.


207-218: Ohayo! The initialization feedback improvements look solid overall, sensei!

The changes effectively handle both multicall and sequential initialization scenarios while providing clear user feedback. The error handling is robust, and the code follows Rust best practices.

examples/spawn-and-move/manifest_dev.json (6)

6-7: LGTM! World configuration looks good.

The world name and seed are properly configured with clear, descriptive values.


8-1120: Ohayo sensei! Comprehensive world ABI implementation looks solid.

The ABI definitions are well-structured and include all necessary components for the Dojo world:

  • Core types (ByteArray, Resource, etc.)
  • World interfaces (IWorld, IUpgradeableWorld)
  • Event definitions
  • Access control functions

Line range hint 1124-1441: Contract configuration for actions system is well-defined.

The actions contract is properly configured with:

  • Correct address and class hash
  • Complete ABI including implementations, interfaces, and events
  • Proper namespace prefix in tag (ns-actions)

Line range hint 1626-1785: Mock token contract configuration follows best practices.

The mock token contract configuration maintains consistency with other contracts:

  • Follows the same ABI structure
  • Uses consistent namespace prefix (ns-mock_token)
  • Properly defined events and interfaces

1994-2000: Event configuration update looks good.

The events have been properly updated:

  • ContractInitialized renamed to Moved
  • New MyInit event added
  • Class hashes are properly configured
#!/bin/bash
# Verify the event name changes in the codebase
echo "Checking for old event name usage..."
rg "ContractInitialized" --type cairo

echo "Checking for new event names..."
rg "MyInit|Moved" --type cairo

Line range hint 1789-1955: Verify initialization value for others contract.

The others contract has an initialization value of 0xff. Please confirm if this is the intended value for production.

crates/sozo/ops/src/tests/migration.rs (1)

74-78: Great job on the migrate_no_change test

Ohayo sensei! The migrate_no_change test correctly verifies that no changes occur when the state is unchanged. This is a valuable addition to ensure stability in migrations.

@@ -36,7 +36,7 @@ cargo +nightly-2024-08-28 fmt --all -- "$@"
./target/release/sozo build --manifest-path crates/torii/types-test/Scarb.toml

# Generates the database for testing by migrating the spawn and move example.
cargo generate-test-db
KATANA_RUNNER_BIN=./target/release/katana cargo generate-test-db
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo! Consider using an absolute path for KATANA_RUNNER_BIN.

The change to use the local katana binary is good, but using a relative path could be fragile if the script is executed from a different directory.

Consider using:

-KATANA_RUNNER_BIN=./target/release/katana cargo generate-test-db
+KATANA_RUNNER_BIN="$(pwd)/target/release/katana" cargo generate-test-db
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
KATANA_RUNNER_BIN=./target/release/katana cargo generate-test-db
KATANA_RUNNER_BIN="$(pwd)/target/release/katana" cargo generate-test-db

@@ -56,7 +56,7 @@ async fn migrate_spawn_and_move(db_path: &Path) -> Result<Manifest> {
profile_config,
runner.url().to_string(),
)
.migrate(&mut MigrationUi::new("").with_silent())
.migrate(&mut MigrationUi::new(None).with_silent())
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider extracting the common migration UI configuration, sensei!

Both test functions use identical MigrationUi configuration. We could improve maintainability by extracting this into a helper function.

Here's a suggested implementation:

fn create_silent_migration_ui() -> MigrationUi {
    MigrationUi::new(None).with_silent()
}

Then use it in both functions:

-    .migrate(&mut MigrationUi::new(None).with_silent())
+    .migrate(&mut create_silent_migration_ui())

Also applies to: 106-106

Comment on lines +29 to +32
let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap();

#[tokio::test(flavor = "multi_thread")]
#[katana_runner::test(accounts = 10)]
async fn migrate_with_auto_mine(sequencer: &RunnerCtx) {
let config = setup::load_config();
let ws = setup::setup_ws(&config);
let world_local = ws.load_world_local().unwrap();
let world_address = world_local.deterministic_world_address().unwrap();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider handling errors instead of using unwrap()

Ohayo sensei! Using unwrap() can cause the program to panic if an error occurs. It's better to handle possible errors gracefully using the ? operator to propagate them, enhancing the robustness of the code.

Apply this diff to improve error handling:

-let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap();
+let ws = scarb::ops::read_workspace(config.manifest_path(), &config)?;

-let world_local = ws.load_world_local().unwrap();
+let world_local = ws.load_world_local()?;

-let world_address = world_local.deterministic_world_address().unwrap();
+let world_address = world_local.deterministic_world_address()?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap();
#[tokio::test(flavor = "multi_thread")]
#[katana_runner::test(accounts = 10)]
async fn migrate_with_auto_mine(sequencer: &RunnerCtx) {
let config = setup::load_config();
let ws = setup::setup_ws(&config);
let world_local = ws.load_world_local().unwrap();
let world_address = world_local.deterministic_world_address().unwrap();
let ws = scarb::ops::read_workspace(config.manifest_path(), &config)?;
let world_local = ws.load_world_local()?;
let world_address = world_local.deterministic_world_address()?;


assert_eq!(local_manifest.world.inner.class_hash, remote_manifest.world.inner.class_hash);
assert_eq!(local_manifest.models.len(), remote_manifest.models.len());
migration.migrate(&mut ui).await.expect("Migration spawn-and-move failed.")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle migration errors without panicking

Ohayo sensei! Using expect() will cause a panic if the migration fails. Consider handling the error gracefully to improve robustness and provide better error reporting.

Apply this diff to handle the error:

-migration.migrate(&mut ui).await.expect("Migration spawn-and-move failed.")
+if let Err(e) = migration.migrate(&mut ui).await {
+    eprintln!("Migration failed: {:?}", e);
+    return Err(e.into());
+}

Committable suggestion skipped: line range outside the PR's diff.

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

🧹 Outside diff range and nitpick comments (1)
bin/sozo/tests/test_data/policies.json (1)

Line range hint 1-999: Consider organizing test policies by functionality, sensei.

The file contains a mix of different policy types (spawn, move, upgrade, etc.). Consider organizing these policies into logical groups within the test data, perhaps using separate files or adding comments to clearly indicate the purpose of each policy group.

Consider structuring the test data like this:

{
  "core_policies": [
    // Core system policies
  ],
  "game_policies": [
    // Game-specific policies
  ],
  "upgrade_policies": [
    // All upgrade-related policies
  ]
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 28a4f10 and a2a9f00.

📒 Files selected for processing (1)
  • bin/sozo/tests/test_data/policies.json (1 hunks)
🔇 Additional comments (1)
bin/sozo/tests/test_data/policies.json (1)

35-37: Ohayo! Verify duplicate upgrade policies, sensei.

I notice we have multiple entries for the "upgrade" method with different target addresses. While this might be intentional for testing purposes, we should verify that this doesn't cause any conflicts in the test scenarios.

Let's check for all upgrade method entries:

✅ Verification successful

Ohayo! Multiple upgrade policies are expected in test data, sensei!

The presence of multiple upgrade policies with different target addresses in the test data file is intentional and valid. This is common in test scenarios to verify different upgrade paths and configurations. Each target address is unique, and there are no duplicates that could cause conflicts:

  • 0x7bc340...34d4
  • 0x200cd8...43d1 (newly added)
  • 0x2e7d50...4a8
  • 0x41ceb7...9db
  • 0x234d35...c32
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all upgrade method entries and their targets
echo "Checking all upgrade method policies..."
jq '.[] | select(.method == "upgrade") | .target' bin/sozo/tests/test_data/policies.json

Length of output: 519

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes missing coverage. Please review.

Project coverage is 57.94%. Comparing base (9f3f501) to head (253d5d6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/sozo/ops/src/migration_ui.rs 62.50% 3 Missing ⚠️
crates/sozo/ops/src/migrate/mod.rs 50.00% 2 Missing ⚠️
xtask/generate-test-db/src/main.rs 0.00% 2 Missing ⚠️
bin/sozo/src/commands/migrate.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2614      +/-   ##
==========================================
+ Coverage   55.65%   57.94%   +2.28%     
==========================================
  Files         393      393              
  Lines       48566    48567       +1     
==========================================
+ Hits        27029    28141    +1112     
+ Misses      21537    20426    -1111     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a2a9f00 and 253d5d6.

⛔ Files ignored due to path filters (3)
  • Cargo.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 (3)
  • bin/sozo/src/commands/migrate.rs (1 hunks)
  • crates/sozo/ops/src/migration_ui.rs (1 hunks)
  • examples/spawn-and-move/manifest_dev.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • bin/sozo/src/commands/migrate.rs
  • crates/sozo/ops/src/migration_ui.rs
🧰 Additional context used
🪛 Biome
examples/spawn-and-move/manifest_dev.json

[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: expected , but instead found HEAD

Remove HEAD

(parse)


[error] 1790-1790: expected , but instead found "address"

Remove "address"

(parse)


[error] 1790-1790: expected , but instead found :

Remove :

(parse)


[error] 1790-1790: expected , but instead found "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1"

Remove "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1"

(parse)


[error] 1791-1791: expected , but instead found :

Remove :

(parse)


[error] 1791-1791: expected , but instead found "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e"

Remove "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e"

(parse)


[error] 1791-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1793-1793: expected , but instead found "address"

Remove "address"

(parse)


[error] 1793-1793: expected , but instead found :

Remove :

(parse)


[error] 1793-1793: expected , but instead found "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792"

Remove "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792"

(parse)


[error] 1794-1794: expected , but instead found :

Remove :

(parse)


[error] 1794-1794: expected , but instead found "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88"

Remove "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88"

(parse)


[error] 1794-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: expected , but instead found dojo

Remove dojo

(parse)


[error] 1795-1795: unexpected character /

(parse)


[error] 1795-1795: expected , but instead found main

Remove main

(parse)

🔇 Additional comments (2)
examples/spawn-and-move/manifest_dev.json (2)

Line range hint 1789-2005: Verify dojo_init parameter change impact.

The dojo_init function in the "others" contract now accepts a value parameter of type u8. This change is reflected in the init_calldata which now contains ["0xff"].

Let's verify this change is properly implemented across the codebase:

#!/bin/bash
# Description: Verify dojo_init implementation consistency
# Search for dojo_init implementations and their parameter lists

echo "Searching for dojo_init implementations..."
ast-grep --pattern 'fn dojo_init($$$) {
  $$$
}'
🧰 Tools
🪛 Biome

[error] 1788-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: expected , but instead found HEAD

Remove HEAD

(parse)


[error] 1790-1790: expected , but instead found "address"

Remove "address"

(parse)


[error] 1790-1790: expected , but instead found :

Remove :

(parse)


[error] 1790-1790: expected , but instead found "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1"

Remove "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1"

(parse)


[error] 1791-1791: expected , but instead found :

Remove :

(parse)


[error] 1791-1791: expected , but instead found "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e"

Remove "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e"

(parse)


[error] 1791-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1793-1793: expected , but instead found "address"

Remove "address"

(parse)


[error] 1793-1793: expected , but instead found :

Remove :

(parse)


[error] 1793-1793: expected , but instead found "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792"

Remove "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792"

(parse)


[error] 1794-1794: expected , but instead found :

Remove :

(parse)


[error] 1794-1794: expected , but instead found "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88"

Remove "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88"

(parse)


[error] 1794-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: expected , but instead found dojo

Remove dojo

(parse)


[error] 1795-1795: unexpected character /

(parse)


[error] 1795-1795: expected , but instead found main

Remove main

(parse)


[error] 1796-1796: expected , but instead found "abi"

Remove "abi"

(parse)


[error] 1796-1796: expected , but instead found :

Remove :

(parse)


[error] 1796-1796: expected , but instead found [

Remove [

(parse)


1999-2005: Event changes need verification.

The manifest shows two significant event changes:

  1. Event with class hash 0x22c33f3c7e525a21cd3651326f74c61deff6d75e26e06725f53ac2dfd4646fa is now tagged as "Moved" (previously "ContractInitialized")
  2. New event with class hash 0x2c78ad5ec05d05be24a1cbace308ad15bff9375b56be8a8fa892ff5fc79eb23 is tagged as "MyInit"

Let's verify these event changes are consistent with the codebase:

✅ Verification successful

Ohayo sensei! Based on the verification results, I can now provide a conclusive response:

Event changes are valid and properly implemented

The changes in the manifest are consistent with the codebase:

  • The new "MyInit" event is properly implemented in others.cairo with appropriate structure and emitted during initialization
  • The "Moved" tag replacing "ContractInitialized" is valid as ContractInitialized is a core system event (found in world_contract.cairo), not a custom game event
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the event changes in the codebase
# Look for references to these events in the code

# Search for Moved event usage
echo "Searching for Moved event usage..."
rg -l "Moved"

# Search for MyInit event usage
echo "Searching for MyInit event usage..."
rg -l "MyInit"

# Search for any remaining references to ContractInitialized
echo "Checking for any remaining ContractInitialized references..."
rg -l "ContractInitialized"

Length of output: 817


Script:

#!/bin/bash
# Let's check the implementation details of these events

# Check the implementation of MyInit in others.cairo
echo "Checking MyInit implementation in others.cairo..."
rg -A 10 "MyInit" "examples/spawn-and-move/src/others.cairo"

# Check for Moved event implementation
echo "Checking Moved event implementation..."
rg -A 10 "Moved" "examples/spawn-and-move/src/others.cairo"

# Check the context around ContractInitialized in world_contract.cairo
echo "Checking ContractInitialized context in world contract..."
rg -A 10 "ContractInitialized" "crates/dojo/core/src/world/world_contract.cairo"

Length of output: 1817

Comment on lines +1789 to +1795
<<<<<<< HEAD
"address": "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1",
"class_hash": "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e",
=======
"address": "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792",
"class_hash": "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88",
>>>>>>> dojo/main
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! Please resolve the merge conflict.

There's an unresolved merge conflict in the "others" contract configuration. The conflict shows different values for both the address and class_hash:

HEAD version:

  • address: 0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1
  • class_hash: 0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e

dojo/main version:

  • address: 0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792
  • class_hash: 0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88

Please resolve this conflict by choosing the appropriate version based on your migration requirements.

🧰 Tools
🪛 Biome

[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: unexpected character <

(parse)


[error] 1789-1789: expected , but instead found HEAD

Remove HEAD

(parse)


[error] 1790-1790: expected , but instead found "address"

Remove "address"

(parse)


[error] 1790-1790: expected , but instead found :

Remove :

(parse)


[error] 1790-1790: expected , but instead found "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1"

Remove "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1"

(parse)


[error] 1791-1791: expected , but instead found :

Remove :

(parse)


[error] 1791-1791: expected , but instead found "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e"

Remove "0x4f290c42a0a2e342bf8da74103a31c6e3f2ebca2c72054da9d6d24754c3cc7e"

(parse)


[error] 1791-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1792-1792: unexpected character =

(parse)


[error] 1793-1793: expected , but instead found "address"

Remove "address"

(parse)


[error] 1793-1793: expected , but instead found :

Remove :

(parse)


[error] 1793-1793: expected , but instead found "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792"

Remove "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792"

(parse)


[error] 1794-1794: expected , but instead found :

Remove :

(parse)


[error] 1794-1794: expected , but instead found "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88"

Remove "0x3356ff99134a997be6f9366c47ad18993aac3e29803819cc80309a57fa23f88"

(parse)


[error] 1794-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: unexpected character >

(parse)


[error] 1795-1795: expected , but instead found dojo

Remove dojo

(parse)


[error] 1795-1795: unexpected character /

(parse)


[error] 1795-1795: expected , but instead found main

Remove main

(parse)

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