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

fix(sozo): upgrade_contract use selector instead of contract_address #2234

Merged
merged 4 commits into from
Jul 30, 2024

Conversation

notV4l
Copy link
Collaborator

@notV4l notV4l commented Jul 30, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced contract deployment capabilities by allowing optional parameters to improve flexibility and control in the deployment process.
    • Added functionality for migration processes to accept additional context metadata for improved traceability.
    • Introduced a new test case to validate the migration process followed by an upgrade, ensuring the integrity of the workflow.
  • Bug Fixes

    • Improved handling of contract upgrades by incorporating a selector derived from a newly introduced tag parameter.

Copy link

coderabbitai bot commented Jul 30, 2024

Walkthrough

Ohayo, sensei! The recent changes enhance the flexibility and functionality of the contract deployment and migration processes within the Dojo framework. Key modifications include the addition of contextual parameters in the deploy_world and deploy_dojo_contract methods, allowing for improved management of contract interactions. These updates streamline the logic flow and refine the system's capability to handle various deployment scenarios, making it more robust and adaptable.

Changes

Files Change Summary
crates/dojo-world/src/contracts/world_test.rs
crates/dojo-world/src/migration/mod.rs
Added tag: &str parameter to deploy_world and deploy_dojo_contract methods, enhancing their capability to handle contextual information during deployments.
crates/sozo/ops/src/migration/migrate.rs Modified asynchronous function calls to include an additional tag argument, improving the context and traceability of the migration process.
bin/sozo/tests/test_migrate.rs Introduced a new asynchronous test function, test_migrate_then_upgrade, to validate the migration followed by an upgrade, enhancing the testing framework.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d873553 and fe1c0f9.

