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

Drop --rpc-url and --network-passphrase. #1616

Closed
wants to merge 5 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
104 changes: 26 additions & 78 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

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-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 -- "$@"
66 changes: 15 additions & 51 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ pub struct TestEnv {
impl Default for TestEnv {
fn default() -> Self {
let temp_dir = TempDir::new().unwrap();
Self {

let env = Self {
temp_dir,
rpc_url: "http://localhost:8889/soroban/rpc".to_string(),
}
rpc_url: "http://localhost:8000/soroban/rpc".to_string(),
};

env.generate_account("test", None).assert().success();

env
}
}

Expand All @@ -90,59 +95,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 +182,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 +196,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 +250,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
12 changes: 8 additions & 4 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 Expand Up @@ -221,7 +225,7 @@ fn generate_key_on_testnet() {
.new_assert_cmd("keys")
.arg("generate")
.arg("--rpc-url=https://soroban-testnet.stellar.org:443")
.arg("--network-passphrase=Test SDF Network ; September 2015")
.arg("--network=local")
.arg("test_2")
.assert()
.stdout("")
Expand Down
18 changes: 7 additions & 11 deletions cmd/crates/soroban-test/tests/it/integration/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use super::util::deploy_custom_account;
use super::util::deploy_swap;
use soroban_test::{TestEnv, LOCAL_NETWORK_PASSPHRASE};
use soroban_test::TestEnv;

const OUTPUT_DIR: &str = "./bindings-output";

#[tokio::test]
async fn invoke_test_generate_typescript_bindings() {
let sandbox = &TestEnv::new();
let sandbox = &TestEnv::default();
let contract_id = deploy_swap(sandbox).await;
let outdir = sandbox.dir().join(OUTPUT_DIR);
let cmd = sandbox.cmd_arr::<soroban_cli::commands::contract::bindings::typescript::Cmd>(&[
"--network-passphrase",
LOCAL_NETWORK_PASSPHRASE,
"--rpc-url",
&sandbox.rpc_url,
"--network",
"local",
"--output-dir",
&outdir.display().to_string(),
"--overwrite",
Expand All @@ -36,14 +34,12 @@ async fn invoke_test_generate_typescript_bindings() {

#[tokio::test]
async fn invoke_test_bindings_context_failure() {
let sandbox = &TestEnv::new();
let sandbox = &TestEnv::default();
let contract_id = deploy_custom_account(sandbox).await;
let outdir = sandbox.dir().join(OUTPUT_DIR);
let cmd = sandbox.cmd_arr::<soroban_cli::commands::contract::bindings::typescript::Cmd>(&[
"--network-passphrase",
LOCAL_NETWORK_PASSPHRASE,
"--rpc-url",
&sandbox.rpc_url,
"--network",
"local",
"--output-dir",
&outdir.display().to_string(),
"--overwrite",
Expand Down
6 changes: 2 additions & 4 deletions cmd/crates/soroban-test/tests/it/integration/cookbook.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use predicates::prelude::*;
use soroban_cli::config::network::passphrase::LOCAL;
use soroban_test::TestEnv;
use soroban_test::{AssertExt, TestEnv};
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -185,15 +185,13 @@ fn get_repo_root() -> PathBuf {

#[cfg(test)]
mod tests {
use soroban_test::AssertExt;

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

use super::*;

#[tokio::test]
async fn test_all_mdx_files() {
let sandbox = TestEnv::new();
let sandbox = TestEnv::default();
let wasm = HELLO_WORLD;
let wasm_path = wasm.path();
let wasm_hash = wasm.hash().expect("should exist").to_string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn invoke_custom(e: &TestEnv, id: &str, func: &str) -> assert_cmd::Command {

#[tokio::test]
async fn parse() {
let sandbox = &TestEnv::new();
let sandbox = &TestEnv::default();
let id = &deploy_custom(sandbox).await;
extend_contract(sandbox, id).await;
symbol(sandbox, id);
Expand Down
6 changes: 3 additions & 3 deletions cmd/crates/soroban-test/tests/it/integration/dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn write_env_file(e: &TestEnv, contents: &str) {

#[tokio::test]
async fn can_read_file() {
let e = &TestEnv::new();
let e = &TestEnv::default();
std::thread::sleep(core::time::Duration::from_millis(1000));
let id = deploy_hello(e).await;
println!("{id}");
Expand All @@ -28,7 +28,7 @@ async fn can_read_file() {

#[tokio::test]
async fn current_env_not_overwritten() {
let e = TestEnv::new();
let e = TestEnv::default();
std::thread::sleep(core::time::Duration::from_millis(3000));
write_env_file(&e, &deploy_hello(&e).await);
e.new_assert_cmd("contract")
Expand All @@ -48,7 +48,7 @@ async fn current_env_not_overwritten() {

#[tokio::test]
async fn cli_args_have_priority() {
let e = &TestEnv::new();
let e = &TestEnv::default();
std::thread::sleep(core::time::Duration::from_millis(6000));
let id = deploy_hello(e).await;
write_env_file(e, &id);
Expand Down
Loading
Loading