Skip to content

Commit

Permalink
Split sozo ops into its own crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonatan Chaverri committed Feb 20, 2024
1 parent 77c37f7 commit 1d1451d
Show file tree
Hide file tree
Showing 50 changed files with 105 additions and 63 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"crates/metrics",
"crates/saya/core",
"crates/sozo/signers",
"crates/sozo/ops",
"crates/torii/client",
"crates/torii/server",
"crates/torii/types-test",
Expand Down Expand Up @@ -92,6 +93,7 @@ saya-core = { path = "crates/saya/core" }

# sozo
sozo-signers = { path = "crates/sozo/signers" }
sozo-ops = { path = "crates/sozo/ops" }

anyhow = "1.0.75"
assert_matches = "1.5.0"
Expand Down
36 changes: 1 addition & 35 deletions bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,11 @@ version.workspace = true

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
cairo-lang-compiler.workspace = true
cairo-lang-defs.workspace = true
cairo-lang-filesystem.workspace = true
cairo-lang-plugins.workspace = true
cairo-lang-project.workspace = true
cairo-lang-sierra-to-casm.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-starknet.workspace = true
cairo-lang-test-plugin.workspace = true
cairo-lang-test-runner.workspace = true
cairo-lang-utils.workspace = true
camino.workspace = true
clap-verbosity-flag = "2.0.1"
clap.workspace = true
clap_complete.workspace = true
console.workspace = true
dojo-bindgen.workspace = true
dojo-lang.workspace = true
dojo-types.workspace = true
dojo-world = { workspace = true, features = [ "contracts", "metadata", "migration" ] }
notify = "6.0.1"
notify-debouncer-mini = "0.3.0"
scarb-ui.workspace = true
scarb.workspace = true
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
smol_str.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing-log = "0.1.3"
tracing.workspace = true
url.workspace = true

[dev-dependencies]
assert_fs = "1.0.10"
dojo-test-utils = { workspace = true, features = [ "build-examples" ] }
katana-runner.workspace = true
snapbox = "0.4.6"
sozo-ops.workspace = true
3 changes: 0 additions & 3 deletions bin/sozo/src/lib.rs

This file was deleted.

4 changes: 2 additions & 2 deletions bin/sozo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use scarb::compiler::CompilerRepository;
use scarb::core::{Config, TomlManifest};
use scarb_ui::{OutputFormat, Ui};
use semver::Version;
use sozo::args::{Commands, SozoArgs};
use sozo_ops::args::{Commands, SozoArgs};

