Skip to content

Commit

Permalink
fix help tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Nov 18, 2024
1 parent 90db678 commit 7453642
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 107 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sep5 = { workspace = true }
soroban-cli = { workspace = true }
soroban-rpc = { workspace = true }

either = "1.13.0"
thiserror = "1.0.31"
sha2 = "0.10.6"
assert_cmd = "2.0.4"
Expand Down
8 changes: 5 additions & 3 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{ffi::OsString, fmt::Display, path::Path};

use assert_cmd::{assert::Assert, Command};
use assert_fs::{fixture::FixtureError, prelude::PathChild, TempDir};
use either::Either;
use fs_extra::dir::CopyOptions;

use soroban_cli::{
Expand Down Expand Up @@ -202,9 +203,10 @@ impl TestEnv {
source: &str,
) -> Result<String, invoke::Error> {
let cmd = self.cmd_with_config::<I, invoke::Cmd>(command_str, None);
self.run_cmd_with(cmd, source)
.await
.map(|r| r.into_result().unwrap())
self.run_cmd_with(cmd, source).await.map(|r| match r {
Either::Left(help) => help,
Either::Right(tx) => tx.into_result().unwrap(),
})
}

/// A convenience method for using the invoke command.
Expand Down
89 changes: 57 additions & 32 deletions cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn tuple_help() {
#[tokio::test]
async fn strukt_help() {
let output = invoke_custom("strukt", "--help").await.unwrap();
println!("{output}");
assert!(output.contains("--strukt '{ \"a\": 1, \"b\": true, \"c\": \"hello\" }'",));
assert!(output.contains("This is from the rust doc above the struct Test",));
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/crates/soroban-test/tests/it/util.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::path::Path;

use either::Either;
use soroban_cli::{
commands::contract,
config::{locator::KeyType, secret::Secret},
};
use soroban_test::{TestEnv, Wasm, TEST_ACCOUNT};
use std::path::Path;

pub const CUSTOM_TYPES: &Wasm = &Wasm::Custom("test-wasms", "test_custom_types");

Expand Down Expand Up @@ -54,10 +54,11 @@ pub async fn invoke_custom(
let mut i: contract::invoke::Cmd =
sandbox.cmd_with_config(&["--id", id, "--", func, arg], None);
i.wasm = Some(wasm.to_path_buf());
sandbox
.run_cmd_with(i, TEST_ACCOUNT)
.await
.map(|r| r.into_result().unwrap())
let s = sandbox.run_cmd_with(i, TEST_ACCOUNT).await;
s.map(|r| match r {
Either::Left(help) => help,
Either::Right(tx) => tx.into_result().unwrap(),
})
}

pub const DEFAULT_CONTRACT_ID: &str = "CDR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OO5Z";
Expand Down
Loading

0 comments on commit 7453642

Please sign in to comment.