Skip to content

Commit

Permalink
tests: fix building with dojo-test-utils + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Jan 16, 2024
1 parent a0b5251 commit f66a75a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 88 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/dojo-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ starknet.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
dojo-test-utils = { path = "../dojo-test-utils", features = [ "build-examples" ] }

cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.2.1" }
170 changes: 83 additions & 87 deletions crates/dojo-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,90 +261,86 @@ fn is_model_contract(tokens: &TokenizedAbi) -> bool {
funcs_counts == expected_funcs.len()
}

// Spawn and move project is not built at the time this lib is being tested.
// Need plain artifacts to simplify or use `sozo` from env (available as we're in the devcontainer).
// #[cfg(test)]
// mod tests {
// use super::*;

// #[test]
// fn is_system_contract_ok() {
// let file_name = "dojo_examples::actions::actions.json";
// let file_content = include_str!(
// "test_data/spawn-and-move/target/dev/dojo_examples::actions::actions.json"
// );

// assert!(is_systems_contract(file_name, file_content));
// }

// #[test]
// fn is_system_contract_ignore_dojo_files() {
// let file_name = "dojo::world::world.json";
// let file_content = "";
// assert!(!is_systems_contract(file_name, file_content));

// let file_name = "manifest.json";
// assert!(!is_systems_contract(file_name, file_content));
// }

// #[test]
// fn test_is_system_contract_ignore_models() {
// let file_name = "dojo_examples::models::position.json";
// let file_content = include_str!(
// "test_data/spawn-and-move/target/dev/dojo_examples::models::position.json"
// );
// assert!(!is_systems_contract(file_name, file_content));
// }

// #[test]
// fn model_name_from_artifact_filename_ok() {
// let file_name = "dojo_examples::models::position.json";
// assert_eq!(model_name_from_artifact_filename(file_name), Some("position".to_string()));
// }

// #[test]
// fn is_model_contract_ok() {
// let file_content =
//
// include_str!("test_data/spawn-and-move/target/dev/dojo_examples::models::moves.json");
// let tokens = AbiParser::tokens_from_abi_string(file_content, &HashMap::new()).unwrap();

// assert!(is_model_contract(&tokens));
// }

// #[test]
// fn is_model_contract_ignore_systems() {
// let file_content = include_str!(
// "test_data/spawn-and-move/target/dev/dojo_examples::actions::actions.json"
// );
// let tokens = AbiParser::tokens_from_abi_string(file_content, &HashMap::new()).unwrap();

// assert!(!is_model_contract(&tokens));
// }

// #[test]
// fn is_model_contract_ignore_dojo_files() {
// let file_content =
// include_str!("test_data/spawn-and-move/target/dev/dojo::world::world.json");
// let tokens = AbiParser::tokens_from_abi_string(file_content, &HashMap::new()).unwrap();

// assert!(!is_model_contract(&tokens));
// }

// #[test]
// fn gather_models_ok() {
// let models =
//
// gather_models(&Utf8PathBuf::from("src/test_data/spawn-and-move/target/dev")).unwrap();

// assert_eq!(models.len(), 2);

// let pos = models.get("Position").unwrap();
// assert_eq!(pos.name, "Position");
// assert_eq!(pos.qualified_path, "dojo_examples::models::Position");

// let moves = models.get("Moves").unwrap();
// assert_eq!(moves.name, "Moves");
// assert_eq!(moves.qualified_path, "dojo_examples::models::Moves");
// }
// }
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn is_system_contract_ok() {
let file_name = "dojo_examples::actions::actions.json";
let file_content = include_str!(
"test_data/spawn-and-move/target/dev/dojo_examples::actions::actions.json"
);

assert!(is_systems_contract(file_name, file_content));
}

#[test]
fn is_system_contract_ignore_dojo_files() {
let file_name = "dojo::world::world.json";
let file_content = "";
assert!(!is_systems_contract(file_name, file_content));

let file_name = "manifest.json";
assert!(!is_systems_contract(file_name, file_content));
}

#[test]
fn test_is_system_contract_ignore_models() {
let file_name = "dojo_examples::models::position.json";
let file_content = include_str!(
"test_data/spawn-and-move/target/dev/dojo_examples::models::position.json"
);
assert!(!is_systems_contract(file_name, file_content));
}

#[test]
fn model_name_from_artifact_filename_ok() {
let file_name = "dojo_examples::models::position.json";
assert_eq!(model_name_from_artifact_filename(file_name), Some("position".to_string()));
}

#[test]
fn is_model_contract_ok() {
let file_content =
include_str!("test_data/spawn-and-move/target/dev/dojo_examples::models::moves.json");
let tokens = AbiParser::tokens_from_abi_string(file_content, &HashMap::new()).unwrap();

assert!(is_model_contract(&tokens));
}

#[test]
fn is_model_contract_ignore_systems() {
let file_content = include_str!(
"test_data/spawn-and-move/target/dev/dojo_examples::actions::actions.json"
);
let tokens = AbiParser::tokens_from_abi_string(file_content, &HashMap::new()).unwrap();

assert!(!is_model_contract(&tokens));
}

#[test]
fn is_model_contract_ignore_dojo_files() {
let file_content =
include_str!("test_data/spawn-and-move/target/dev/dojo::world::world.json");
let tokens = AbiParser::tokens_from_abi_string(file_content, &HashMap::new()).unwrap();

assert!(!is_model_contract(&tokens));
}

#[test]
fn gather_data_ok() {
let data = gather_dojo_data(&Utf8PathBuf::from("src/test_data/spawn-and-move/target/dev"))
.unwrap();

assert_eq!(data.models.len(), 4);

let pos = data.models.get("Position").unwrap();
assert_eq!(pos.name, "Position");
assert_eq!(pos.qualified_path, "dojo_examples::models::Position");

let moves = data.models.get("Moves").unwrap();
assert_eq!(moves.name, "Moves");
assert_eq!(moves.qualified_path, "dojo_examples::models::Moves");
}
}
2 changes: 1 addition & 1 deletion crates/dojo-world/src/contracts/model_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn test_model() {
assert_eq!(
position.class_hash(),
FieldElement::from_hex_be(
"0x02a7df852d6ef0af662dad741b97b423ba0fb34a1483599781ac9e7f6822bc25"
"0x004cd20d231b04405a77b184c115dc60637e186504fad7f0929bd76cbd09c10b"
)
.unwrap()
);
Expand Down

0 comments on commit f66a75a

Please sign in to comment.