Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed Jul 2, 2024
1 parent a542afd commit 89f96b7
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions crates/loam-cli/tests/it/util.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use assert_cmd::{assert::Assert, Command};
use assert_fs::TempDir;
use fs_extra::dir::{copy, CopyOptions};
use std::path::PathBuf;
use std::fs;
use rand::{thread_rng, Rng};
use toml::Value;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
use toml::Value;

pub struct TestEnv {
pub temp_dir: TempDir,
Expand Down Expand Up @@ -52,20 +52,25 @@ 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");
let cargo_toml_path = self
.cwd
.join("contracts")
.join(contract_name)
.join("Cargo.toml");
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))?;
let package_name = cargo_toml["package"]["name"]
.as_str()
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid Cargo.toml"))?;

let package_name = cargo_toml["package"]["name"].as_str().ok_or_else(|| {
std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid Cargo.toml")
})?;

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

// Construct the path to the .wasm file
let wasm_path = self.cwd
let wasm_path = self
.cwd
.join("target")
.join("wasm32-unknown-unknown")
.join("release")
Expand All @@ -81,13 +86,15 @@ impl TestEnv {
}

pub fn loam_build(&self, env: &str, randomize_wasm: bool) -> Command {
if(randomize_wasm){
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");
initial_build
.output()
.expect("Failed to execute initial build");

// Modify WASM files
let contracts_dir = self.cwd.join("contracts");
Expand All @@ -96,7 +103,8 @@ impl TestEnv {
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");
self.modify_wasm(contract_name)
.expect("Failed to modify WASM");
}
}
}
Expand All @@ -115,8 +123,7 @@ impl TestEnv {
pub fn loam(&self, cmd: &str) -> Command {
if cmd == "build" {
self.loam_build("production", true)
}
else{
} else {
let mut loam = Command::cargo_bin("loam").unwrap();
loam.current_dir(&self.cwd);
loam.arg(cmd);
Expand Down

0 comments on commit 89f96b7

Please sign in to comment.