Skip to content

Commit

Permalink
test: add tests related to change
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed Jan 11, 2024
1 parent 8a13577 commit a181242
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
63 changes: 63 additions & 0 deletions crates/sozo/src/commands/options/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 5 additions & 1 deletion crates/sozo/src/ops/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,15 @@ where
.map(|c| world.register_model_getcall(&c.diff.local.into()))
.collect::<Vec<_>>();

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?;

Expand Down

0 comments on commit a181242

Please sign in to comment.