Skip to content

Commit

Permalink
fix: forc-client build script should update proxy abi also for deploy…
Browse files Browse the repository at this point in the history
…ment tests (#6561)

## Description
closes #6558.

This PR fixes an issue with the forc-client build script that causes the
deployment tests to be updated manually for each proxy abi change. This
is a follow up on #6535 and was overlooked in that one. Not critical as
it does not break anything on the user side but rather an code-quality
issue.
  • Loading branch information
kayagokalp authored Sep 19, 2024
1 parent 10a78a7 commit 613f129
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 746 deletions.
43 changes: 25 additions & 18 deletions forc-plugins/forc-client/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

fn minify_json(json: &str) -> String {
let mut result = String::with_capacity(json.len());
Expand Down Expand Up @@ -27,24 +27,9 @@ fn minify_json(json: &str) -> String {
result
}

fn main() {
// Path to the JSON file in the root directory next to the `src` folder
let json_path = PathBuf::from("proxy_abi/proxy_contract-abi.json");
// If proxy_contract-abi.json is changed, re-run this script
println!("cargo:rerun-if-changed=proxy_abi/proxy_contract-abi.json");
// Path to the Rust source file that contains the `abigen!` macro that
// creates a `ProxyContract`.
let source_file_path = PathBuf::from("src/util/tx.rs");
// Read the contents of the JSON file
let json_content =
fs::read_to_string(json_path).expect("Unable to read proxy_contract-abi.json");

// Minify the JSON content
let minified_json = minify_json(&json_content);

fn update_proxy_abi_decl_with_file(source_file_path: &Path, minified_json: &str) {
// Read the contents of the source file
let mut source_code =
fs::read_to_string(&source_file_path).expect("Unable to read source file");
let mut source_code = fs::read_to_string(source_file_path).expect("Unable to read source file");

// Prepare the replacement string for the `abigen!` macro
let escaped_json = minified_json.replace('\\', "\\\\").replace('"', "\\\"");
Expand All @@ -67,3 +52,25 @@ fn main() {
// Write the modified source code back to the source file
fs::write(source_file_path, source_code).expect("Unable to write back to the source file");
}

fn main() {
// Path to the JSON file in the root directory next to the `src` folder
let json_path = PathBuf::from("proxy_abi/proxy_contract-abi.json");
// Read the contents of the JSON file
let json_content =
fs::read_to_string(json_path).expect("Unable to read proxy_contract-abi.json");

// Minify the JSON content
let minified_json = minify_json(&json_content);

// If proxy_contract-abi.json is changed, re-run this script
println!("cargo:rerun-if-changed=proxy_abi/proxy_contract-abi.json");

// Path to the Rust source file that contains the `abigen!` macro that
// creates a `ProxyContract`.
let util_tx_path = PathBuf::from("src/util/tx.rs");
update_proxy_abi_decl_with_file(&util_tx_path, &minified_json);

let util_tx_path = PathBuf::from("tests/deploy.rs");
update_proxy_abi_decl_with_file(&util_tx_path, &minified_json);
}
Loading

0 comments on commit 613f129

Please sign in to comment.