Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed Jul 31, 2024
1 parent a6e4bb5 commit 30d200d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 51 deletions.
5 changes: 3 additions & 2 deletions crates/dojo-test-utils/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn prepare_migration_with_world_and_seed(
world_address: Option<Felt>,
seed: &str,
default_namespace: &str,
) -> Result<MigrationStrategy> {
) -> Result<(MigrationStrategy, WorldDiff)> {
// In testing, profile name is always dev.
let profile_name = "dev";

Expand All @@ -63,5 +63,6 @@ pub fn prepare_migration_with_world_and_seed(
let world = WorldDiff::compute(manifest, None, default_namespace)?;

let seed = cairo_short_string_to_felt(seed).unwrap();
prepare_for_migration(world_address, seed, &target_dir, world)
let strat = prepare_for_migration(world_address, seed, &target_dir, world.clone())?;
Ok((strat, world))
}
6 changes: 3 additions & 3 deletions crates/dojo-world/src/manifest/manifest_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn parse_deployed_contracts_events_without_upgrade() {
build_deploy_event(vec![felt!("0x0"), felt!("0x3"), felt!("0x789")], "ns3", "c3"),
];

let actual_contracts = parse_contracts_events(events, vec![]);
let actual_contracts = parse_contracts_events(events, vec![], vec![]);
assert_eq!(actual_contracts, expected_contracts);
}

Expand Down Expand Up @@ -213,7 +213,7 @@ fn parse_deployed_contracts_events_with_upgrade() {
},
];

let actual_contracts = parse_contracts_events(deployed_events, upgrade_events);
let actual_contracts = parse_contracts_events(deployed_events, upgrade_events, vec![]);
similar_asserts::assert_eq!(actual_contracts, expected_contracts);
}

Expand Down Expand Up @@ -293,7 +293,7 @@ fn events_without_block_number_arent_parsed() {
},
];

let actual_contracts = parse_contracts_events(deployed_events, upgrade_events);
let actual_contracts = parse_contracts_events(deployed_events, upgrade_events, vec![]);
similar_asserts::assert_eq!(actual_contracts, expected_contracts);
}

Expand Down
7 changes: 0 additions & 7 deletions crates/dojo-world/src/manifest/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ pub struct DeploymentManifest {
pub models: Vec<Manifest<DojoModel>>,
}

