From ba32bad6b3ac4957ca9d032639f239f8c4f344ba Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Thu, 17 Jul 2025 22:26:49 +0300 Subject: [PATCH] Fix edge-case in deployment order --- Cargo.lock | 15 ++++++++------- Cargo.toml | 1 + crates/core/Cargo.toml | 1 + crates/core/src/driver/mod.rs | 16 +++++++++++----- crates/format/src/input.rs | 3 +-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eebc456..1fdc74f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -336,7 +336,7 @@ dependencies = [ "derive_more 2.0.1", "foldhash", "hashbrown 0.15.3", - "indexmap 2.9.0", + "indexmap 2.10.0", "itoa", "k256", "keccak-asm", @@ -597,7 +597,7 @@ dependencies = [ "alloy-sol-macro-input", "const-hex", "heck", - "indexmap 2.9.0", + "indexmap 2.10.0", "proc-macro-error2", "proc-macro2", "quote", @@ -2400,7 +2400,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.9.0", + "indexmap 2.10.0", "slab", "tokio", "tokio-util", @@ -2842,9 +2842,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown 0.15.3", @@ -3962,6 +3962,7 @@ dependencies = [ "alloy", "anyhow", "clap", + "indexmap 2.10.0", "rayon", "revive-dt-compiler", "revive-dt-config", @@ -4505,7 +4506,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.9.0", + "indexmap 2.10.0", "serde", "serde_derive", "serde_json", @@ -5394,7 +5395,7 @@ version = "0.22.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" dependencies = [ - "indexmap 2.9.0", + "indexmap 2.10.0", "serde", "serde_spanned", "toml_datetime", diff --git a/Cargo.toml b/Cargo.toml index 9f3c875..ac0bce5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ tracing-subscriber = { version = "0.3.19", default-features = false, features = "json", "env-filter", ] } +indexmap = { version = "2.10.0", default-features = false } # revive compiler revive-solc-json-interface = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" } diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index cf93997..89fe7b9 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -23,6 +23,7 @@ revive-dt-report = { workspace = true } alloy = { workspace = true } anyhow = { workspace = true } clap = { workspace = true } +indexmap = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } rayon = { workspace = true } diff --git a/crates/core/src/driver/mod.rs b/crates/core/src/driver/mod.rs index afdae67..e249676 100644 --- a/crates/core/src/driver/mod.rs +++ b/crates/core/src/driver/mod.rs @@ -15,6 +15,7 @@ use alloy::{ }, }; use anyhow::Context; +use indexmap::IndexMap; use revive_dt_compiler::{Compiler, SolidityCompiler}; use revive_dt_config::Arguments; use revive_dt_format::case::CaseIdx; @@ -162,11 +163,12 @@ where ); let _guard = span.enter(); - let mut instances_we_must_deploy = HashMap::::new(); - if let Method::Deployer = input.method { - instances_we_must_deploy.insert(input.instance.clone(), true); - } - + // The ordering of the following statements and the use of the IndexMap is very intentional + // here. The order in which we do the deployments matters. For example, say that this is + // a `#deployer` call and the first argument is `Callable.address` which has not yet been + // deployed. This means that we need to deploy it first and then deploy then deploy the one + // from the input. + let mut instances_we_must_deploy = IndexMap::::new(); for instance in input.find_all_contract_instances().into_iter() { if !self .deployed_contracts @@ -177,6 +179,10 @@ where instances_we_must_deploy.entry(instance).or_insert(false); } } + if let Method::Deployer = input.method { + instances_we_must_deploy.swap_remove(&input.instance); + instances_we_must_deploy.insert(input.instance.clone(), true); + } tracing::debug!( instances_to_deploy = instances_we_must_deploy.len(), diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index 6c3ea5c..a73e64a 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -107,7 +107,7 @@ impl Input { deployed_contracts: &HashMap, ) -> anyhow::Result { match self.method { - Method::Deployer => { + Method::Deployer | Method::Fallback => { let calldata_args = match &self.calldata { Some(Calldata::Compound(args)) => args, _ => anyhow::bail!("Expected compound calldata for function call"), @@ -128,7 +128,6 @@ impl Input { Ok(calldata.into()) } - Method::Fallback => Ok(Default::default()), Method::FunctionName(ref function_name) => { let Some(abi) = deployed_contracts.get(&self.instance).map(|(_, a)| a) else { tracing::error!(