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
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
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 @@
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..."));

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 (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 @@

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());

Check warning on line 215 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-L215

Added lines #L214 - L215 were not covered by tests
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 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 }

Check warning on line 27 in crates/sozo/ops/src/migration_ui.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration_ui.rs#L25-L27

Added lines #L25 - L27 were not covered by tests
} 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
Loading