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): fix profile detection and UI rework #2606

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/sozo/src/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use dojo_utils::Invoker;
use dojo_world::contracts::naming::ensure_namespace;
use scarb::core::Config;
use sozo_ops::migration_ui::MigrationUi;
use sozo_scarbext::WorkspaceExt;
use sozo_walnut::WalnutDebugger;
use starknet::core::types::{Call, Felt};
Expand Down Expand Up @@ -79,11 +80,14 @@
);

config.tokio_handle().block_on(async {
let mut spinner = MigrationUi::new("").with_silent();

Check warning on line 83 in bin/sozo/src/commands/execute.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/execute.rs#L83

Added line #L83 was not covered by tests

let (world_diff, account, _) = utils::get_world_diff_and_account(
self.account,
self.starknet.clone(),
self.world,
&ws,
&mut spinner,

Check warning on line 90 in bin/sozo/src/commands/execute.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/execute.rs#L90

Added line #L90 was not covered by tests
)
.await?;

Expand Down
18 changes: 8 additions & 10 deletions bin/sozo/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use dojo_utils::{self, TxnConfig};
use dojo_world::contracts::WorldContract;
use scarb::core::{Config, Workspace};
use sozo_ops::migrate::{Migration, MigrationResult, MigrationUi};
use sozo_ops::migrate::{Migration, MigrationResult};
use sozo_ops::migration_ui::MigrationUi;
use sozo_scarbext::WorkspaceExt;
use spinoff::{spinner, spinners, Spinner};
use starknet::core::utils::parse_cairo_short_string;
use starknet::providers::Provider;
use tabled::settings::Style;
Expand Down Expand Up @@ -45,20 +45,17 @@

let MigrateArgs { world, starknet, account, .. } = self;

let frames = spinner!(["⛩️ ", "🎃", "👻", "🧟", "💀"], 500);
// let frames = spinner!(["⛩️ ", "🥷 ", "🗡️ "], 500);

config.tokio_handle().block_on(async {
print_banner(&ws, &starknet).await?;

let mut spinner =
MigrationUi::Spinner(Spinner::new(frames, "Evaluating world diff...", None));
let mut spinner = MigrationUi::new("Evaluating world diff...");

Check warning on line 51 in bin/sozo/src/commands/migrate.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/migrate.rs#L51

Added line #L51 was not covered by tests

let mut txn_config: TxnConfig = self.transaction.into();
txn_config.wait = true;

let (world_diff, account, rpc_url) =
utils::get_world_diff_and_account(account, starknet, world, &ws).await?;
utils::get_world_diff_and_account(account, starknet, world, &ws, &mut spinner)
.await?;

Check warning on line 58 in bin/sozo/src/commands/migrate.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/migrate.rs#L57-L58

Added lines #L57 - L58 were not covered by tests

let world_address = world_diff.world_info.address;

Expand All @@ -84,7 +81,7 @@
("🎃", format!("No changes for world at address {:#066x}", world_address))
};

spinner.stop_and_persist(symbol, Box::leak(end_text.into_boxed_str()));
spinner.stop_and_persist_boxed(symbol, end_text);

Check warning on line 84 in bin/sozo/src/commands/migrate.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/migrate.rs#L84

Added line #L84 was not covered by tests

Ok(())
})
Expand All @@ -100,7 +97,8 @@

/// Prints the migration banner.
async fn print_banner(ws: &Workspace<'_>, starknet: &StarknetOptions) -> Result<()> {
let (provider, rpc_url) = starknet.provider(None)?;
let profile_config = ws.load_profile_config()?;
let (provider, rpc_url) = starknet.provider(profile_config.env.as_ref())?;

Check warning on line 101 in bin/sozo/src/commands/migrate.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/migrate.rs#L100-L101

Added lines #L100 - L101 were not covered by tests

let chain_id = provider.chain_id().await?;
let chain_id = parse_cairo_short_string(&chain_id)
Expand Down
2 changes: 1 addition & 1 deletion bin/sozo/src/commands/options/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ impl AccountOptions {
let account_address = self.account_address(env_metadata)?;

let signer = self.signer.signer(env_metadata, false)?;
trace!(?signer, "Signer obtained.");

trace!("Fetching chain id...");
let chain_id = provider.chain_id().await?;
trace!(?chain_id);

Comment on lines +110 to 113
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 enhancing error context for chain ID fetching.

The chain ID fetch could benefit from additional error context to help diagnose RPC-related issues.

-        let chain_id = provider.chain_id().await?;
+        let chain_id = provider.chain_id().await.with_context(|| "Failed to fetch chain ID from provider")?;
📝 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
trace!("Fetching chain id...");
let chain_id = provider.chain_id().await?;
trace!(?chain_id);
trace!("Fetching chain id...");
let chain_id = provider.chain_id().await.with_context(|| "Failed to fetch chain ID from provider")?;
trace!(?chain_id);

Expand Down
7 changes: 7 additions & 0 deletions bin/sozo/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use katana_rpc_api::starknet::RPC_SPEC_VERSION;
use scarb::core::{TomlManifest, Workspace};
use semver::Version;
use sozo_ops::migration_ui::MigrationUi;
use sozo_scarbext::WorkspaceExt;
use starknet::accounts::{Account, ConnectedAccount};
use starknet::core::types::Felt;
Expand Down Expand Up @@ -144,19 +145,25 @@
starknet: StarknetOptions,
world: WorldOptions,
ws: &Workspace<'_>,
ui: &mut MigrationUi,

Check warning on line 148 in bin/sozo/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/utils.rs#L148

Added line #L148 was not covered by tests
) -> Result<(WorldDiff, SozoAccount<JsonRpcClient<HttpTransport>>, String)> {
let profile_config = ws.load_profile_config()?;
let env = profile_config.env.as_ref();

let (world_diff, provider, rpc_url) =
get_world_diff_and_provider(starknet.clone(), world, ws).await?;

// Ensures we don't interfere with the spinner if a password must be prompted.
ui.stop();

Check warning on line 157 in bin/sozo/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/utils.rs#L157

Added line #L157 was not covered by tests

Comment on lines +156 to +158
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 enhancing error handling for UI operations, sensei!

While the UI integration improves user feedback, consider handling potential UI operation failures:

-    ui.stop();
+    if let Err(e) = ui.stop() {
+        tracing::warn!("Failed to stop UI spinner: {}", e);
+    }

     let account = {
         account
             .account(provider, world_diff.world_info.address, &starknet, env, &world_diff)
             .await?
     };

-    ui.restart("Verifying account...");
+    if let Err(e) = ui.restart("Verifying account...") {
+        tracing::warn!("Failed to restart UI with status: {}", e);
+    }

This ensures the main flow continues even if UI operations fail.

Also applies to: 165-166

let account = {
account
.account(provider, world_diff.world_info.address, &starknet, env, &world_diff)
.await?
};

ui.restart("Verifying account...");

Check warning on line 166 in bin/sozo/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/utils.rs#L165-L166

Added lines #L165 - L166 were not covered by tests
if !dojo_utils::is_deployed(account.address(), &account.provider()).await? {
return Err(anyhow!("Account with address {:#x} doesn't exist.", account.address()));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo/utils/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
} else if no_wait {
Err(anyhow!("Could not find password. Please specify the password."))
} else {
Ok(rpassword::prompt_password("Enter password: ")?.to_owned())
Ok(rpassword::prompt_password("Enter the keystore password: ")?.to_owned())

Check warning on line 11 in crates/dojo/utils/src/keystore.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/utils/src/keystore.rs#L11

Added line #L11 was not covered by tests
}
}
5 changes: 5 additions & 0 deletions crates/dojo/world/src/local/artifact_to_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

impl WorldLocal {
pub fn from_directory<P: AsRef<Path>>(dir: P, profile_config: ProfileConfig) -> Result<Self> {
trace!(
?profile_config,
directory = %dir.as_ref().to_string_lossy(),
"Loading world from directory."

Check warning on line 27 in crates/dojo/world/src/local/artifact_to_local.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/world/src/local/artifact_to_local.rs#L26-L27

Added lines #L26 - L27 were not covered by tests
);
let mut resources = vec![];

let mut world_class = None;
Expand Down
1 change: 1 addition & 0 deletions crates/sozo/ops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod account;
pub mod migrate;
pub mod migration_ui;

#[cfg(test)]
pub mod tests;
117 changes: 66 additions & 51 deletions crates/sozo/ops/src/migrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! initialization of contracts can mutate resources.

use std::collections::HashMap;
use std::fmt;
use std::str::FromStr;

use cainome::cairo_serde::{ByteArray, ClassHash, ContractAddress};
Expand All @@ -30,14 +29,15 @@
use dojo_world::local::ResourceLocal;
use dojo_world::remote::ResourceRemote;
use dojo_world::{utils, ResourceType};
use spinoff::Spinner;
use starknet::accounts::{ConnectedAccount, SingleOwnerAccount};
use starknet::core::types::{Call, FlattenedSierraClass};
use starknet::providers::AnyProvider;
use starknet::signers::LocalWallet;
use starknet_crypto::Felt;
use tracing::trace;

use crate::migration_ui::MigrationUi;

pub mod error;
pub use error::MigrationError;

Expand All @@ -61,36 +61,6 @@
pub manifest: Manifest,
}

pub enum MigrationUi {
Spinner(Spinner),
None,
}

impl fmt::Debug for MigrationUi {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Spinner(_) => write!(f, "Spinner"),
Self::None => write!(f, "None"),
}
}
}

impl MigrationUi {
pub fn update_text(&mut self, text: &'static str) {
match self {
Self::Spinner(s) => s.update_text(text),
Self::None => (),
}
}

pub fn stop_and_persist(&mut self, symbol: &'static str, text: &'static str) {
match self {
Self::Spinner(s) => s.stop_and_persist(symbol, text),
Self::None => (),
}
}
}

impl<A> Migration<A>
where
A: ConnectedAccount + Sync + Send,
Expand All @@ -113,23 +83,17 @@
/// spinner.
pub async fn migrate(
&self,
spinner: &mut MigrationUi,
ui: &mut MigrationUi,

Check warning on line 86 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L86

Added line #L86 was not covered by tests
) -> Result<MigrationResult, MigrationError<A::SignError>> {
spinner.update_text("Deploying world...");
ui.update_text("Deploying world...");

Check warning on line 88 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L88

Added line #L88 was not covered by tests
Comment on lines 85 to +88
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 enhancing error state handling in UI updates.

While the UI updates provide good feedback during successful operations, consider adding error state handling to provide clear feedback when operations fail. This would improve the user experience during error scenarios.

 pub async fn migrate(
     &self,
     ui: &mut MigrationUi,
 ) -> Result<MigrationResult, MigrationError<A::SignError>> {
     ui.update_text("Deploying world...");
-    let world_has_changed = self.ensure_world().await?;
+    let world_has_changed = match self.ensure_world().await {
+        Ok(changed) => {
+            ui.update_text("World deployment successful!");
+            changed
+        }
+        Err(e) => {
+            ui.update_text(&format!("World deployment failed: {}", e));
+            return Err(e);
+        }
+    };

Also applies to: 91-96

let world_has_changed = self.ensure_world().await?;

let resources_have_changed = if !self.diff.is_synced() {
spinner.update_text("Syncing resources...");
self.sync_resources().await?
} else {
false
};
let resources_have_changed =
if !self.diff.is_synced() { self.sync_resources(ui).await? } else { false };

Check warning on line 92 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L91-L92

Added lines #L91 - L92 were not covered by tests

spinner.update_text("Syncing permissions...");
let permissions_have_changed = self.sync_permissions().await?;
let permissions_have_changed = self.sync_permissions(ui).await?;

Check warning on line 94 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L94

Added line #L94 was not covered by tests

spinner.update_text("Initializing contracts...");
let contracts_have_changed = self.initialize_contracts().await?;
let contracts_have_changed = self.initialize_contracts(ui).await?;

Check warning on line 96 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L96

Added line #L96 was not covered by tests

Ok(MigrationResult {
has_changes: world_has_changed
Expand All @@ -152,7 +116,12 @@
/// found in the [`ProfileConfig`].
///
/// Returns true if at least one contract has been initialized, false otherwise.
async fn initialize_contracts(&self) -> Result<bool, MigrationError<A::SignError>> {
async fn initialize_contracts(
&self,
ui: &mut MigrationUi,
) -> Result<bool, MigrationError<A::SignError>> {
ui.update_text("Initializing contracts...");

Check warning on line 124 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L119-L124

Added lines #L119 - L124 were not covered by tests
let mut invoker = Invoker::new(&self.world.account, self.txn_config);

let init_call_args = if let Some(init_call_args) = &self.profile_config.init_call_args {
Expand Down Expand Up @@ -235,10 +204,21 @@

let has_changed = !invoker.calls.is_empty();

if self.do_multicall() {
invoker.multicall().await?;
} else {
invoker.invoke_all_sequentially().await?;
if !ordered_init_calls.is_empty() {
if self.do_multicall() {
let ui_text = format!("Initializing {} contracts...", ordered_init_calls.len());
ui.update_text_boxed(ui_text);

invoker.multicall().await?;

Check warning on line 212 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L207-L212

Added lines #L207 - L212 were not covered by tests
} else {
let ui_text = format!(
"Initializing {} contracts (sequentially)...",
ordered_init_calls.len()
);
ui.update_text_boxed(ui_text);

invoker.invoke_all_sequentially().await?;

Check warning on line 220 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L214-L220

Added lines #L214 - L220 were not covered by tests
}
Comment on lines +207 to +221
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance progress tracking for sequential contract initialization.

While the current implementation provides good feedback, sequential execution could benefit from per-contract progress updates to give users better visibility into the initialization process.

 if !self.do_multicall() {
     let ui_text = format!(
         "Initializing {} contracts (sequentially)...",
         ordered_init_calls.len()
     );
     ui.update_text_boxed(ui_text);

-    invoker.invoke_all_sequentially().await?;
+    for (i, call) in invoker.calls.iter().enumerate() {
+        ui.update_text(&format!("Initializing contract {}/{}", i + 1, invoker.calls.len()));
+        invoker.invoke_single(call).await?;
+    }
 }

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

}

Ok(has_changed)
Expand All @@ -257,7 +237,12 @@
/// overlay resource, which can contain also writers.
///
/// Returns true if at least one permission has changed, false otherwise.
async fn sync_permissions(&self) -> Result<bool, MigrationError<A::SignError>> {
async fn sync_permissions(
&self,
ui: &mut MigrationUi,
) -> Result<bool, MigrationError<A::SignError>> {
ui.update_text("Syncing permissions...");

Check warning on line 245 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L240-L245

Added lines #L240 - L245 were not covered by tests
let mut invoker = Invoker::new(&self.world.account, self.txn_config);

// Only takes the local permissions that are not already set onchain to apply them.
Expand Down Expand Up @@ -296,8 +281,14 @@
let has_changed = !invoker.calls.is_empty();

if self.do_multicall() {
let ui_text = format!("Syncing {} permissions...", invoker.calls.len());
ui.update_text_boxed(ui_text);

Check warning on line 286 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L284-L286

Added lines #L284 - L286 were not covered by tests
invoker.multicall().await?;
} else {
let ui_text = format!("Syncing {} permissions (sequentially)...", invoker.calls.len());
ui.update_text_boxed(ui_text);

Check warning on line 291 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L289-L291

Added lines #L289 - L291 were not covered by tests
Comment on lines +284 to +291
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Differentiate between writer and owner permissions in UI updates.

The current UI feedback could be more informative by breaking down the permission types being synced.

-let ui_text = format!("Syncing {} permissions...", invoker.calls.len());
+let (writer_count, owner_count) = invoker.calls.iter().fold((0, 0), |(w, o), call| {
+    if call.selector.to_string().contains("grant_writer") {
+        (w + 1, o)
+    } else {
+        (w, o + 1)
+    }
+});
+let ui_text = format!("Syncing {} writer and {} owner permissions...", writer_count, owner_count);

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

invoker.invoke_all_sequentially().await?;
}

Expand All @@ -307,13 +298,19 @@
/// Syncs the resources by declaring the classes and registering/upgrading the resources.
///
/// Returns true if at least one resource has changed, false otherwise.
async fn sync_resources(&self) -> Result<bool, MigrationError<A::SignError>> {
async fn sync_resources(
&self,
ui: &mut MigrationUi,
) -> Result<bool, MigrationError<A::SignError>> {
ui.update_text("Syncing resources...");

Check warning on line 306 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L301-L306

Added lines #L301 - L306 were not covered by tests
let mut invoker = Invoker::new(&self.world.account, self.txn_config);

// Namespaces must be synced first, since contracts, models and events are namespaced.
self.namespaces_getcalls(&mut invoker).await?;

let mut classes: HashMap<Felt, FlattenedSierraClass> = HashMap::new();
let mut n_resources = 0;

Check warning on line 313 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L313

Added line #L313 was not covered by tests
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance resource type tracking in UI updates.

The current implementation tracks total resources, but providing a breakdown by resource type would offer more detailed progress information.

-let mut n_resources = 0;
+#[derive(Default)]
+struct ResourceCounts {
+    contracts: usize,
+    models: usize,
+    events: usize,
+}
+let mut counts = ResourceCounts::default();

 // In the resource type match blocks:
 match resource.resource_type() {
     ResourceType::Contract => {
         // ... existing code ...
-        n_resources += 1;
+        counts.contracts += 1;
     }
     ResourceType::Model => {
         // ... existing code ...
-        n_resources += 1;
+        counts.models += 1;
     }
     ResourceType::Event => {
         // ... existing code ...
-        n_resources += 1;
+        counts.events += 1;
     }
 }

-let ui_text = format!("Registering {} resources...", n_resources);
+let ui_text = format!(
+    "Registering resources: {} contracts, {} models, {} events",
+    counts.contracts, counts.models, counts.events
+);

Also applies to: 327-327, 333-333, 339-339, 400-407


// Collects the calls and classes to be declared to sync the resources.
for resource in self.diff.resources.values() {
Expand All @@ -327,16 +324,19 @@
self.contracts_calls_classes(resource).await?;
invoker.extend_calls(contract_calls);
classes.extend(contract_classes);
n_resources += 1;

Check warning on line 327 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L327

Added line #L327 was not covered by tests
}
ResourceType::Model => {
let (model_calls, model_classes) = self.models_calls_classes(resource).await?;
invoker.extend_calls(model_calls);
classes.extend(model_classes);
n_resources += 1;

Check warning on line 333 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L333

Added line #L333 was not covered by tests
}
ResourceType::Event => {
let (event_calls, event_classes) = self.events_calls_classes(resource).await?;
invoker.extend_calls(event_calls);
classes.extend(event_classes);
n_resources += 1;

Check warning on line 339 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L339

Added line #L339 was not covered by tests
}
_ => continue,
}
Expand All @@ -350,11 +350,16 @@
// Since migrator account from `self.world.account` is under the [`ConnectedAccount`] trait,
// we can group it with the predeployed accounts which are concrete types.
let accounts = self.get_accounts().await;
let n_classes = classes.len();

Check warning on line 353 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L353

Added line #L353 was not covered by tests

if accounts.is_empty() {
trace!("Declaring classes with migrator account.");
let mut declarer = Declarer::new(&self.world.account, self.txn_config);
declarer.extend_classes(classes.into_iter().collect());

let ui_text = format!("Declaring {} classes...", n_classes);
ui.update_text_boxed(ui_text);

Check warning on line 362 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L359-L362

Added lines #L359 - L362 were not covered by tests
declarer.declare_all().await?;
} else {
trace!("Declaring classes with {} accounts.", accounts.len());
Expand All @@ -368,6 +373,10 @@
declarers[declarer_idx].add_class(casm_class_hash, class);
}

let ui_text =
format!("Declaring {} classes with {} accounts...", n_classes, declarers.len());
ui.update_text_boxed(ui_text);

Check warning on line 378 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L376-L378

Added lines #L376 - L378 were not covered by tests

let declarers_futures =
futures::future::join_all(declarers.into_iter().map(|d| d.declare_all())).await;

Expand All @@ -388,8 +397,14 @@
}

if self.do_multicall() {
let ui_text = format!("Registering {} resources...", n_resources);
ui.update_text_boxed(ui_text);

Check warning on line 402 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L400-L402

Added lines #L400 - L402 were not covered by tests
invoker.multicall().await?;
} else {
let ui_text = format!("Registering {} resources (sequentially)...", n_resources);
ui.update_text_boxed(ui_text);

Check warning on line 407 in crates/sozo/ops/src/migrate/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migrate/mod.rs#L405-L407

Added lines #L405 - L407 were not covered by tests
invoker.invoke_all_sequentially().await?;
}

Expand Down
Loading
Loading