fn main() {
let args = SozoArgs::parse();
Expand Down Expand Up @@ -48,7 +48,7 @@ fn cli_main(args: SozoArgs) -> Result<()> {
.compilers(compilers)
.build()?;

sozo::commands::run(args.command, &config)
sozo_ops::commands::run(args.command, &config)
}

fn verify_cairo_version_compatibility(manifest_path: &Utf8PathBuf) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions crates/benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ clap.workspace = true
scarb.workspace = true
dojo-lang.workspace = true
dojo-world.workspace = true
sozo-ops.workspace = true

[features]
default = ["skip-benchmarks"]
Expand Down
4 changes: 2 additions & 2 deletions crates/benches/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use katana_runner::KatanaRunner;
use scarb::compiler::CompilerRepository;
use scarb::core::{Config, TargetKind};
use scarb::ops::CompileOpts;
use sozo::args::{Commands, SozoArgs};
use sozo::ops::migration;
use sozo_ops::args::{Commands, SozoArgs};
use sozo_ops::migration;
use starknet::core::types::FieldElement;
use tokio::process::Command;

Expand Down
51 changes: 51 additions & 0 deletions crates/sozo/ops/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[package]
name = "sozo-ops"
edition.workspace = true
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
cairo-lang-compiler.workspace = true
cairo-lang-defs.workspace = true
cairo-lang-filesystem.workspace = true
cairo-lang-plugins.workspace = true
cairo-lang-project.workspace = true
cairo-lang-sierra-to-casm.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-starknet.workspace = true
cairo-lang-test-plugin.workspace = true
cairo-lang-test-runner.workspace = true
cairo-lang-utils.workspace = true
camino.workspace = true
clap-verbosity-flag = "2.0.1"
clap.workspace = true
clap_complete.workspace = true
console.workspace = true
dojo-bindgen.workspace = true
dojo-lang.workspace = true
dojo-types.workspace = true
dojo-world = { workspace = true, features = [ "contracts", "metadata", "migration" ] }
notify = "6.0.1"
notify-debouncer-mini = "0.3.0"
scarb-ui.workspace = true
scarb.workspace = true
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
smol_str.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing-log = "0.1.3"
tracing.workspace = true
url.workspace = true

[dev-dependencies]
assert_fs = "1.0.10"
dojo-test-utils = { workspace = true, features = [ "build-examples" ] }
katana-runner.workspace = true
snapbox = "0.4.6"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::transaction::TransactionOptions;
use super::options::world::WorldOptions;
use crate::ops::auth;
use crate::auth;

#[derive(Debug, Args)]
pub struct AuthArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod tests {

#[test]
fn build_example_with_typescript_and_unity_bindings() {
let config = build_test_config("../../examples/spawn-and-move/Scarb.toml").unwrap();
let config = build_test_config("../../../examples/spawn-and-move/Scarb.toml").unwrap();

let build_args =
BuildArgs { bindings_output: "generated".to_string(), typescript: true, unity: true };
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tracing_log::log;
use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
use crate::ops::migration;
use crate::migration;

#[derive(Args)]
pub struct DevArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use starknet::core::utils::starknet_keccak;

use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
use crate::ops::events;
use crate::events;

#[derive(Parser, Debug)]
pub struct EventsArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use starknet::core::types::FieldElement;
use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::transaction::TransactionOptions;
use crate::ops::execute;
use crate::execute;

#[derive(Debug, Args)]
#[command(about = "Execute a system with the given calldata.")]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::transaction::TransactionOptions;
use super::options::world::WorldOptions;
use crate::ops::migration;
use crate::migration;

#[derive(Args)]
pub struct MigrateArgs {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use starknet::core::types::FieldElement;

use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
use crate::ops::model;
use crate::model;

#[derive(Debug, Args)]
pub struct ModelArgs {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::transaction::TransactionOptions;
use super::options::world::WorldOptions;
use crate::ops::register;
use crate::register;

#[derive(Debug, Args)]
pub struct RegisterArgs {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions bin/sozo/src/ops/mod.rs → crates/sozo/ops/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod args;
pub mod auth;
pub mod commands;
pub mod events;
pub mod execute;
pub mod migration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ use starknet::providers::JsonRpcClient;
use starknet::signers::{LocalWallet, SigningKey};

use crate::commands::options::transaction::TransactionOptions;
use crate::ops::migration::execute_strategy;
use crate::migration::execute_strategy;

#[tokio::test(flavor = "multi_thread")]
async fn migrate_with_auto_mine() {
let config = build_test_config("../../examples/spawn-and-move/Scarb.toml").unwrap();
let config = build_test_config("../../../examples/spawn-and-move/Scarb.toml").unwrap();
let ws = ops::read_workspace(config.manifest_path(), &config)
.unwrap_or_else(|op| panic!("Error building workspace: {op:?}"));

let migration = prepare_migration("../../examples/spawn-and-move/target/dev".into()).unwrap();
let migration =
prepare_migration("../../../examples/spawn-and-move/target/dev".into()).unwrap();

let sequencer =
TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await;
Expand All @@ -40,11 +41,12 @@ async fn migrate_with_auto_mine() {

#[tokio::test(flavor = "multi_thread")]
async fn migrate_with_block_time() {
let config = build_test_config("../../examples/spawn-and-move/Scarb.toml").unwrap();
let config = build_test_config("../../../examples/spawn-and-move/Scarb.toml").unwrap();
let ws = ops::read_workspace(config.manifest_path(), &config)
.unwrap_or_else(|op| panic!("Error building workspace: {op:?}"));

let migration = prepare_migration("../../examples/spawn-and-move/target/dev".into()).unwrap();
let migration =
prepare_migration("../../../examples/spawn-and-move/target/dev".into()).unwrap();

let sequencer = TestSequencer::start(
SequencerConfig { block_time: Some(1000), ..Default::default() },
Expand All @@ -61,11 +63,12 @@ async fn migrate_with_block_time() {

#[tokio::test(flavor = "multi_thread")]
async fn migrate_with_small_fee_multiplier_will_fail() {
let config = build_test_config("../../examples/spawn-and-move/Scarb.toml").unwrap();
let config = build_test_config("../../../examples/spawn-and-move/Scarb.toml").unwrap();
let ws = ops::read_workspace(config.manifest_path(), &config)
.unwrap_or_else(|op| panic!("Error building workspace: {op:?}"));

let migration = prepare_migration("../../examples/spawn-and-move/target/dev".into()).unwrap();
let migration =
prepare_migration("../../../examples/spawn-and-move/target/dev".into()).unwrap();

let sequencer = TestSequencer::start(
Default::default(),
Expand Down Expand Up @@ -99,7 +102,7 @@ async fn migrate_with_small_fee_multiplier_will_fail() {
#[test]
fn migrate_world_without_seed_will_fail() {
let target_dir =
Utf8PathBuf::from_path_buf("../../examples/spawn-and-move/target/dev".into()).unwrap();
Utf8PathBuf::from_path_buf("../../../examples/spawn-and-move/target/dev".into()).unwrap();
let manifest = Manifest::load_from_path(target_dir.join("manifest.json")).unwrap();
let world = WorldDiff::compute(manifest, None);
let res = prepare_for_migration(None, None, target_dir, world);
Expand All @@ -109,11 +112,11 @@ fn migrate_world_without_seed_will_fail() {
#[ignore]
#[tokio::test]
async fn migration_from_remote() {
let config = build_test_config("../../examples/spawn-and-move/Scarb.toml").unwrap();
let config = build_test_config("../../../examples/spawn-and-move/Scarb.toml").unwrap();
let ws = ops::read_workspace(config.manifest_path(), &config)
.unwrap_or_else(|op| panic!("Error building workspace: {op:?}"));
let target_dir =
Utf8PathBuf::from_path_buf("../../examples/spawn-and-move/target/dev".into()).unwrap();
Utf8PathBuf::from_path_buf("../../../examples/spawn-and-move/target/dev".into()).unwrap();

let sequencer =
TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use utils::stdout::expected_stdout;

#[test]
fn test_invalid_cairo_version() {
let path = fs::canonicalize("./tests/test_data/invalid_cairo_version");
let path = fs::canonicalize("./ops/tests/test_data/invalid_cairo_version");
let assert = get_snapbox().arg("build").current_dir(path.unwrap()).assert().failure();
assert.stdout_eq(expected_stdout("wrong-cairo-version"));
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions crates/torii/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tokio = { version = "1.32.0", features = [ "sync" ], default-features = true }
tokio-stream = "0.1.11"
tokio-util = "0.7.7"
tracing.workspace = true
sozo-ops.workspace = true

[dev-dependencies]
camino.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/core/src/sql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dojo_test_utils::sequencer::{
use dojo_world::contracts::world::WorldContractReader;
use dojo_world::migration::strategy::MigrationStrategy;
use scarb::ops;
use sozo::ops::migration::execute_strategy;
use sozo_ops::migration::execute_strategy;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use starknet::core::types::{BlockId, BlockTag, Event, FieldElement};
use starknet::providers::jsonrpc::HttpTransport;
Expand Down
1 change: 1 addition & 0 deletions crates/torii/graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ torii-core = { path = "../core" }
tracing.workspace = true
url.workspace = true
warp.workspace = true
sozo-ops.workspace = true

[dev-dependencies]
camino.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use dojo_world::utils::TransactionWaiter;
use scarb::ops;
use serde::Deserialize;
use serde_json::Value;
use sozo::ops::migration::execute_strategy;
use sozo_ops::migration::execute_strategy;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::SqlitePool;
use starknet::accounts::{Account, Call};
Expand Down

0 comments on commit 1d1451d

Please sign in to comment.