// bool represents authorization has been done for that contract
// #[derive(Default, Clone, Debug, Serialize, Deserialize)]
// #[cfg_attr(test, derive(PartialEq))]
// pub struct DeploymentMetadata {
// pub world_metadata: bool,
// }

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct OverlayManifest {
Expand Down
1 change: 0 additions & 1 deletion crates/dojo-world/src/migration/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ pub fn prepare_for_migration(
}

// If world address is not provided, then we expect the world to be migrated.
// TODO: see if there are any case where world_address is not provided and `world` is none
let world_address = world_address.unwrap_or_else(|| world.as_ref().unwrap().contract_address);

let mut migration =
Expand Down
8 changes: 4 additions & 4 deletions crates/sozo/ops/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl FromStr for ResourceOwner {
pub async fn grant_writer<'a, A>(
ui: &'a Ui,
world: &WorldContract<A>,
new_writers: &Vec<ResourceWriter>,
new_writers: &[ResourceWriter],
txn_config: TxnConfig,
default_namespace: &str,
) -> Result<()>
Expand Down Expand Up @@ -149,7 +149,7 @@ where
pub async fn grant_owner<A>(
ui: &Ui,
world: &WorldContract<A>,
new_owners: &Vec<ResourceOwner>,
new_owners: &[ResourceOwner],
txn_config: TxnConfig,
default_namespace: &str,
) -> Result<()>
Expand Down Expand Up @@ -187,7 +187,7 @@ where
pub async fn revoke_writer<A>(
ui: &Ui,
world: &WorldContract<A>,
new_writers: &Vec<ResourceWriter>,
new_writers: &[ResourceWriter],
txn_config: TxnConfig,
default_namespace: &str,
) -> Result<()>
Expand Down Expand Up @@ -228,7 +228,7 @@ where
pub async fn revoke_owner<A>(
ui: &Ui,
world: &WorldContract<A>,
new_owners: &Vec<ResourceOwner>,
new_owners: &[ResourceOwner],
txn_config: TxnConfig,
default_namespace: &str,
) -> Result<()>
Expand Down
5 changes: 3 additions & 2 deletions crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ mod ui;
mod utils;

pub use self::auto_auth::auto_authorize;
use self::migrate::update_manifests_and_abis;
pub use self::migrate::{
apply_diff, execute_strategy, prepare_migration, print_strategy, upload_metadata,
apply_diff, execute_strategy, find_authorization_diff, prepare_migration, print_strategy,
upload_metadata,
};
use self::migrate::{find_authorization_diff, update_manifests_and_abis};
use self::ui::MigrationUi;

#[derive(Debug, Default, Clone)]
Expand Down
12 changes: 6 additions & 6 deletions crates/sozo/ops/src/tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn auth_grant_writer_ok() {
auth::grant_writer(
&Ui::new(Verbosity::Normal, OutputFormat::Text),
&world,
vec![moves_mc, position_mc],
&[moves_mc, position_mc],
TxnConfig { wait: true, ..Default::default() },
DEFAULT_NAMESPACE,
)
Expand Down Expand Up @@ -86,7 +86,7 @@ async fn auth_revoke_writer_ok() {
auth::grant_writer(
&Ui::new(Verbosity::Normal, OutputFormat::Text),
&world,
vec![moves_mc.clone(), position_mc.clone()],
&[moves_mc.clone(), position_mc.clone()],
TxnConfig { wait: true, ..Default::default() },
DEFAULT_NAMESPACE,
)
Expand All @@ -100,7 +100,7 @@ async fn auth_revoke_writer_ok() {
auth::revoke_writer(
&Ui::new(Verbosity::Normal, OutputFormat::Text),
&world,
vec![moves_mc, position_mc],
&[moves_mc, position_mc],
TxnConfig { wait: true, ..Default::default() },
DEFAULT_NAMESPACE,
)
Expand Down Expand Up @@ -141,7 +141,7 @@ async fn auth_grant_owner_ok() {
auth::grant_owner(
&Ui::new(Verbosity::Normal, OutputFormat::Text),
&world,
vec![moves, position],
&[moves, position],
TxnConfig { wait: true, ..Default::default() },
DEFAULT_NAMESPACE,
)
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn auth_revoke_owner_ok() {
auth::grant_owner(
&Ui::new(Verbosity::Normal, OutputFormat::Text),
&world,
vec![moves.clone(), position.clone()],
&[moves.clone(), position.clone()],
TxnConfig { wait: true, ..Default::default() },
DEFAULT_NAMESPACE,
)
Expand All @@ -193,7 +193,7 @@ async fn auth_revoke_owner_ok() {
auth::revoke_owner(
&Ui::new(Verbosity::Normal, OutputFormat::Text),
&world,
vec![moves, position],
&[moves, position],
TxnConfig { wait: true, ..Default::default() },
DEFAULT_NAMESPACE,
)
Expand Down
41 changes: 21 additions & 20 deletions crates/sozo/ops/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use starknet::providers::JsonRpcClient;

use super::setup;
use crate::migration::{
auto_authorize, execute_strategy, update_deployment_metadata, upload_metadata,
auto_authorize, execute_strategy, find_authorization_diff, upload_metadata,
};
use crate::utils::get_contract_address_from_reader;

Expand Down Expand Up @@ -60,7 +60,7 @@ async fn migrate_with_auto_mine() {
let config = setup::load_config();
let ws = setup::setup_ws(&config);

let migration = setup::setup_migration(&config).unwrap();
let (migration, _) = setup::setup_migration(&config).unwrap();

let sequencer = KatanaRunner::new().expect("Fail to start runner");

Expand All @@ -75,7 +75,7 @@ async fn migrate_with_block_time() {
let config = setup::load_config();
let ws = setup::setup_ws(&config);

let migration = setup::setup_migration(&config).unwrap();
let (migration, _) = setup::setup_migration(&config).unwrap();

let sequencer = KatanaRunner::new_with_config(KatanaRunnerConfig {
block_time: Some(1000),
Expand All @@ -95,7 +95,7 @@ async fn migrate_with_small_fee_multiplier_will_fail() {
let config = setup::load_config();
let ws = setup::setup_ws(&config);

let migration = setup::setup_migration(&config).unwrap();
let (migration, _) = setup::setup_migration(&config).unwrap();

let sequencer = KatanaRunner::new_with_config(KatanaRunnerConfig {
disable_fee: true,
Expand All @@ -105,16 +105,14 @@ async fn migrate_with_small_fee_multiplier_will_fail() {

let account = sequencer.account(0);

assert!(
execute_strategy(
&ws,
&migration,
&account,
TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default() },
)
.await
.is_err()
);
assert!(execute_strategy(
&ws,
&migration,
&account,
TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default() },
)
.await
.is_err());
}

#[tokio::test]
Expand Down Expand Up @@ -277,7 +275,7 @@ async fn migrate_with_metadata() {
let config = setup::load_config();
let ws = setup::setup_ws(&config);

let migration = setup::setup_migration(&config).unwrap();
let (migration, _) = setup::setup_migration(&config).unwrap();

let sequencer = KatanaRunner::new().expect("Fail to start runner");

Expand Down Expand Up @@ -350,7 +348,7 @@ async fn migrate_with_auto_authorize() {
let config = setup::load_config();
let ws = setup::setup_ws(&config);

let migration = setup::setup_migration(&config).unwrap();
let (migration, diff) = setup::setup_migration(&config).unwrap();

let manifest_base = config.manifest_path().parent().unwrap();
let mut manifest =
Expand All @@ -375,10 +373,13 @@ async fn migrate_with_auto_authorize() {
let world_address = migration.world_address;
let world = WorldContract::new(world_address, account);

let work =
update_deployment_metadata(&manifest_base.to_path_buf(), &manifest, Some(&output)).unwrap();
let default_namespace = get_default_namespace_from_ws(&ws).unwrap();
let res = auto_authorize(&ws, &world, &txn_config, &manifest, &default_namespace, &work).await;
let (grant, revoke) =
find_authorization_diff(&config.ui(), &world, &diff, Some(&output), &default_namespace)
.await
.unwrap();

let res = auto_authorize(&ws, &world, &txn_config, &default_namespace, &grant, &revoke).await;
assert!(res.is_ok());

let provider = sequencer.provider();
Expand Down Expand Up @@ -411,7 +412,7 @@ async fn migration_with_mismatching_world_address_and_seed() {

let default_namespace = get_default_namespace_from_ws(&ws).unwrap();

let strategy = prepare_migration_with_world_and_seed(
let (strategy, _) = prepare_migration_with_world_and_seed(
base_dir,
target_dir,
Some(Felt::ONE),
Expand Down
6 changes: 4 additions & 2 deletions crates/sozo/ops/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use dojo_test_utils::migration::prepare_migration_with_world_and_seed;
use dojo_world::contracts::world::WorldContract;
use dojo_world::metadata::get_default_namespace_from_ws;
use dojo_world::migration::strategy::MigrationStrategy;
use dojo_world::migration::world::WorldDiff;
use dojo_world::migration::TxnConfig;
use katana_runner::KatanaRunner;
use scarb::compiler::Profile;
Expand Down Expand Up @@ -49,7 +50,7 @@ pub fn setup_ws(config: &Config) -> Workspace<'_> {
/// # Returns
///
/// A [`MigrationStrategy`] to execute to migrate the full spawn-and-moves project.
pub fn setup_migration(config: &Config) -> Result<MigrationStrategy> {
pub fn setup_migration(config: &Config) -> Result<(MigrationStrategy, WorldDiff)> {
let ws = setup_ws(config);

let manifest_path = config.manifest_path();
Expand Down Expand Up @@ -83,7 +84,7 @@ pub async fn setup(
let config = load_config();
let ws = setup_ws(&config);

let migration = setup_migration(&config)?;
let (migration, _) = setup_migration(&config)?;

let mut account = sequencer.account(0);
account.set_block_id(BlockId::Tag(BlockTag::Pending));
Expand All @@ -95,6 +96,7 @@ pub async fn setup(
TxnConfig { wait: true, ..Default::default() },
)
.await?;
// TODO: do we need to do authorization in setup?
let world = WorldContract::new(output.world_address, account)
.with_block(BlockId::Tag(BlockTag::Pending));

Expand Down
9 changes: 6 additions & 3 deletions crates/torii/core/src/sql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn test_load_from_remote() {
&ws,
None,
sequencer.url().to_string(),
&account,
account,
"dojo_examples",
false,
TxnConfig::init_wait(),
Expand All @@ -82,6 +82,7 @@ async fn test_load_from_remote() {
.unwrap()
.unwrap();

let account = sequencer.account(0);
// spawn
let tx = &account
.execute_v1(vec![Call {
Expand Down Expand Up @@ -204,7 +205,7 @@ async fn test_load_from_remote_del() {
&ws,
None,
sequencer.url().to_string(),
&account,
account,
"dojo_examples",
false,
TxnConfig::init_wait(),
Expand All @@ -214,6 +215,7 @@ async fn test_load_from_remote_del() {
.unwrap()
.unwrap();

let account = sequencer.account(0);
// spawn
account
.execute_v1(vec![Call {
Expand Down Expand Up @@ -316,7 +318,7 @@ async fn test_get_entity_keys() {
&ws,
None,
sequencer.url().to_string(),
&account,
account,
"dojo_examples",
false,
TxnConfig::init_wait(),
Expand All @@ -326,6 +328,7 @@ async fn test_get_entity_keys() {
.unwrap()
.unwrap();

let account = sequencer.account(0);
// spawn
account
.execute_v1(vec![Call {
Expand Down
3 changes: 2 additions & 1 deletion crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub async fn spinup_types_test() -> Result<SqlitePool> {
&ws,
None,
sequencer.url().to_string(),
&account,
account,
"types_test",
false,
TxnConfig::init_wait(),
Expand All @@ -295,6 +295,7 @@ pub async fn spinup_types_test() -> Result<SqlitePool> {
.unwrap()
.unwrap();

let account = sequencer.account(0);
// Execute `create` and insert 11 records into storage
let records_contract = migration_output
.contracts
Expand Down

0 comments on commit 30d200d

Please sign in to comment.