diff --git a/bin/sozo/tests/register_test.rs b/bin/sozo/tests/register_test.rs index 4a5c234848..5b5e490571 100644 --- a/bin/sozo/tests/register_test.rs +++ b/bin/sozo/tests/register_test.rs @@ -3,7 +3,7 @@ mod utils; use camino::Utf8PathBuf; use dojo_test_utils::compiler::CompilerTestSetup; use dojo_test_utils::migration::{copy_spawn_and_move_db, prepare_migration_with_world_and_seed}; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb::compiler::Profile; use scarb::ops; use starknet::accounts::Account; @@ -11,7 +11,8 @@ use starknet::core::types::{BlockId, BlockTag}; use utils::snapbox::get_snapbox; #[tokio::test(flavor = "multi_thread")] -async fn reregister_models() { +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +async fn reregister_models(sequencer: &RunnerCtx) { let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/"); let config = setup.build_test_config("spawn-and-move", Profile::DEV); @@ -22,9 +23,6 @@ async fn reregister_models() { let target_path = ws.target_dir().path_existent().unwrap().join(ws.config().profile().to_string()); - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - let (strat, _) = prepare_migration_with_world_and_seed( manifest_path, target_path, diff --git a/bin/sozo/tests/test_migrate.rs b/bin/sozo/tests/test_migrate.rs index b1f672b929..ca55c20dc6 100644 --- a/bin/sozo/tests/test_migrate.rs +++ b/bin/sozo/tests/test_migrate.rs @@ -2,7 +2,7 @@ use std::fs; use dojo_test_utils::compiler::CompilerTestSetup; use dojo_test_utils::migration::copy_spawn_and_move_db; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::{KatanaRunner, RunnerCtx}; use scarb::compiler::Profile; use starknet::accounts::Account; use starknet::core::types::{BlockId, BlockTag}; @@ -51,14 +51,12 @@ async fn migrate_dry_run() { } #[tokio::test(flavor = "multi_thread")] -async fn test_migrate_then_upgrade() { +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +async fn test_migrate_then_upgrade(sequencer: &RunnerCtx) { let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/"); let config = setup.build_test_config("spawn-and-move", Profile::DEV); let tmp_dir = config.manifest_path().parent().unwrap(); - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); diff --git a/crates/dojo-world/src/contracts/model_test.rs b/crates/dojo-world/src/contracts/model_test.rs index 40da5893ad..93a2955025 100644 --- a/crates/dojo-world/src/contracts/model_test.rs +++ b/crates/dojo-world/src/contracts/model_test.rs @@ -3,7 +3,7 @@ use dojo_test_utils::compiler::CompilerTestSetup; use dojo_test_utils::migration::{copy_spawn_and_move_db, prepare_migration_with_world_and_seed}; use dojo_types::primitive::Primitive; use dojo_types::schema::{Enum, EnumOption, Member, Struct, Ty}; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb::compiler::Profile; use starknet::accounts::ConnectedAccount; use starknet::macros::felt; @@ -12,10 +12,8 @@ use crate::contracts::model::ModelReader; use crate::contracts::world::WorldContractReader; #[tokio::test(flavor = "multi_thread")] -async fn test_model() { - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +async fn test_model(sequencer: &RunnerCtx) { let account = sequencer.account(0); let provider = account.provider(); diff --git a/crates/dojo-world/src/contracts/world_test.rs b/crates/dojo-world/src/contracts/world_test.rs index 229746717f..e9a6d8c88f 100644 --- a/crates/dojo-world/src/contracts/world_test.rs +++ b/crates/dojo-world/src/contracts/world_test.rs @@ -1,6 +1,6 @@ use dojo_test_utils::compiler::CompilerTestSetup; use dojo_test_utils::migration::{copy_spawn_and_move_db, prepare_migration_with_world_and_seed}; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb::compiler::Profile; use starknet::accounts::ConnectedAccount; use starknet::core::types::{BlockId, BlockTag}; @@ -8,16 +8,14 @@ use starknet::core::types::{BlockId, BlockTag}; use super::WorldContractReader; #[tokio::test(flavor = "multi_thread")] -async fn test_world_contract_reader() { +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +async fn test_world_contract_reader(sequencer: &RunnerCtx) { let setup = CompilerTestSetup::from_examples("../dojo-core", "../../examples/"); let config = setup.build_test_config("spawn-and-move", Profile::DEV); let manifest_dir = config.manifest_path().parent().unwrap(); let target_dir = manifest_dir.join("target").join("dev"); - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); diff --git a/crates/dojo-world/src/manifest/manifest_test.rs b/crates/dojo-world/src/manifest/manifest_test.rs index ed166325b3..eb66cb326a 100644 --- a/crates/dojo-world/src/manifest/manifest_test.rs +++ b/crates/dojo-world/src/manifest/manifest_test.rs @@ -5,7 +5,7 @@ use camino::Utf8PathBuf; use dojo_test_utils::compiler::CompilerTestSetup; use dojo_test_utils::migration::{copy_spawn_and_move_db, prepare_migration_with_world_and_seed}; use dojo_test_utils::rpc::MockJsonRpcTransport; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb::compiler::Profile; use serde_json::json; use starknet::accounts::ConnectedAccount; @@ -285,11 +285,8 @@ fn events_without_block_number_arent_parsed() { similar_asserts::assert_eq!(actual_contracts, expected_contracts); } -#[test] -fn fetch_remote_manifest() { - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +fn fetch_remote_manifest(sequencer: &RunnerCtx) { let account = sequencer.account(0); let provider = account.provider(); diff --git a/crates/katana/runner/macro/src/config.rs b/crates/katana/runner/macro/src/config.rs index c8a2fc484a..cb6c6b8651 100644 --- a/crates/katana/runner/macro/src/config.rs +++ b/crates/katana/runner/macro/src/config.rs @@ -8,18 +8,16 @@ use crate::utils::{parse_bool, parse_int, parse_path, parse_string}; pub const DEFAULT_ERROR_CONFIG: Configuration = Configuration::new(false); -/// Partial configuration for extracting the individual configuration values from the attribute -/// arguments. pub struct Configuration { pub crate_name: Option, pub dev: bool, pub is_test: bool, - pub accounts: Option, - pub fee: Option, - pub validation: Option, - pub db_dir: Option, - pub block_time: Option, - pub log_path: Option, + pub accounts: Option, + pub fee: Option, + pub validation: Option, + pub db_dir: Option, + pub block_time: Option, + pub log_path: Option, } impl Configuration { @@ -48,77 +46,63 @@ impl Configuration { let name_path = parse_path(name, span, "crate")?; self.crate_name = Some(name_path); - Ok(()) } - fn set_db_dir(&mut self, db_dir: syn::Lit, span: proc_macro2::Span) -> Result<(), syn::Error> { + fn set_db_dir(&mut self, db_dir: syn::Expr, span: proc_macro2::Span) -> Result<(), syn::Error> { if self.db_dir.is_some() { return Err(syn::Error::new(span, "`db_dir` set multiple times.")); } - let db_dir = parse_string(db_dir, span, "db_dir")?; self.db_dir = Some(db_dir); - Ok(()) } - fn set_fee(&mut self, fee: syn::Lit, span: proc_macro2::Span) -> Result<(), syn::Error> { + fn set_fee(&mut self, fee: syn::Expr, span: proc_macro2::Span) -> Result<(), syn::Error> { if self.fee.is_some() { return Err(syn::Error::new(span, "`fee` set multiple times.")); } - let fee = parse_bool(fee, span, "fee")?; self.fee = Some(fee); - Ok(()) } fn set_validation( &mut self, - validation: syn::Lit, + validation: syn::Expr, span: proc_macro2::Span, ) -> Result<(), syn::Error> { if self.validation.is_some() { return Err(syn::Error::new(span, "`validation` set multiple times.")); } - let validation = parse_bool(validation, span, "validation")?; self.validation = Some(validation); - Ok(()) } fn set_block_time( &mut self, - block_time: syn::Lit, + block_time: syn::Expr, span: proc_macro2::Span, ) -> Result<(), syn::Error> { if self.block_time.is_some() { return Err(syn::Error::new(span, "`block_time` set multiple times.")); } - let block_time = parse_int(block_time, span, "block_time")? as u64; self.block_time = Some(block_time); - Ok(()) } fn set_accounts( &mut self, - accounts: syn::Lit, + accounts: syn::Expr, span: proc_macro2::Span, ) -> Result<(), syn::Error> { if self.accounts.is_some() { return Err(syn::Error::new(span, "`accounts` set multiple times.")); } - let int = parse_int(accounts, span, "accounts")?; - let accounts = u16::try_from(int) - .map_err(|_| syn::Error::new(span, "`accounts` must be a valid u16."))?; - self.accounts = Some(accounts); - Ok(()) } } @@ -168,30 +152,28 @@ pub fn build_config( .to_string() .to_lowercase(); - // the value of the attribute - let lit = match &namevalue.value { - syn::Expr::Lit(syn::ExprLit { lit, .. }) => lit, - expr => return Err(syn::Error::new_spanned(expr, "Must be a literal")), - }; - // the ident of the attribute let ident = ident.as_str(); let arg = RunnerArg::from_str(ident) .map_err(|err| syn::Error::new_spanned(&namevalue, err))?; + let expr = &namevalue.value; + match arg { RunnerArg::BlockTime => { - config.set_block_time(lit.clone(), Spanned::span(lit))? + config.set_block_time(expr.clone(), Spanned::span(&namevalue))? } RunnerArg::Validation => { - config.set_validation(lit.clone(), Spanned::span(lit))? + config.set_validation(expr.clone(), Spanned::span(&namevalue))? } RunnerArg::Accounts => { - config.set_accounts(lit.clone(), Spanned::span(lit))?; + config.set_accounts(expr.clone(), Spanned::span(&namevalue))?; + } + RunnerArg::DbDir => { + config.set_db_dir(expr.clone(), Spanned::span(&namevalue))? } - RunnerArg::Fee => config.set_fee(lit.clone(), Spanned::span(lit))?, - RunnerArg::DbDir => config.set_db_dir(lit.clone(), Spanned::span(lit))?, + RunnerArg::Fee => config.set_fee(expr.clone(), Spanned::span(&namevalue))?, } } diff --git a/crates/katana/runner/macro/src/entry.rs b/crates/katana/runner/macro/src/entry.rs index e233ffb1da..6311fbdf52 100644 --- a/crates/katana/runner/macro/src/entry.rs +++ b/crates/katana/runner/macro/src/entry.rs @@ -66,7 +66,7 @@ pub fn parse_knobs(input: ItemFn, is_test: bool, config: Configuration) -> Token } if let Some(value) = config.db_dir { - cfg = quote_spanned! (last_stmt_start_span=> #cfg db_dir: Some(std::path::PathBuf::from(#value)), ); + cfg = quote_spanned! (last_stmt_start_span=> #cfg db_dir: Some(core::str::FromStr::from_str(#value).expect("valid path")), ); } if let Some(value) = config.accounts { diff --git a/crates/katana/runner/tests/runner.rs b/crates/katana/runner/tests/runner.rs index 55586399fe..dcec61acd1 100644 --- a/crates/katana/runner/tests/runner.rs +++ b/crates/katana/runner/tests/runner.rs @@ -11,7 +11,7 @@ fn with_return(_: &RunnerCtx) -> Result<(), Box> { Ok(()) } -#[tokio::test] +#[tokio::test(flavor = "current_thread")] #[katana_runner::test] async fn with_async(ctx: &RunnerCtx) -> Result<(), Box> { let provider = ctx.provider(); diff --git a/crates/sozo/ops/src/tests/auth.rs b/crates/sozo/ops/src/tests/auth.rs index 38aaf0ee4b..4619fbb19d 100644 --- a/crates/sozo/ops/src/tests/auth.rs +++ b/crates/sozo/ops/src/tests/auth.rs @@ -4,7 +4,7 @@ use dojo_test_utils::migration::copy_spawn_and_move_db; use dojo_utils::TxnConfig; use dojo_world::contracts::naming::compute_selector_from_tag; use dojo_world::contracts::world::WorldContract; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb_ui::{OutputFormat, Ui, Verbosity}; use starknet::accounts::{Account, ConnectedAccount}; use starknet::core::types::Felt; @@ -49,13 +49,9 @@ fn get_resource_owners(owner: Felt) -> [ResourceOwner; 2] { } #[tokio::test(flavor = "multi_thread")] -async fn auth_grant_writer_ok() { - let config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn auth_grant_writer_ok(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); // Overlays already have the writer set up. But running again to ensure we don't // actually revert something with this call. @@ -77,13 +73,9 @@ async fn auth_grant_writer_ok() { } #[tokio::test(flavor = "multi_thread")] -async fn auth_revoke_writer_ok() { - let config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn auth_revoke_writer_ok(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); auth::grant_writer( &Ui::new(Verbosity::Normal, OutputFormat::Text), @@ -116,17 +108,14 @@ async fn auth_revoke_writer_ok() { } #[tokio::test(flavor = "multi_thread")] -async fn auth_grant_owner_ok() { +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn auth_grant_owner_ok(sequencer: &RunnerCtx) { let move_model_selector = compute_selector_from_tag(MOVE_MODEL_TAG); let position_model_selector = compute_selector_from_tag(POSITION_MODEL_TAG); - let config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); println!("sequencer logs: {:?}", sequencer.log_file_path()); - let world = setup::setup_with_world(&sequencer).await.unwrap(); + let world = setup::setup_with_world(sequencer).await.unwrap(); let default_account = sequencer.account(0).address(); let other_account = sequencer.account(1).address(); @@ -155,16 +144,12 @@ async fn auth_grant_owner_ok() { } #[tokio::test(flavor = "multi_thread")] -async fn auth_revoke_owner_ok() { +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn auth_revoke_owner_ok(sequencer: &RunnerCtx) { let move_model_selector = compute_selector_from_tag(MOVE_MODEL_TAG); let position_model_selector = compute_selector_from_tag(POSITION_MODEL_TAG); - let config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); + let world = setup::setup_with_world(sequencer).await.unwrap(); let default_account = sequencer.account(0).address(); diff --git a/crates/sozo/ops/src/tests/call.rs b/crates/sozo/ops/src/tests/call.rs index f477c64814..155f46e9a3 100644 --- a/crates/sozo/ops/src/tests/call.rs +++ b/crates/sozo/ops/src/tests/call.rs @@ -1,5 +1,5 @@ use dojo_world::contracts::WorldContractReader; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb_ui::Ui; use starknet::accounts::SingleOwnerAccount; use starknet::core::types::Felt; @@ -14,11 +14,9 @@ const CONTRACT_TAG: &str = "dojo_examples-actions"; const ENTRYPOINT: &str = "get_player_position"; #[tokio::test] -async fn call_with_bad_address() { - let config = KatanaRunnerConfig::default().with_db_dir("/tmp/spawn-and-move-db"); - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(db_dir = "/tmp/spawn-and-move-db")] +async fn call_with_bad_address(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); @@ -39,11 +37,9 @@ async fn call_with_bad_address() { } #[tokio::test] -async fn call_with_bad_name() { - let config = KatanaRunnerConfig::default().with_db_dir("/tmp/spawn-and-move-db"); - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(db_dir = "/tmp/spawn-and-move-db")] +async fn call_with_bad_name(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); @@ -64,11 +60,9 @@ async fn call_with_bad_name() { } #[tokio::test] -async fn call_with_bad_entrypoint() { - let config = KatanaRunnerConfig::default().with_db_dir("/tmp/spawn-and-move-db"); - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(db_dir = "/tmp/spawn-and-move-db")] +async fn call_with_bad_entrypoint(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); @@ -89,11 +83,9 @@ async fn call_with_bad_entrypoint() { } #[tokio::test] -async fn call_with_bad_calldata() { - let config = KatanaRunnerConfig::default().with_db_dir("/tmp/spawn-and-move-db"); - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(db_dir = "/tmp/spawn-and-move-db")] +async fn call_with_bad_calldata(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); @@ -114,11 +106,9 @@ async fn call_with_bad_calldata() { } #[tokio::test] -async fn call_with_contract_name() { - let config = KatanaRunnerConfig::default().with_db_dir("/tmp/spawn-and-move-db"); - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(db_dir = "/tmp/spawn-and-move-db")] +async fn call_with_contract_name(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); @@ -138,13 +128,11 @@ async fn call_with_contract_name() { } #[tokio::test] -async fn call_with_contract_address() { - let config = KatanaRunnerConfig::default().with_db_dir("/tmp/spawn-and-move-db"); - let sequencer = KatanaRunner::new_with_config(config).expect("Failed to start runner."); - +#[katana_runner::test(db_dir = "/tmp/spawn-and-move-db")] +async fn call_with_contract_address(sequencer: &RunnerCtx) { let ui = Ui::new(scarb_ui::Verbosity::Verbose, scarb_ui::OutputFormat::Text); - let world = setup::setup_with_world(&sequencer).await.unwrap(); + let world = setup::setup_with_world(sequencer).await.unwrap(); let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); diff --git a/crates/sozo/ops/src/tests/migration.rs b/crates/sozo/ops/src/tests/migration.rs index 8dac034b65..cdfa44d93b 100644 --- a/crates/sozo/ops/src/tests/migration.rs +++ b/crates/sozo/ops/src/tests/migration.rs @@ -20,7 +20,7 @@ use dojo_world::migration::world::WorldDiff; use dojo_world::uri::Uri; use futures::TryStreamExt; use ipfs_api_backend_hyper::{HyperBackend, IpfsApi, IpfsClient, TryFromUri}; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use starknet::core::types::{BlockId, BlockTag, Felt}; use starknet::macros::felt; use starknet::providers::jsonrpc::HttpTransport; @@ -34,17 +34,11 @@ use crate::test_utils::setup; use crate::utils::get_contract_address_from_reader; #[tokio::test(flavor = "multi_thread")] -async fn default_migrate_no_dry_run() { +#[katana_runner::test(accounts = 10)] +async fn default_migrate_no_dry_run(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); - let sequencer = KatanaRunner::new_with_config(KatanaRunnerConfig { - n_accounts: 10, - dev: true, - ..Default::default() - }) - .expect("Fail to start runner"); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); @@ -63,48 +57,39 @@ async fn default_migrate_no_dry_run() { } #[tokio::test(flavor = "multi_thread")] -async fn migrate_with_auto_mine() { +#[katana_runner::test(accounts = 10)] +async fn migrate_with_auto_mine(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); let (migration, _) = setup::setup_migration(&config, "dojo_examples").unwrap(); - let sequencer = - KatanaRunner::new_with_config(KatanaRunnerConfig { n_accounts: 10, ..Default::default() }) - .expect("Fail to start runner"); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); - let declarers = setup::get_declarers_from_sequencer(&sequencer).await; + let declarers = setup::get_declarers_from_sequencer(sequencer).await; execute_strategy(&ws, &migration, &account, TxnConfig::init_wait(), &declarers).await.unwrap(); } #[tokio::test(flavor = "multi_thread")] -async fn migrate_with_block_time() { +#[katana_runner::test(accounts = 10, block_time = 1000)] +async fn migrate_with_block_time(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); let (migration, _) = setup::setup_migration(&config, "dojo_examples").unwrap(); - let sequencer = KatanaRunner::new_with_config(KatanaRunnerConfig { - n_accounts: 10, - block_time: Some(1000), - ..Default::default() - }) - .expect("Fail to start runner"); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); - let declarers = setup::get_declarers_from_sequencer(&sequencer).await; + let declarers = setup::get_declarers_from_sequencer(sequencer).await; execute_strategy(&ws, &migration, &account, TxnConfig::default(), &declarers).await.unwrap(); } -#[tokio::test] -async fn metadata_calculated_properly() { +#[test] +fn metadata_calculated_properly() { let config = setup::load_config(); let ws = setup::setup_ws(&config); @@ -145,17 +130,14 @@ async fn metadata_calculated_properly() { } #[tokio::test] -async fn migration_with_correct_calldata_second_time_work_as_expected() { +#[katana_runner::test(accounts = 10)] +async fn migration_with_correct_calldata_second_time_work_as_expected(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); let base = config.manifest_path().parent().unwrap(); let target_dir = format!("{}/target/dev", base); - let sequencer = - KatanaRunner::new_with_config(KatanaRunnerConfig { n_accounts: 10, ..Default::default() }) - .expect("Failed to start runner."); - let account = sequencer.account(0); let profile_name = ws.current_profile().unwrap().to_string(); @@ -175,7 +157,7 @@ async fn migration_with_correct_calldata_second_time_work_as_expected() { ) .unwrap(); - let declarers = setup::get_declarers_from_sequencer(&sequencer).await; + let declarers = setup::get_declarers_from_sequencer(sequencer).await; let migration_output = execute_strategy(&ws, &migration, &account, TxnConfig::init_wait(), &declarers) @@ -218,17 +200,14 @@ async fn migration_with_correct_calldata_second_time_work_as_expected() { } #[tokio::test] -async fn migration_from_remote() { +#[katana_runner::test(accounts = 10)] +async fn migration_from_remote(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); let base = config.manifest_path().parent().unwrap(); let target_dir = format!("{}/target/dev", base); - let sequencer = - KatanaRunner::new_with_config(KatanaRunnerConfig { n_accounts: 10, ..Default::default() }) - .expect("Failed to start runner."); - let account = sequencer.account(0); let profile_name = ws.current_profile().unwrap().to_string(); @@ -248,7 +227,7 @@ async fn migration_from_remote() { ) .unwrap(); - let declarers = setup::get_declarers_from_sequencer(&sequencer).await; + let declarers = setup::get_declarers_from_sequencer(sequencer).await; execute_strategy(&ws, &migration, &account, TxnConfig::init_wait(), &declarers).await.unwrap(); @@ -269,20 +248,17 @@ async fn migration_from_remote() { } #[tokio::test(flavor = "multi_thread")] -async fn migrate_with_metadata() { +#[katana_runner::test(accounts = 10)] +async fn migrate_with_metadata(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); let (migration, _) = setup::setup_migration(&config, "dojo_examples").unwrap(); - let sequencer = - KatanaRunner::new_with_config(KatanaRunnerConfig { n_accounts: 10, ..Default::default() }) - .expect("Failed to start runner."); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); - let declarers = setup::get_declarers_from_sequencer(&sequencer).await; + let declarers = setup::get_declarers_from_sequencer(sequencer).await; let output = execute_strategy(&ws, &migration, &account, TxnConfig::init_wait(), &declarers) .await @@ -348,7 +324,8 @@ async fn migrate_with_metadata() { } #[tokio::test(flavor = "multi_thread")] -async fn migrate_with_auto_authorize() { +#[katana_runner::test(accounts = 10)] +async fn migrate_with_auto_authorize(sequencer: &RunnerCtx) { let config = setup::load_config(); let ws = setup::setup_ws(&config); @@ -365,16 +342,12 @@ async fn migrate_with_auto_authorize() { manifest.merge(overlay_manifest); } - let sequencer = - KatanaRunner::new_with_config(KatanaRunnerConfig { n_accounts: 10, ..Default::default() }) - .expect("Failed to start runner."); - let mut account = sequencer.account(0); account.set_block_id(BlockId::Tag(BlockTag::Pending)); let txn_config = TxnConfig::init_wait(); - let declarers = setup::get_declarers_from_sequencer(&sequencer).await; + let declarers = setup::get_declarers_from_sequencer(sequencer).await; let output = execute_strategy(&ws, &migration, &account, txn_config, &declarers).await.unwrap(); @@ -428,8 +401,8 @@ async fn migrate_with_auto_authorize() { } } -#[tokio::test(flavor = "multi_thread")] -async fn migration_with_mismatching_world_address_and_seed() { +#[test] +fn migration_with_mismatching_world_address_and_seed() { let config = setup::load_config(); let ws = setup::setup_ws(&config); diff --git a/crates/sozo/ops/src/tests/model.rs b/crates/sozo/ops/src/tests/model.rs index 4e44973261..fc84a9cfce 100644 --- a/crates/sozo/ops/src/tests/model.rs +++ b/crates/sozo/ops/src/tests/model.rs @@ -4,7 +4,7 @@ use dojo_world::contracts::abi::model::{FieldLayout, Layout}; use dojo_world::contracts::abi::world::Resource; use dojo_world::contracts::naming::{compute_bytearray_hash, compute_selector_from_tag}; use dojo_world::contracts::world::WorldContract; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb_ui::{OutputFormat, Ui, Verbosity}; use starknet::accounts::Account; use starknet::core::types::Felt; @@ -15,13 +15,9 @@ use crate::{execute, model}; // Test model ops in the same to avoid spinning up several katana with full // migration for now. Should be replaced by individual tests once Katana spinning up is enhanced. #[tokio::test(flavor = "multi_thread")] -async fn test_model_ops() { - let seq_config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn test_model_ops(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let action_address = if let Resource::Contract((_, address)) = world.resource(&compute_selector_from_tag("dojo_examples-actions")).call().await.unwrap() @@ -192,8 +188,8 @@ async fn test_model_ops() { assert_eq!(values, expected_values); } -#[tokio::test(flavor = "multi_thread")] -async fn test_check_tag_or_read_default() { +#[test] +fn test_check_tag_or_read_default() { let config = setup::load_config(); let tag = model::check_tag_or_read_default_namespace("Moves", &config).unwrap(); diff --git a/crates/sozo/ops/src/tests/utils.rs b/crates/sozo/ops/src/tests/utils.rs index 8247ee55a3..53ca807818 100644 --- a/crates/sozo/ops/src/tests/utils.rs +++ b/crates/sozo/ops/src/tests/utils.rs @@ -1,7 +1,7 @@ use dojo_test_utils::migration::copy_spawn_and_move_db; use dojo_world::contracts::world::WorldContract; use dojo_world::contracts::WorldContractReader; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use starknet::accounts::ConnectedAccount; use starknet::core::types::{BlockId, BlockTag, Felt}; @@ -11,35 +11,26 @@ use crate::utils; const ACTION_CONTRACT_TAG: &str = "dojo_examples-actions"; #[tokio::test(flavor = "multi_thread")] -async fn get_contract_address_from_world() { - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); - +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +async fn get_contract_address_from_world(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let contract_address = utils::get_contract_address(&world, ACTION_CONTRACT_TAG).await.unwrap(); - assert!(contract_address != Felt::ZERO); } #[tokio::test(flavor = "multi_thread")] -async fn get_contract_address_from_string() { - let sequencer = KatanaRunner::new().expect("Failed to start runner."); - +#[katana_runner::test] +async fn get_contract_address_from_string(sequencer: &RunnerCtx) { let account = sequencer.account(0); let world = WorldContract::new(Felt::ZERO, account); - let contract_address = utils::get_contract_address(&world, "0x1234").await.unwrap(); - assert_eq!(contract_address, Felt::from_hex("0x1234").unwrap()); } #[tokio::test(flavor = "multi_thread")] -async fn get_contract_address_from_world_with_world_reader() { - let seq_config = KatanaRunnerConfig::default().with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - - let world = setup::setup_with_world(&sequencer).await.unwrap(); +#[katana_runner::test(db_dir = copy_spawn_and_move_db().as_str())] +async fn get_contract_address_from_world_with_world_reader(sequencer: &RunnerCtx) { + let world = setup::setup_with_world(sequencer).await.unwrap(); let account = sequencer.account(0); let provider = account.provider(); let world_reader = WorldContractReader::new(world.address, provider); @@ -53,9 +44,8 @@ async fn get_contract_address_from_world_with_world_reader() { } #[tokio::test(flavor = "multi_thread")] -async fn get_contract_address_from_string_with_world_reader() { - let sequencer = KatanaRunner::new().expect("Failed to start runner."); - +#[katana_runner::test] +async fn get_contract_address_from_string_with_world_reader(sequencer: &RunnerCtx) { let account = sequencer.account(0); let provider = account.provider(); let world_reader = WorldContractReader::new(Felt::ZERO, provider); diff --git a/crates/torii/core/src/sql_test.rs b/crates/torii/core/src/sql_test.rs index b60ea3de36..f31cacbb66 100644 --- a/crates/torii/core/src/sql_test.rs +++ b/crates/torii/core/src/sql_test.rs @@ -8,7 +8,7 @@ use dojo_test_utils::migration::{copy_spawn_and_move_db, prepare_migration_with_ use dojo_utils::{TransactionExt, TransactionWaiter, TxnConfig}; use dojo_world::contracts::naming::{compute_bytearray_hash, compute_selector_from_names}; use dojo_world::contracts::world::{WorldContract, WorldContractReader}; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb::compiler::Profile; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; use starknet::accounts::Account; @@ -64,7 +64,8 @@ where } #[tokio::test(flavor = "multi_thread")] -async fn test_load_from_remote() { +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn test_load_from_remote(sequencer: &RunnerCtx) { let options = SqliteConnectOptions::from_str("sqlite::memory:").unwrap().create_if_missing(true); let pool = SqlitePoolOptions::new().max_connections(5).connect_with(options).await.unwrap(); @@ -77,10 +78,6 @@ async fn test_load_from_remote() { let manifest_path = Utf8PathBuf::from(config.manifest_path().parent().unwrap()); let target_dir = Utf8PathBuf::from(ws.target_dir().to_string()).join("dev"); - let seq_config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); let account = sequencer.account(0); let provider = Arc::new(JsonRpcClient::new(HttpTransport::new(sequencer.url()))); @@ -199,7 +196,8 @@ async fn test_load_from_remote() { } #[tokio::test(flavor = "multi_thread")] -async fn test_load_from_remote_del() { +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn test_load_from_remote_del(sequencer: &RunnerCtx) { let options = SqliteConnectOptions::from_str("sqlite::memory:").unwrap().create_if_missing(true); let pool = SqlitePoolOptions::new().max_connections(5).connect_with(options).await.unwrap(); @@ -212,10 +210,6 @@ async fn test_load_from_remote_del() { let manifest_path = Utf8PathBuf::from(config.manifest_path().parent().unwrap()); let target_dir = Utf8PathBuf::from(ws.target_dir().to_string()).join("dev"); - let seq_config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); let account = sequencer.account(0); let provider = Arc::new(JsonRpcClient::new(HttpTransport::new(sequencer.url()))); @@ -301,7 +295,8 @@ async fn test_load_from_remote_del() { } #[tokio::test(flavor = "multi_thread")] -async fn test_update_with_set_record() { +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn test_update_with_set_record(sequencer: &RunnerCtx) { let options = SqliteConnectOptions::from_str("sqlite::memory:").unwrap().create_if_missing(true); let pool = SqlitePoolOptions::new().max_connections(5).connect_with(options).await.unwrap(); @@ -314,10 +309,6 @@ async fn test_update_with_set_record() { let manifest_path = Utf8PathBuf::from(config.manifest_path().parent().unwrap()); let target_dir = Utf8PathBuf::from(ws.target_dir().to_string()).join("dev"); - let seq_config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); - let (strat, _) = prepare_migration_with_world_and_seed( manifest_path, target_dir, diff --git a/crates/torii/grpc/src/server/tests/entities_test.rs b/crates/torii/grpc/src/server/tests/entities_test.rs index ba35e24b8a..0b04574a03 100644 --- a/crates/torii/grpc/src/server/tests/entities_test.rs +++ b/crates/torii/grpc/src/server/tests/entities_test.rs @@ -8,7 +8,7 @@ use dojo_test_utils::migration::{copy_spawn_and_move_db, prepare_migration_with_ use dojo_utils::{TransactionExt, TransactionWaiter, TxnConfig}; use dojo_world::contracts::naming::compute_bytearray_hash; use dojo_world::contracts::{WorldContract, WorldContractReader}; -use katana_runner::{KatanaRunner, KatanaRunnerConfig}; +use katana_runner::RunnerCtx; use scarb::compiler::Profile; use scarb::ops; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; @@ -30,7 +30,8 @@ use crate::server::DojoWorld; use crate::types::schema::Entity; #[tokio::test(flavor = "multi_thread")] -async fn test_entities_queries() { +#[katana_runner::test(accounts = 10, db_dir = copy_spawn_and_move_db().as_str())] +async fn test_entities_queries(sequencer: &RunnerCtx) { let options = SqliteConnectOptions::from_str("sqlite::memory:") .unwrap() .create_if_missing(true) @@ -47,10 +48,6 @@ async fn test_entities_queries() { let manifest_path = Utf8PathBuf::from(config.manifest_path().parent().unwrap()); let target_path = ws.target_dir().path_existent().unwrap().join(config.profile().to_string()); - let seq_config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } - .with_db_dir(copy_spawn_and_move_db().as_str()); - - let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); let account = sequencer.account(0); let (strat, _) = prepare_migration_with_world_and_seed(