Skip to content

Commit

Permalink
tests: add tests for migration (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm authored Nov 2, 2024
1 parent 9f3f501 commit 301706a
Show file tree
Hide file tree
Showing 30 changed files with 90 additions and 9,428 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/sozo/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl MigrateArgs {
config.tokio_handle().block_on(async {
print_banner(&ws, &starknet).await?;

let mut spinner = MigrationUi::new("Evaluating world diff...");
let mut spinner = MigrationUi::new(Some("Evaluating world diff..."));

let (world_diff, account, rpc_url) = utils::get_world_diff_and_account(
account,
Expand Down
2 changes: 1 addition & 1 deletion bin/sozo/tests/test_data/policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"method": "upgrade"
},
{
"target": "0x79e0653fbebdbdb864ca69d1470b263f2efdfce9cf355cfe9c7719627eff792",
"target": "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1",
"method": "upgrade"
},
{
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo/world/src/remote/events_to_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl WorldRemote {
resource.push_class_hash(e.class_hash.into());
}
WorldEvent::ContractInitialized(e) => {
// Unwrap is safe bcause the contract must exist in the world.
// Unwrap is safe because the contract must exist in the world.
let resource = self.resources.get_mut(&e.selector).unwrap();
let contract = resource.as_contract_mut()?;
contract.is_initialized = true;
Expand Down
3 changes: 3 additions & 0 deletions crates/sozo/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dojo-test-utils = { workspace = true, features = [ "build-examples" ] }
ipfs-api-backend-hyper = { git = "https://github.com/ferristseng/rust-ipfs-api", rev = "af2c17f7b19ef5b9898f458d97a90055c3605633", features = [ "with-hyper-rustls" ] }
katana-runner.workspace = true
dojo-types.workspace = true
tokio.workspace = true
scarb.workspace = true
sozo-scarbext.workspace = true

[features]
test-utils = [ "dep:dojo-test-utils", "dep:katana-runner" ]
Expand Down
10 changes: 4 additions & 6 deletions crates/sozo/ops/src/migrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,15 @@ where

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

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

invoker.multicall().await?;
} else {
let ui_text = format!(
"Initializing {} contracts (sequentially)...",
ordered_init_calls.len()
);
let ui_text =
format!("Initializing {} contracts (sequentially)...", invoker.calls.len());
ui.update_text_boxed(ui_text);

invoker.invoke_all_sequentially().await?;
Expand Down
14 changes: 10 additions & 4 deletions crates/sozo/ops/src/migration_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ impl fmt::Debug for MigrationUi {

impl MigrationUi {
/// Returns a new instance with the default frames.
pub fn new(text: &'static str) -> Self {
let frames = spinner!(["⛩️ ", "🎃", "👻", "🧟", "💀"], 500);
let spinner = Spinner::new(frames.clone(), text, None);
Self { spinner, default_frames: frames, silent: false }
pub fn new(text: Option<&'static str>) -> Self {
if let Some(text) = text {
let frames = spinner!(["⛩️ ", "🎃", "👻", "🧟", "💀"], 500);
let spinner = Spinner::new(frames.clone(), text, None);
Self { spinner, default_frames: frames, silent: false }
} else {
let frames = spinner!([""], 5000);
let spinner = Spinner::new(frames.clone(), "", None);
Self { spinner, default_frames: frames, silent: false }
}
}

/// Returns a new instance with the silent flag set.
Expand Down
Loading

0 comments on commit 301706a

Please sign in to comment.