From 15d208f1b96dc53c05d249e73c8a8cefd37319d3 Mon Sep 17 00:00:00 2001 From: Devan Non Date: Mon, 8 May 2023 17:53:26 +0200 Subject: [PATCH] load paths back into ScriptSequence and store rpc based on index --- cli/src/cmd/forge/script/sequence.rs | 33 +++++++++++-------- cli/tests/it/script.rs | 15 +++++---- .../fixtures/broadcast.sensitive.log.json | 28 +++++++++++----- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/cli/src/cmd/forge/script/sequence.rs b/cli/src/cmd/forge/script/sequence.rs index 2f9af7c3c257..3d9661445ecc 100644 --- a/cli/src/cmd/forge/script/sequence.rs +++ b/cli/src/cmd/forge/script/sequence.rs @@ -13,11 +13,11 @@ use ethers::{ types::transaction::eip2718::TypedTransaction, }; use eyre::{ContextCompat, WrapErr}; -use foundry_common::{fs, shell, RpcUrl, SELECTOR_LEN}; +use foundry_common::{fs, shell, SELECTOR_LEN}; use foundry_config::Config; use serde::{Deserialize, Serialize}; use std::{ - collections::{BTreeMap, HashMap, VecDeque}, + collections::{HashMap, VecDeque}, io::BufWriter, path::{Path, PathBuf}, time::{SystemTime, UNIX_EPOCH}, @@ -48,20 +48,24 @@ pub struct ScriptSequence { pub commit: Option, } +#[derive(Deserialize, Serialize, Clone, Default)] +pub struct TransactionWithMetadataSensitive { + pub rpc: Option, +} + /// Sensitive info from the script sequence which is saved into the cache folder #[derive(Deserialize, Serialize, Clone, Default)] pub struct ScriptSequenceSensitive { - pub transactions_to_rpc: BTreeMap>, + pub transactions: VecDeque, } impl From<&mut ScriptSequence> for ScriptSequenceSensitive { fn from(sequence: &mut ScriptSequence) -> Self { ScriptSequenceSensitive { - transactions_to_rpc: sequence + transactions: sequence .transactions .iter() - .filter(|tx| tx.hash.is_some()) - .map(|tx| (tx.hash.unwrap(), tx.rpc.clone())) + .map(|tx| TransactionWithMetadataSensitive { rpc: tx.rpc.clone() }) .collect(), } } @@ -125,19 +129,22 @@ impl ScriptSequence { broadcasted, )?; - let mut script_sequence: Self = ethers::solc::utils::read_json_file(path) + let mut script_sequence: Self = ethers::solc::utils::read_json_file(&path) .wrap_err(format!("Deployment not found for chain `{chain_id}`."))?; let script_sequence_sensitive: ScriptSequenceSensitive = - ethers::solc::utils::read_json_file(sensitive_path).wrap_err(format!( + ethers::solc::utils::read_json_file(&sensitive_path).wrap_err(format!( "Deployment's sensitive details not found for chain `{chain_id}`." ))?; - script_sequence.transactions.iter_mut().for_each(|tx| { - if tx.hash.is_some() { - tx.rpc = script_sequence_sensitive.transactions_to_rpc[&tx.hash.unwrap()].clone() - } - }); + script_sequence + .transactions + .iter_mut() + .enumerate() + .for_each(|(i, tx)| tx.rpc = script_sequence_sensitive.transactions[i].rpc.clone()); + + script_sequence.path = path; + script_sequence.sensitive_path = sensitive_path; Ok(script_sequence) } diff --git a/cli/tests/it/script.rs b/cli/tests/it/script.rs index b6e213a4c16c..6a4ead595929 100644 --- a/cli/tests/it/script.rs +++ b/cli/tests/it/script.rs @@ -705,9 +705,10 @@ forgetest_async!(check_broadcast_log, |prj: TestProject, cmd: TestCommand| async .await; // Uncomment to recreate the broadcast log - // std::fs::copy("broadcast/Broadcast.t.sol/31337/run-latest.json", - // PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../testdata/fixtures/broadcast.log.json" - // )); + // std::fs::copy( + // "broadcast/Broadcast.t.sol/31337/run-latest.json", + // PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../testdata/fixtures/broadcast.log.json" + // ), ); // Check broadcast logs // Ignore timestamp, blockHash, blockNumber, cumulativeGasUsed, effectiveGasPrice, @@ -727,9 +728,11 @@ forgetest_async!(check_broadcast_log, |prj: TestProject, cmd: TestCommand| async assert!(fixtures_log == run_log); // Uncomment to recreate the sensitive log - // std::fs::copy("cache/Broadcast.t.sol/31337/run-latest.json", - // PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../testdata/fixtures/broadcast.sensitive.log. - // json" )); + // std::fs::copy( + // "cache/Broadcast.t.sol/31337/run-latest.json", + // PathBuf::from(env!("CARGO_MANIFEST_DIR")) + // .join("../testdata/fixtures/broadcast.sensitive.log.json"), + // ); // Check sensitive logs // Ignore port number since it can change inbetween runs diff --git a/testdata/fixtures/broadcast.sensitive.log.json b/testdata/fixtures/broadcast.sensitive.log.json index 001d692a6b31..eff805f1bd56 100644 --- a/testdata/fixtures/broadcast.sensitive.log.json +++ b/testdata/fixtures/broadcast.sensitive.log.json @@ -1,10 +1,22 @@ { - "transactions_to_rpc": { - "0x4a492e51c01833ab295b3bffee253c03f054c061ce2795390d159a6c22258234": "http://127.0.0.1:51071", - "0x58480c8e39cb861ec12c7e8c95def65920a757be223852e8d08f32b472cfe512": "http://127.0.0.1:51071", - "0x66c8b101ee0f30a82f398e82da941a0d007c3205f02449e386fe340e56e7e9a0": "http://127.0.0.1:51071", - "0xba07558b550c650b07b665781bb3a90d4e186c2c6a9eb79bd483127f53fa8dd7": "http://127.0.0.1:51071", - "0xd5ceb345dc52a62a759650fcb276ac348fb644fed75b1bb7208f3b2b09a9119e": "http://127.0.0.1:51071", - "0xf49f62416a761e0ad98cdbd64d41afac96f46a7632d2ab145173611102d8a849": "http://127.0.0.1:51071" - } + "transactions": [ + { + "rpc": "http://127.0.0.1:50842" + }, + { + "rpc": "http://127.0.0.1:50842" + }, + { + "rpc": "http://127.0.0.1:50842" + }, + { + "rpc": "http://127.0.0.1:50842" + }, + { + "rpc": "http://127.0.0.1:50842" + }, + { + "rpc": "http://127.0.0.1:50842" + } + ] } \ No newline at end of file