Skip to content

Commit

Permalink
fix: incorrect assumption about migration output (#1790)
Browse files Browse the repository at this point in the history
* fix: incorrect assumption about migration output

* remove unnecessary import
  • Loading branch information
lambda-0x authored Apr 11, 2024
1 parent ab1fa3f commit f1cf597
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
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 @@ -182,25 +182,27 @@ async fn update_manifests_and_abis(
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
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(
salt,
base_class_hash,
output.base_class_hash,
&[],
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;
}
});

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

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 @@ -788,7 +791,7 @@ where
)
.await
{
Ok(output) => {
Ok(mut output) => {
if let Some(ref declare) = output.declare {
ui.print_hidden_sub(format!(
"Declare transaction: {:#x}",
Expand All @@ -814,7 +817,9 @@ where
));
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

0 comments on commit f1cf597

Please sign in to comment.