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 e4b3254
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 115 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
14 changes: 7 additions & 7 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use predicates::boolean::PredicateBooleanExt;
use soroban_rpc::GetLatestLedgerResponse;

use soroban_cli::{
commands::{
contract::{self, fetch},
txn_result::TxnResult,
},
config::{address::Address, locator, secret},
config::{locator, secret},
};
use soroban_rpc::GetLatestLedgerResponse;
use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE};
use soroban_test::{AssertExt, LOCAL_NETWORK_PASSPHRASE, TestEnv};

use crate::integration::util::extend_contract;

Expand All @@ -19,8 +19,8 @@ async fn invoke_view_with_non_existent_source_account() {
let sandbox = &TestEnv::new();
let id = deploy_hello(sandbox).await;
let world = "world";
let mut cmd = hello_world_cmd(&id, world);
let res = sandbox.run_cmd_with(cmd, "").await.unwrap();
let cmd = hello_world_cmd(&id, world);
let res = sandbox.run_cmd_with(cmd, "").await.unwrap().unwrap_right();
assert_eq!(res, TxnResult::Res(format!(r#"["Hello",{world:?}]"#)));
}

Expand Down Expand Up @@ -167,7 +167,7 @@ fn hello_world_cmd(id: &str, arg: &str) -> contract::invoke::Cmd {

async fn invoke_hello_world_with_lib(e: &TestEnv, id: &str) {
let cmd = hello_world_cmd(id, "world");
let res = e.run_cmd_with(cmd, "test").await.unwrap();
let res = e.run_cmd_with(cmd, "test").await.unwrap().unwrap_right();
assert_eq!(res, TxnResult::Res(r#"["Hello","world"]"#.to_string()));
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ pub async fn deploy_contract(
let res = sandbox
.run_cmd_with(cmd, deployer.unwrap_or("test"))
.await
.unwrap();
.unwrap()
.unwrap_right();
match deploy {
DeployKind::BuildOnly | DeployKind::SimOnly => match res.to_envelope() {
commands::txn_result::TxnEnvelopeResult::TxnEnvelope(e) => {
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 e4b3254

Please sign in to comment.