Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sozo): add ability to migrate the world #1698

Merged
merged 14 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn update_manifest(
&manifest_dir,
&mut Manifest::new(
// abi path will be written by `write_manifest`
Class { class_hash: *hash, abi: None },
Class { class_hash: *hash, abi: None, original_class_hash: *hash },
WORLD_CONTRACT_NAME.into(),
),
abi,
Expand All @@ -245,7 +245,10 @@ fn update_manifest(
&relative_manifests_dir,
&relative_abis_dir,
&manifest_dir,
&mut Manifest::new(Class { class_hash: *hash, abi: None }, BASE_CONTRACT_NAME.into()),
&mut Manifest::new(
Class { class_hash: *hash, abi: None, original_class_hash: *hash },
BASE_CONTRACT_NAME.into(),
),
&None,
)?;

Expand Down Expand Up @@ -352,7 +355,12 @@ fn get_dojo_model_artifacts(
model_full_name.clone(),
(
Manifest::new(
DojoModel { class_hash, abi: None, members: model.members.clone() },
DojoModel {
class_hash,
abi: None,
members: model.members.clone(),
original_class_hash: class_hash,
},
model_full_name.into(),
),
abi,
Expand Down Expand Up @@ -423,7 +431,7 @@ fn get_dojo_contract_artifacts(
writes,
reads,
class_hash: *class_hash,
abi: None,
original_class_hash: *class_hash,
..Default::default()
},
module_name.clone(),
Expand Down
8 changes: 7 additions & 1 deletion crates/dojo-world/src/contracts/world_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ pub async fn deploy_world(
for contract in strategy.contracts {
let declare_res = contract.declare(&account, Default::default()).await.unwrap();
contract
.world_deploy(world_address, declare_res.class_hash, &account, Default::default())
.deploy_dojo_contract(
world_address,
declare_res.class_hash,
base_class_hash,
&account,
Default::default(),
)
.await
.unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,29 @@ fn test_abi_format_to_embed() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[test]
fn test_abi_format_to_path() {
let embedded = AbiFormat::Embed(vec![]);
assert!(embedded.to_path().is_none());

let path = AbiFormat::Path(Utf8PathBuf::from("/tmp"));
assert!(path.to_path().is_some());
}

#[test]
fn test_abi_format_load_abi_string() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = tempfile::tempdir()?;
let temp_path = temp_dir.path().join("abi.json");
let mut temp_file = std::fs::File::create(&temp_path)?;

write!(temp_file, "[]")?;

let path = AbiFormat::Path(Utf8PathBuf::from_path_buf(temp_path.clone()).unwrap());
assert_eq!(path.load_abi_string(&Utf8PathBuf::new()).unwrap(), "[]");

let embedded = AbiFormat::Embed(vec![]);
assert_eq!(embedded.load_abi_string(&Utf8PathBuf::new()).unwrap(), "[]");

Ok(())
}
Loading
Loading