Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forc-client build script should update proxy abi also for deployment tests #6561

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading