diff --git a/crates/sozo/Cargo.toml b/crates/sozo/Cargo.toml index d6fbb86796..da7b252cc5 100644 --- a/crates/sozo/Cargo.toml +++ b/crates/sozo/Cargo.toml @@ -46,4 +46,5 @@ url.workspace = true [dev-dependencies] assert_fs = "1.0.10" dojo-test-utils = { path = "../dojo-test-utils", features = [ "build-examples" ] } +katana-runner = { path = "../katana/runner" } snapbox = "0.4.6" diff --git a/crates/sozo/src/commands/options/account.rs b/crates/sozo/src/commands/options/account.rs index d8b22fbaef..17e05f4d07 100644 --- a/crates/sozo/src/commands/options/account.rs +++ b/crates/sozo/src/commands/options/account.rs @@ -105,3 +105,66 @@ impl AccountOptions { } } } + +#[cfg(test)] +mod tests { + use clap::Parser; + use katana_runner::KatanaRunner; + use starknet::accounts::{Call, ExecutionEncoder}; + use starknet_crypto::FieldElement; + + use super::AccountOptions; + + #[derive(clap::Parser)] + struct Command { + #[clap(flatten)] + account: AccountOptions, + } + + #[tokio::test] + async fn legacy_flag_works_as_expected() { + let cmd = Command::parse_from([ + "sozo", + "--legacy", + "--account-address", + "0x0", + "--private-key", + "0x1", + ]); + let (_runner, provider) = KatanaRunner::new().unwrap(); + let dummy_call = vec![Call { + to: FieldElement::from_hex_be("0x0").unwrap(), + selector: FieldElement::from_hex_be("0x1").unwrap(), + calldata: vec![ + FieldElement::from_hex_be("0x2").unwrap(), + FieldElement::from_hex_be("0x3").unwrap(), + ], + }]; + + // HACK: SingleOwnerAccount doesn't expose a way to check `encoding` type used in struct, so + // checking it by encoding a dummy call and checking which method it used to encode the call + let account = cmd.account.account(provider, None).await.unwrap(); + let result = account.encode_calls(&dummy_call); + assert!(*result.get(3).unwrap() == FieldElement::from_hex_be("0x0").unwrap()); + } + + #[tokio::test] + async fn without_legacy_flag_works_as_expected() { + let cmd = Command::parse_from(["sozo", "--account-address", "0x0", "--private-key", "0x1"]); + let (_runner, provider) = KatanaRunner::new().unwrap(); + let dummy_call = vec![Call { + to: FieldElement::from_hex_be("0x0").unwrap(), + selector: FieldElement::from_hex_be("0x1").unwrap(), + calldata: vec![ + FieldElement::from_hex_be("0x2").unwrap(), + FieldElement::from_hex_be("0x3").unwrap(), + ], + }]; + + // HACK: SingleOwnerAccount doesn't expose a way to check `encoding` type used in struct, so + // checking it by encoding a dummy call and checking which method it used to encode the call + let account = cmd.account.account(provider, None).await.unwrap(); + let result = account.encode_calls(&dummy_call); + assert!(*result.get(3).unwrap() == FieldElement::from_hex_be("0x2").unwrap()); + } +} diff --git a/crates/sozo/src/ops/migration/mod.rs b/crates/sozo/src/ops/migration/mod.rs index 1fbfb96b29..33bbd30ec9 100644 --- a/crates/sozo/src/ops/migration/mod.rs +++ b/crates/sozo/src/ops/migration/mod.rs @@ -471,11 +471,15 @@ where .map(|c| world.register_model_getcall(&c.diff.local.into())) .collect::>(); + dbg!(&calls); + let InvokeTransactionResult { transaction_hash } = migrator .execute(calls) .send() .await - .map_err(|e| anyhow!("Failed to register models to World: {e}"))?; + .map_err(|e| anyhow!("Failed to register models to World: {e:?}"))?; + + dbg!(&transaction_hash); TransactionWaiter::new(transaction_hash, migrator.provider()).await?;