diff --git a/forc-plugins/forc-client/src/cmd/deploy.rs b/forc-plugins/forc-client/src/cmd/deploy.rs index 23a38ada2d9..c6d04ddcbb9 100644 --- a/forc-plugins/forc-client/src/cmd/deploy.rs +++ b/forc-plugins/forc-client/src/cmd/deploy.rs @@ -52,4 +52,24 @@ pub struct Command { /// Sign the deployment transaction manually. #[clap(long)] pub manual_signing: bool, + /// Override storage slot initialization. + /// + /// By default, storage slots are initialized with the values defined in the storage block in + /// the contract. You can override the initialization by providing the file path to a JSON file + /// containing the overriden values. + /// + /// The file format and key values should match the compiler-generated `*-storage_slots.json` file in the output + /// directory of the compiled contract. + /// + /// Example: `forc deploy --override-storage-slots my_override.json` + /// + /// my_override.json: + /// [ + /// { + /// "key": "", + /// "value": "0000000000000000000000000000000000000000000000000000000000000001" + /// } + /// ] + #[clap(long, verbatim_doc_comment, name = "JSON_FILE_PATH")] + pub override_storage_slots: Option, } diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index b86ca2e2134..d761117bd69 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -215,7 +215,14 @@ pub async fn deploy_pkg( let bytecode = &compiled.bytecode.bytes; - let mut storage_slots = compiled.storage_slots.clone(); + let mut storage_slots = + if let Some(storage_slot_override_file) = &command.override_storage_slots { + let storage_slots_file = std::fs::read_to_string(storage_slot_override_file)?; + let storage_slots: Vec = serde_json::from_str(&storage_slots_file)?; + storage_slots + } else { + compiled.storage_slots.clone() + }; storage_slots.sort(); let contract = Contract::from(bytecode.clone());