Skip to content

Commit

Permalink
dont randomize bytes for the alias test
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed Jul 2, 2024
1 parent 1df943d commit a542afd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
8 changes: 4 additions & 4 deletions crates/loam-cli/tests/it/build_clients/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ hello_world.workspace = true
"#,
);
let output = env
.loam_env("development")
.loam_env("development", true)
.output()
.expect("Failed to execute command");

Expand All @@ -108,7 +108,7 @@ hello_world.workspace = true
.contains("🍽️ importing \"hello_world\" contract"));

let output2 = env
.loam_env("development")
.loam_env("development", false)
.output()
.expect("Failed to execute command");

Expand All @@ -123,7 +123,7 @@ hello_world.workspace = true
env.replace_file(file, file_replaced);

let output3 = env
.loam_env("development")
.loam_env("development", false)
.output()
.expect("Failed to execute command");

Expand All @@ -150,7 +150,7 @@ hello_world.workspace = true
env.replace_file("contracts/auth/src/lib.rs", file_replaced);

let output4 = env
.loam("build")
.loam_build("production", false)
.output()
.expect("Failed to execute command");

Expand Down
52 changes: 21 additions & 31 deletions crates/loam-cli/tests/it/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl TestEnv {
pub fn modify_wasm(&self, contract_name: &str) -> Result<(), Box<dyn Error>> {
// Read Cargo.toml to get the actual name
let cargo_toml_path = self.cwd.join("contracts").join(contract_name).join("Cargo.toml");
println!("cargo toml path is {:?}", cargo_toml_path);
let cargo_toml_content = fs::read_to_string(cargo_toml_path)?;
let cargo_toml: Value = toml::from_str(&cargo_toml_content)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
Expand All @@ -62,8 +61,6 @@ impl TestEnv {
.as_str()
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid Cargo.toml"))?;

println!("packange name is is {:?}", package_name);

// Convert package name to proper filename format
let filename = package_name.replace('-', "_");

Expand All @@ -74,45 +71,38 @@ impl TestEnv {
.join("release")
.join(format!("{}.wasm", filename));

println!("wasm path is {:?}", wasm_path);
// Read the original wasm
let mut wasm_bytes = fs::read(&wasm_path)?;

// Generate random bytes
let mut rng = thread_rng();
let random_bytes: Vec<u8> = (0..10).map(|_| rng.gen()).collect();

// Write the custom section
wasm_gen::write_custom_section(&mut wasm_bytes, "random_data", &random_bytes);

// Write the modified wasm
fs::write(&wasm_path, wasm_bytes)?;

Ok(())
}

pub fn loam_build(&self, env: &str) -> Command {
// Run initial build
let mut initial_build = Command::cargo_bin("loam").unwrap();
initial_build.current_dir(&self.cwd);
initial_build.arg("build");
initial_build.arg(env);
initial_build.output().expect("Failed to execute initial build");

// Modify WASM files
let contracts_dir = self.cwd.join("contracts");
if let Ok(entries) = fs::read_dir(contracts_dir) {
for entry in entries.flatten() {
if let Ok(file_type) = entry.file_type() {
if file_type.is_dir() {
if let Some(contract_name) = entry.file_name().to_str() {
self.modify_wasm(contract_name).expect("Failed to modify WASM");
pub fn loam_build(&self, env: &str, randomize_wasm: bool) -> Command {
if(randomize_wasm){
// Run initial build
let mut initial_build = Command::cargo_bin("loam").unwrap();
initial_build.current_dir(&self.cwd);
initial_build.arg("build");
initial_build.arg(env);
initial_build.output().expect("Failed to execute initial build");

// Modify WASM files
let contracts_dir = self.cwd.join("contracts");
if let Ok(entries) = fs::read_dir(contracts_dir) {
for entry in entries.flatten() {
if let Ok(file_type) = entry.file_type() {
if file_type.is_dir() {
if let Some(contract_name) = entry.file_name().to_str() {
self.modify_wasm(contract_name).expect("Failed to modify WASM");
}
}
}
}
}
}

// Run final build with --build-clients
let mut loam = Command::cargo_bin("loam").unwrap();
loam.current_dir(&self.cwd);
Expand All @@ -124,7 +114,7 @@ impl TestEnv {

pub fn loam(&self, cmd: &str) -> Command {
if cmd == "build" {
self.loam_build("production")
self.loam_build("production", true)
}
else{
let mut loam = Command::cargo_bin("loam").unwrap();
Expand All @@ -134,8 +124,8 @@ impl TestEnv {
}
}

pub fn loam_env(&self, env: &str) -> Command {
self.loam_build(env)
pub fn loam_env(&self, env: &str, randomize_wasm: bool) -> Command {
self.loam_build(env, randomize_wasm)
}

pub fn soroban(&self, cmd: &str) -> Command {
Expand Down

0 comments on commit a542afd

Please sign in to comment.