Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sign with lab #1579

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion Cargo.lock

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

155 changes: 133 additions & 22 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use fs_extra::dir::CopyOptions;

use soroban_cli::{
commands::{contract::invoke, global, keys, NetworkRunnable},
config::{self, network},
config::{self, network, sign_with},
CommandParser,
};

Expand Down Expand Up @@ -222,17 +222,20 @@ impl TestEnv {
pub fn clone_config(&self, account: &str) -> config::Args {
let config_dir = Some(self.dir().to_path_buf());
config::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
source_account: account.to_string(),
locator: config::locator::Args {
global: false,
config_dir,
sign_with: sign_with::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
locator: config::locator::Args {
global: false,
config_dir,
},
yes: true,
..Default::default()
},
hd_path: None,
}
}

Expand All @@ -243,9 +246,10 @@ impl TestEnv {
account: &str,
) -> Result<T::Result, T::Error> {
let config = self.clone_config(account);
eprintln!("Running with config: {config:#?}");
cmd.run_against_rpc_server(
Some(&global::Args {
locator: config.locator.clone(),
locator: config.sign_with.locator.clone(),
filter_logs: Vec::default(),
quiet: false,
verbose: false,
Expand All @@ -264,9 +268,10 @@ impl TestEnv {
}

/// Returns the public key corresponding to the test keys's `hd_path`
pub fn test_address(&self, hd_path: usize) -> String {
pub async fn test_address(&self, hd_path: usize) -> String {
self.cmd::<keys::address::Cmd>(&format!("--hd-path={hd_path}"))
.public_key()
.await
.unwrap()
.to_string()
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ use super::util::invoke_with_roundtrip;

fn invoke_custom(e: &TestEnv, id: &str, func: &str) -> assert_cmd::Command {
let mut s = e.new_assert_cmd("contract");
s.arg("invoke").arg("--id").arg(id).arg("--").arg(func);
s.env("RUST_LOG", "soroban_cli::log::diagnostic_event=off")
.arg("invoke")
.arg("--id")
.arg(id)
.arg("--is-view")
.arg("--")
.arg(func);
s
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ async fn invoke_auth_with_different_test_account_fail(sandbox: &TestEnv, id: &st
"--hd-path=0",
"--id",
id,
"--fee=1000000",
"--",
"auth",
&format!("--addr={addr}"),
Expand All @@ -227,8 +228,8 @@ async fn invoke_auth_with_different_test_account_fail(sandbox: &TestEnv, id: &st
.await;
let e = res.unwrap_err();
assert!(
matches!(e, contract::invoke::Error::Config(_)),
"Expected config error got {e:?}"
matches!(e, contract::invoke::Error::Rpc(_)),
"Expected rpc error got {e:?}"
);
}

Expand Down
50 changes: 48 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/tx.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use soroban_sdk::xdr::{Limits, ReadXdr, TransactionEnvelope, WriteXdr};
use soroban_test::{AssertExt, TestEnv};

use crate::integration::util::{deploy_contract, DeployKind, HELLO_WORLD};
use crate::integration::util::{deploy_contract, deploy_hello, DeployKind, HELLO_WORLD};

#[tokio::test]
async fn txn_simulate() {
async fn simulate() {
let sandbox = &TestEnv::new();
let xdr_base64_build_only = deploy_contract(sandbox, HELLO_WORLD, DeployKind::BuildOnly).await;
let xdr_base64_sim_only = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly).await;
Expand Down Expand Up @@ -49,3 +49,49 @@ async fn txn_hash() {

assert_eq!(hash.trim(), expected_hash);
}

#[tokio::test]
async fn send() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("contract")
.arg("install")
.args(["--wasm", HELLO_WORLD.path().as_os_str().to_str().unwrap()])
.assert()
.success();

let xdr_base64 = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly).await;
println!("{xdr_base64}");
let tx_env = TransactionEnvelope::from_xdr_base64(&xdr_base64, Limits::none()).unwrap();
let tx_env = sign_manually(sandbox, &tx_env);

println!(
"Transaction to send:\n{}",
tx_env.to_xdr_base64(Limits::none()).unwrap()
);

let assembled_str = sandbox
.new_assert_cmd("tx")
.arg("send")
.write_stdin(tx_env.to_xdr_base64(Limits::none()).unwrap())
.assert()
.success()
.stdout_as_str();
println!("Transaction sent: {assembled_str}");
}

fn sign_manually(sandbox: &TestEnv, tx_env: &TransactionEnvelope) -> TransactionEnvelope {
TransactionEnvelope::from_xdr_base64(
sandbox
.new_assert_cmd("tx")
.arg("sign")
.arg("--sign-with-key=test")
.arg("--yes")
.write_stdin(tx_env.to_xdr_base64(Limits::none()).unwrap().as_bytes())
.assert()
.success()
.stdout_as_str(),
Limits::none(),
)
.unwrap()
}
7 changes: 5 additions & 2 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ soroban-ledger-snapshot = { workspace = true }
stellar-strkey = { workspace = true }
soroban-sdk = { workspace = true }
soroban-rpc = { workspace = true }

clap = { workspace = true, features = [
"derive",
"env",
Expand Down Expand Up @@ -113,17 +114,19 @@ async-compression = { version = "0.4.12", features = [ "tokio", "gzip" ] }
tempfile = "3.8.1"
toml_edit = "0.21.0"
rust-embed = { version = "8.2.0", features = ["debug-embed"] }
bollard = { workspace=true }
bollard = { workspace = true }
futures-util = "0.3.30"
futures = "0.3.30"
home = "0.5.9"
flate2 = "1.0.30"
bytesize = "1.3.0"
humantime = "2.1.0"
phf = { version = "0.11.2", features = ["macros"] }
crossterm = "0.27.0"
semver = "1.0.0"
glob = "0.3.1"

open = "5.3.0"
url = "2.5.2"
# For hyper-tls
[target.'cfg(unix)'.dependencies]
openssl = { version = "=0.10.55", features = ["vendored"] }
Expand Down
Loading
Loading