Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Sep 18, 2024
1 parent 0a0cac0 commit 144be83
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 193 deletions.
96 changes: 24 additions & 72 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/crates/soroban-spec-typescript/ts-tests/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SOROBAN_NETWORK=local
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
SOROBAN_RPC_URL="http://localhost:8000/soroban/rpc"
SOROBAN_FRIENDBOT_URL="http://localhost:8000/friendbot"
8 changes: 4 additions & 4 deletions cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ fi
exe() { echo"${@/eval/}" ; "$@" ; }

function fund_all() {
exe eval "./soroban keys generate root"
exe eval "./soroban keys fund root"
exe eval "./stellar keys generate root"
exe eval "./stellar keys fund root"
}
function deploy() {
exe eval "(./soroban contract deploy --quiet --source root --wasm $1 --ignore-checks) > $2"
exe eval "(./stellar contract deploy --quiet --source root --wasm $1 --ignore-checks) > $2"
}
function deploy_all() {
deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm contract-id-custom-types.txt
}
function bind() {
exe eval "./soroban contract bindings typescript --contract-id $(cat $1) --output-dir ./node_modules/$2 --overwrite"
exe eval "./stellar contract bindings typescript --contract-id $(cat $1) --output-dir ./node_modules/$2 --overwrite"
}
function bind_all() {
bind contract-id-custom-types.txt test-custom-types
Expand Down
3 changes: 0 additions & 3 deletions cmd/crates/soroban-spec-typescript/ts-tests/soroban

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, Keypair } from "@stellar/stellar-sdk";
import { basicNodeSigner } from "@stellar/stellar-sdk/contract";