Files selected for processing (4)
  • bin/sozo/tests/test_migrate.rs (3 hunks)
  • crates/dojo-world/src/contracts/world_test.rs (1 hunks)
  • crates/dojo-world/src/migration/mod.rs (4 hunks)
  • crates/sozo/ops/src/migration/migrate.rs (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • crates/dojo-world/src/contracts/world_test.rs
  • crates/dojo-world/src/migration/mod.rs
  • crates/sozo/ops/src/migration/migrate.rs
Additional comments not posted (2)
bin/sozo/tests/test_migrate.rs (2)

58-59: Ohayo, sensei! Consider error handling for KatanaRunner initialization.

Adding error handling for the KatanaRunner initialization can improve robustness.

-  let sequencer = KatanaRunner::new().expect("Failed to start runner.");
+  let sequencer = KatanaRunner::new().expect("Failed to start KatanaRunner.");

Likely invalid or redundant comment.


Line range hint 1-10:
Ohayo, sensei! Ensure all dependencies are necessary.

Verify that all imported modules are utilized within the file to avoid unnecessary dependencies.

Verification successful

Ohayo, sensei! It looks like our initial attempt to verify the usage of imported modules hit a snag due to a regex parse error. Let's break it down and verify each module separately to ensure all dependencies are necessary.


Ohayo, sensei! After thoroughly checking, I can confirm that all imported modules in bin/sozo/tests/test_migrate.rs are utilized within the file. No unnecessary dependencies were found.

  • dojo_test_utils::compiler::CompilerTestSetup is used for setting up compiler tests.
  • katana_runner::KatanaRunner is used for starting the runner.
  • scarb::compiler::Profile is used for building test configurations.
  • starknet::accounts::Account and starknet::core::types::{BlockId, BlockTag} are used for account and block ID management.
  • utils::snapbox::get_snapbox is used for assertions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of imported modules.

# Test: Search for the usage of each imported module. Expect: All modules are used within the file.
rg --type rust 'use dojo_test_utils::compiler::CompilerTestSetup|use katana_runner::KatanaRunner|use scarb::compiler::Profile|use starknet::accounts::Account|use starknet::core::types::{BlockId, BlockTag}|use utils::snapbox::get_snapbox'

Length of output: 712


Script:

#!/bin/bash
# Description: Verify the usage of each imported module individually.

# Verify usage of dojo_test_utils::compiler::CompilerTestSetup
rg 'CompilerTestSetup' bin/sozo/tests/test_migrate.rs

# Verify usage of katana_runner::KatanaRunner
rg 'KatanaRunner' bin/sozo/tests/test_migrate.rs

# Verify usage of scarb::compiler::Profile
rg 'Profile' bin/sozo/tests/test_migrate.rs

# Verify usage of starknet::accounts::Account
rg 'Account' bin/sozo/tests/test_migrate.rs

# Verify usage of starknet::core::types::{BlockId, BlockTag}
rg 'BlockId' bin/sozo/tests/test_migrate.rs
rg 'BlockTag' bin/sozo/tests/test_migrate.rs

# Verify usage of utils::snapbox::get_snapbox
rg 'get_snapbox' bin/sozo/tests/test_migrate.rs

Length of output: 1593


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.27%. Comparing base (930d0cb) to head (fe1c0f9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2234      +/-   ##
==========================================
+ Coverage   70.10%   70.27%   +0.17%     
==========================================
  Files         340      340              
  Lines       44802    44806       +4     
==========================================
+ Hits        31409    31489      +80     
+ Misses      13393    13317      -76     

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

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Great catch, thank you @notV4l.

We then need at least one test that ensures we don't break upgradeability in the future.

@glihm glihm changed the title sozo: upgrade_contract use selector instead of contract_address fix(sozo): upgrade_contract use selector instead of contract_address Jul 30, 2024
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: 3

Comment on lines +52 to +56
#[tokio::test(flavor = "multi_thread")]
async fn test_migrate_then_upgrade() {
let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/");
let config = setup.build_test_config("spawn-and-move", Profile::DEV);
let tmp_dir = config.manifest_path().parent().unwrap();
Copy link

Choose a reason for hiding this comment

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

Ohayo, sensei! Consider error handling for setup and config.

Adding error handling for the setup and config steps can improve robustness.

-  let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/");
-  let config = setup.build_test_config("spawn-and-move", Profile::DEV);
+  let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples()").expect("Failed to initialize CompilerTestSetup.");
+  let config = setup.build_test_config("spawn-and-move", Profile::DEV).expect("Failed to build test config.");
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
#[tokio::test(flavor = "multi_thread")]
async fn test_migrate_then_upgrade() {
let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/");
let config = setup.build_test_config("spawn-and-move", Profile::DEV);
let tmp_dir = config.manifest_path().parent().unwrap();
#[tokio::test(flavor = "multi_thread")]
async fn test_migrate_then_upgrade() {
let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/").expect("Failed to initialize CompilerTestSetup.");
let config = setup.build_test_config("spawn-and-move", Profile::DEV).expect("Failed to build test config.");
let tmp_dir = config.manifest_path().parent().unwrap();

Comment on lines +93 to +97
get_snapbox().args(build_vec.iter()).assert().success();

let assert = get_snapbox().args(args_vec.iter()).assert().success();
let output = format!("{:#?}", assert.get_output());

Copy link

Choose a reason for hiding this comment

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

Ohayo, sensei! Ensure output verification is robust.

Consider verifying the output more robustly by checking for specific expected values.

-  let output = format!("{:#?}", assert.get_output());
+  let output = String::from_utf8(assert.get_output().to_vec()).expect("Failed to convert output to string.");
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
get_snapbox().args(build_vec.iter()).assert().success();
let assert = get_snapbox().args(args_vec.iter()).assert().success();
let output = format!("{:#?}", assert.get_output());
get_snapbox().args(build_vec.iter()).assert().success();
let assert = get_snapbox().args(args_vec.iter()).assert().success();
let output = String::from_utf8(assert.get_output().to_vec()).expect("Failed to convert output to string.");

Comment on lines +85 to +89
// Modify the actions contracts to have a new class hash.
let actions_path = tmp_dir.join("src/actions.cairo");
let mut actions_content = fs::read_to_string(&actions_path).unwrap();
actions_content = actions_content.replace("quantity: 100", "quantity: 200");
fs::write(&actions_path, actions_content).unwrap();
Copy link

Choose a reason for hiding this comment

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

Ohayo, sensei! Ensure error handling for file operations.

Adding error handling for file read and write operations can improve robustness.

-  let actions_content = fs::read_to_string(&actions_path).unwrap();
+  let actions_content = fs::read_to_string(&actions_path).expect("Failed to read actions contract file.");
-  fs::write(&actions_path, actions_content).unwrap();
+  fs::write(&actions_path, actions_content).expect("Failed to write updated actions contract file.");
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
// Modify the actions contracts to have a new class hash.
let actions_path = tmp_dir.join("src/actions.cairo");
let mut actions_content = fs::read_to_string(&actions_path).unwrap();
actions_content = actions_content.replace("quantity: 100", "quantity: 200");
fs::write(&actions_path, actions_content).unwrap();
// Modify the actions contracts to have a new class hash.
let actions_path = tmp_dir.join("src/actions.cairo");
let actions_content = fs::read_to_string(&actions_path).expect("Failed to read actions contract file.");
actions_content = actions_content.replace("quantity: 100", "quantity: 200");
fs::write(&actions_path, actions_content).expect("Failed to write updated actions contract file.");

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Thanks @notV4l for the fix here. 👍

@glihm glihm merged commit 2a07bdd into main Jul 30, 2024
15 checks passed
@glihm glihm deleted the fix_upgrade_contract branch July 30, 2024 21:44
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