Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed Aug 21, 2024
1 parent 3dff966 commit c5f3a8c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ mod hello_world;
mod snapshot;
mod tx;
mod util;
mod wrap;
mod wrap;
73 changes: 56 additions & 17 deletions cmd/crates/soroban-test/tests/it/integration/cookbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ fn parse_command(command: &str) -> Vec<String> {
.collect()
}

async fn run_command(sandbox: &TestEnv, command: &str, wasm_path: &str, wasm_hash: &str, source: &str, contract_id: &str, bob_id: &str, native_id: &str) -> Result<(), String> {
async fn run_command(
sandbox: &TestEnv,
command: &str,
wasm_path: &str,
wasm_hash: &str,
source: &str,
contract_id: &str,
bob_id: &str,
native_id: &str,
) -> Result<(), String> {
if command.contains("export") {
return Ok(());
}
let args = parse_command(command);
if args.is_empty() {
return Err("Empty command".to_string());
}
if command.contains("contract asset deploy"){
if command.contains("contract asset deploy") {
return Ok(());
}
/*if command.contains("keys generate"){
Expand All @@ -40,48 +49,48 @@ async fn run_command(sandbox: &TestEnv, command: &str, wasm_path: &str, wasm_has
modified_args.push(arg.to_string());
modified_args.push(wasm_path.to_string());
skip_next = true;
},
}
"--wasm-hash" => {
modified_args.push(arg.to_string());
modified_args.push(wasm_hash.to_string());
skip_next = true;
},
}
"--source" | "--source-account" => {
modified_args.push(arg.to_string());
modified_args.push(source.to_string());
skip_next = true;
},
}
"--contract-id" | "--id" => {
modified_args.push(arg.to_string());
modified_args.push(contract_id.to_string());
skip_next = true;
},
}
"--network-passphrase" => {
modified_args.push(arg.to_string());
modified_args.push(LOCAL.to_string());
skip_next = true;
},
}
"--network" => {
modified_args.push(arg.to_string());
modified_args.push("local".to_string());
skip_next = true;
},
}
"<DURABILITY>" => {
modified_args.push("persistent".to_string());
skip_next = false;
},
}
"<KEY>" => {
modified_args.push("COUNTER".to_string());
skip_next = false;
},
}
"<Bob_ID>" => {
modified_args.push(bob_id.to_string());
skip_next = false;
},
}
"<asset_contract_ID>" => {
modified_args.push(native_id.to_string());
skip_next = false;
},
}
_ => modified_args.push(arg.to_string()),
}

Expand All @@ -103,7 +112,16 @@ async fn run_command(sandbox: &TestEnv, command: &str, wasm_path: &str, wasm_has
Ok(())
}

async fn test_mdx_file(sandbox: &TestEnv, file_path: &str, wasm_path: &str, wasm_hash: &str, source: &str, contract_id: &str, bob_id: &str, native_id: &str) -> Result<(), String> {
async fn test_mdx_file(
sandbox: &TestEnv,
file_path: &str,
wasm_path: &str,
wasm_hash: &str,
source: &str,
contract_id: &str,
bob_id: &str,
native_id: &str,
) -> Result<(), String> {
let content = fs::read_to_string(file_path)
.map_err(|e| format!("Failed to read file {}: {}", file_path, e))?;

Expand All @@ -117,7 +135,17 @@ async fn test_mdx_file(sandbox: &TestEnv, file_path: &str, wasm_path: &str, wasm

for (i, command) in commands.iter().enumerate() {
println!("Running command {}: {}", i + 1, command);
run_command(sandbox, command, wasm_path, wasm_hash, source, contract_id, bob_id, native_id).await?;
run_command(
sandbox,
command,
wasm_path,
wasm_hash,
source,
contract_id,
bob_id,
native_id,
)
.await?;
}

Ok(())
Expand Down Expand Up @@ -147,14 +175,14 @@ mod tests {
let wasm_path = wasm.path();
let wasm_hash = wasm.hash().expect("should exist").to_string();
let source = "test";

sandbox
.new_assert_cmd("keys")
.arg("fund")
.arg(source)
.assert()
.success();

sandbox
.new_assert_cmd("keys")
.arg("generate")
Expand Down Expand Up @@ -211,7 +239,18 @@ mod tests {
}

let file_path = path.to_str().unwrap();
match test_mdx_file(&sandbox, file_path, &wasm_path.to_str().unwrap(), &wasm_hash, source, &contract_id, &bob_id, &native_id).await {
match test_mdx_file(
&sandbox,
file_path,
&wasm_path.to_str().unwrap(),
&wasm_hash,
source,
&contract_id,
&bob_id,
&native_id,
)
.await
{
Ok(_) => println!("Successfully tested all commands in {}", file_path),
Err(e) => panic!("Error testing {}: {}", file_path, e),
}
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod build;
mod config;
mod help;
mod init;
#[cfg(feature = "it")]
mod integration;
mod plugin;
mod util;
Expand Down

0 comments on commit c5f3a8c

Please sign in to comment.