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

fix: incorrect assumption about migration output #1790

Merged
merged 2 commits into from
Apr 11, 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
3 changes: 3 additions & 0 deletions crates/dojo-world/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct DeployOutput {
// base class hash at time of deployment
pub base_class_hash: FieldElement,
pub was_upgraded: bool,
pub name: Option<String>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -215,6 +216,7 @@ pub trait Deployable: Declarable + Sync {
declare,
base_class_hash,
was_upgraded,
name: None,
})
}

Expand Down Expand Up @@ -287,6 +289,7 @@ pub trait Deployable: Declarable + Sync {
declare,
base_class_hash: FieldElement::default(),
was_upgraded: false,
name: None,
})
}

Expand Down
37 changes: 21 additions & 16 deletions crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,27 @@
local_manifest.world.inner.block_number = migration_output.world_block_number;
}

let base_class_hash = *local_manifest.base.inner.class_hash();

debug_assert!(local_manifest.contracts.len() == migration_output.contracts.len());

local_manifest.contracts.iter_mut().zip(migration_output.contracts).for_each(
|(local_manifest, contract_output)| {
let salt = generate_salt(&local_manifest.name);
local_manifest.inner.address = Some(get_contract_address(
migration_output.contracts.iter().for_each(|contract_output| {
// ignore failed migration which are represented by None

Check warning on line 185 in crates/sozo/ops/src/migration/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration/mod.rs#L185

Added line #L185 was not covered by tests
if let Some(output) = contract_output {
// find the contract in local manifest and update its address and base class hash
let local = local_manifest
.contracts
.iter_mut()
.find(|c| c.name == output.name.as_ref().unwrap())
.expect("contract got migrated, means it should be present here");

let salt = generate_salt(&local.name);
local.inner.address = Some(get_contract_address(

Check warning on line 195 in crates/sozo/ops/src/migration/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration/mod.rs#L187-L195

Added lines #L187 - L195 were not covered by tests
salt,
base_class_hash,
output.base_class_hash,

Check warning on line 197 in crates/sozo/ops/src/migration/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration/mod.rs#L197

Added line #L197 was not covered by tests
&[],
migration_output.world_address,
));

if let Some(output) = contract_output {
local_manifest.inner.base_class_hash = output.base_class_hash;
}
},
);
local.inner.base_class_hash = output.base_class_hash;
}
});

Check warning on line 204 in crates/sozo/ops/src/migration/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration/mod.rs#L202-L204

Added lines #L202 - L204 were not covered by tests

// copy abi files from `abi/base` to `abi/deployments/{chain_id}` and update abi path in
// local_manifest
Expand Down Expand Up @@ -612,7 +614,7 @@
)
.await
{
Ok(val) => {
Ok(mut val) => {
if let Some(declare) = val.clone().declare {
ui.print_hidden_sub(format!(
"Declare transaction: {:#x}",
Expand All @@ -622,6 +624,7 @@

ui.print_hidden_sub(format!("Deploy transaction: {:#x}", val.transaction_hash));

val.name = Some(contract.diff.name.clone());
Ok(ContractDeploymentOutput::Output(val))
}
Err(MigrationError::ContractAlreadyDeployed(contract_address)) => {
Expand Down Expand Up @@ -787,7 +790,7 @@
)
.await
{
Ok(output) => {
Ok(mut output) => {
if let Some(ref declare) = output.declare {
ui.print_hidden_sub(format!(
"Declare transaction: {:#x}",
Expand All @@ -813,7 +816,9 @@
));
ui.print_sub(format!("Contract address: {:#x}", output.contract_address));
}
let name = contract.diff.name.clone();

output.name = Some(name);
deploy_output.push(Some(output));
}
Err(MigrationError::ContractAlreadyDeployed(contract_address)) => {
Expand Down
Loading