const rootKeypair = Keypair.fromSecret(
spawnSync("./soroban", ["keys", "show", "root"], {
spawnSync("./stellar", ["keys", "show", "root"], {
shell: true,
encoding: "utf8",
}).stdout.trim(),
Expand Down
3 changes: 3 additions & 0 deletions cmd/crates/soroban-spec-typescript/ts-tests/stellar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo run --quiet -p stellar-cli -- "$@"
56 changes: 8 additions & 48 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct TestEnv {
impl Default for TestEnv {
fn default() -> Self {
let temp_dir = TempDir::new().unwrap();

Self {
temp_dir,
rpc_url: "http://localhost:8889/soroban/rpc".to_string(),
Expand All @@ -90,59 +91,32 @@ impl TestEnv {
f(&test_env);
}

pub fn with_default_network<F: FnOnce(&TestEnv)>(f: F) {
let test_env = TestEnv::new();
f(&test_env);
}

pub fn with_port(host_port: u16) -> TestEnv {
Self::with_rpc_url(&format!("http://localhost:{host_port}/soroban/rpc"))
}

pub fn with_rpc_url(rpc_url: &str) -> TestEnv {
let env = TestEnv {
rpc_url: rpc_url.to_string(),
..Default::default()
};
env.generate_account("test", None).assert().success();
env
}

pub fn new() -> TestEnv {
if let Ok(rpc_url) = std::env::var("SOROBAN_RPC_URL") {
return Self::with_rpc_url(&rpc_url);
}
let host_port = std::env::var("SOROBAN_PORT")
.as_deref()
.ok()
.and_then(|n| n.parse().ok())
.unwrap_or(8000);
Self::with_port(host_port)
}
/// Create a new `assert_cmd::Command` for a given subcommand and set's the current directory
/// to be the internal `temp_dir`.
pub fn new_assert_cmd(&self, subcommand: &str) -> Command {
let mut cmd: Command = self.bin();
cmd.arg(subcommand)
.env("SOROBAN_ACCOUNT", TEST_ACCOUNT)
.env("SOROBAN_RPC_URL", &self.rpc_url)
.env("SOROBAN_NETWORK_PASSPHRASE", LOCAL_NETWORK_PASSPHRASE)
.env("SOROBAN_NETWORK", "local")
.env("XDG_CONFIG_HOME", self.temp_dir.join("config").as_os_str())
.env("XDG_DATA_HOME", self.temp_dir.join("data").as_os_str())
.current_dir(&self.temp_dir);
cmd
}

pub fn bin(&self) -> Command {
Command::cargo_bin("soroban").unwrap_or_else(|_| Command::new("soroban"))
Command::cargo_bin("stellar").unwrap_or_else(|_| Command::new("stellar"))
}

pub fn generate_account(&self, account: &str, seed: Option<String>) -> Command {
let mut cmd = self.new_assert_cmd("keys");

cmd.arg("generate").arg(account);

if let Some(seed) = seed {
cmd.arg(format!("--seed={seed}"));
}

cmd
}

Expand Down Expand Up @@ -204,12 +178,7 @@ impl TestEnv {
&self,
command_str: &[I],
) -> T {
let mut arg = vec![
"--network=local",
"--rpc-url=http",
"--network-passphrase=AA",
"--source-account=test",
];
let mut arg = vec!["--network=local", "--source-account=test"];
let input = command_str
.iter()
.map(AsRef::as_ref)
Expand All @@ -223,9 +192,7 @@ impl TestEnv {
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,
network: "local".to_string(),
},
source_account: account.to_string(),
locator: config::locator::Args {
Expand Down Expand Up @@ -279,13 +246,6 @@ impl TestEnv {
.to_string()
}

/// Copy the contents of the current `TestEnv` to another `TestEnv`
pub fn fork(&self) -> Result<TestEnv, Error> {
let this = TestEnv::new();
self.save(&this.temp_dir)?;
Ok(this)
}

/// Save the current state of the `TestEnv` to the given directory.
pub fn save(&self, dst: &Path) -> Result<(), Error> {
fs_extra::dir::copy(&self.temp_dir, dst, &CopyOptions::new())?;
Expand Down
10 changes: 7 additions & 3 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ fn set_and_remove_network() {
let dir = sandbox.dir().join(".soroban").join("network");
let mut read_dir = std::fs::read_dir(dir).unwrap();
let file = read_dir.next().unwrap().unwrap();

assert_eq!(file.file_name().to_str().unwrap(), "local.toml");

let res = ls(sandbox);
assert_eq!(res[0], "local");

assert_eq!(res[1], "local");

sandbox
.new_assert_cmd("network")
.arg("rm")
Expand Down Expand Up @@ -117,7 +121,7 @@ fn set_and_remove_global_network() {
.arg("ls")
.arg("--global")
.assert()
.stdout("global\n");
.stdout("futurenet\nglobal\nlocal\nmainnet\ntestnet\n");

sandbox
.new_assert_cmd("network")
Expand All @@ -133,7 +137,7 @@ fn set_and_remove_global_network() {
.env("XDG_CONFIG_HOME", dir.to_str().unwrap())
.arg("ls")
.assert()
.stdout("\n");
.stdout("futurenet\nlocal\nmainnet\ntestnet\n");
}

#[test]
Expand Down
11 changes: 6 additions & 5 deletions cmd/crates/soroban-test/tests/it/integration/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE};
#[tokio::test]
#[ignore]
async fn burn() {
let sandbox = &TestEnv::new();
let network_passphrase = LOCAL_NETWORK_PASSPHRASE.to_string();
let sandbox = &TestEnv::default();
let address = sandbox
.new_assert_cmd("keys")
.arg("address")
Expand All @@ -22,11 +21,11 @@ async fn burn() {
.arg(&asset)
.assert()
.success();
// wrap_cmd(&asset).run().await.unwrap();

let asset = soroban_cli::utils::parsing::parse_asset(&asset).unwrap();
let hash = contract_id_hash_from_asset(&asset, &network_passphrase);
let id = stellar_strkey::Contract(hash.0).to_string();
println!("{id}, {address}");

sandbox
.new_assert_cmd("contract")
.args([
Expand All @@ -40,6 +39,7 @@ async fn burn() {
])
.assert()
.stdout("\"9223372036854775807\"\n");

sandbox
.new_assert_cmd("contract")
.arg("invoke")
Expand All @@ -53,6 +53,7 @@ async fn burn() {
])
.assert()
.stdout("true\n");

sandbox
.new_assert_cmd("contract")
.args([
Expand All @@ -66,6 +67,7 @@ async fn burn() {
])
.assert()
.stdout("\"9223372036854775807\"\n");

sandbox
.new_assert_cmd("contract")
.arg("invoke")
Expand All @@ -84,7 +86,6 @@ async fn burn() {
.stdout("")
.stderr("");

println!("hi");
sandbox
.new_assert_cmd("contract")
.args([
Expand Down
28 changes: 23 additions & 5 deletions cmd/soroban-cli/src/commands/network/add.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::commands::HEADING_RPC;
use crate::config::{locator, network, secret};
use clap::command;

Expand All @@ -16,17 +17,34 @@ pub struct Cmd {
/// Name of network
pub name: String,

#[command(flatten)]
pub network: network::Network,
/// RPC server endpoint
#[arg(
long = "rpc-url",
env = "STELLAR_RPC_URL",
help_heading = HEADING_RPC,
)]
pub rpc_url: String,

/// Network passphrase to sign the transaction sent to the rpc server
#[arg(
long,
env = "STELLAR_NETWORK_PASSPHRASE",
help_heading = HEADING_RPC,
)]
pub network_passphrase: String,

#[command(flatten)]
pub config_locator: locator::Args,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
Ok(self
.config_locator
.write_network(&self.name, &self.network)?)
let network = network::Network {
rpc_url: self.rpc_url.clone(),
network_passphrase: self.network_passphrase.clone(),
name: self.name.clone(),
};

Ok(self.config_locator.write_network(&self.name, &network)?)
}
}
11 changes: 9 additions & 2 deletions cmd/soroban-cli/src/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ impl Args {
.flatten()
.map(|x| x.0);
let default_networks = network::DEFAULTS.keys().map(ToString::to_string);
Ok(saved_networks.chain(default_networks).unique().collect())
Ok(saved_networks
.chain(default_networks)
.unique()
.sorted_by(Ord::cmp)
.collect())
}

pub fn list_networks_long(&self) -> Result<Vec<(String, Network, String)>, Error> {
Expand All @@ -210,7 +214,10 @@ impl Args {
let default_networks = network::DEFAULTS
.into_iter()
.map(|(name, network)| ((*name).to_string(), network.into(), "Default".to_owned()));
Ok(saved_networks.chain(default_networks).collect())
Ok(saved_networks
.chain(default_networks)
.sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
.collect())
}

pub fn read_identity(&self, name: &str) -> Result<Secret, Error> {
Expand Down
Loading

0 comments on commit 144be83

Please sign in to comment.