Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/contract_aliases…
Browse files Browse the repository at this point in the history
…_in_sc_addr_parsing
  • Loading branch information
willemneal committed Dec 20, 2024
2 parents 68bab4e + 1c0d4e6 commit 52502e2
Show file tree
Hide file tree
Showing 29 changed files with 338 additions and 156 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ toml_edit = "0.22.20"
toml = "0.8.19"
reqwest = "0.12.7"
predicates = "3.1.2"
httpmock = "0.7.0"

[profile.test-wasms]
inherits = "release"
Expand Down
12 changes: 6 additions & 6 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ Create and manage identities including keys and addresses
* `generate` — Generate a new identity with a seed phrase, currently 12 words
* `ls` — List identities
* `rm` — Remove an identity
* `show`Given an identity return its private key
* `secret`Output an identity's secret key
* `use` — Set the default identity that will be used on all commands. This allows you to skip `--source-account` or setting a environment variable, while reusing this value in all commands that require it


Expand All @@ -961,8 +961,8 @@ Add a new identity (keypair, ledger, macOS keychain)

###### **Options:**

* `--secret-key`Add using `secret_key` Can provide with `SOROBAN_SECRET_KEY`
* `--seed-phrase`Add using 12 word seed phrase to generate `secret_key`
* `--secret-key`(deprecated) Enter secret (S) key when prompted
* `--seed-phrase`(deprecated) Enter key using 12-24 word seed phrase
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."

Expand Down Expand Up @@ -1069,11 +1069,11 @@ Remove an identity



## `stellar keys show`
## `stellar keys secret`

Given an identity return its private key
Output an identity's secret key

**Usage:** `stellar keys show [OPTIONS] <NAME>`
**Usage:** `stellar keys secret [OPTIONS] <NAME>`

###### **Arguments:**

Expand Down
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("./stellar", ["keys", "show", "root"], {
spawnSync("./soroban", ["keys", "secret", "root"], {
shell: true,
encoding: "utf8",
}).stdout.trim(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ predicates = { workspace = true }
fs_extra = "1.3.0"
toml = { workspace = true }


[dev-dependencies]
serde_json = "1.0.93"
which = { workspace = true }
Expand All @@ -42,6 +41,7 @@ walkdir = "2.4.0"
ulid.workspace = true
ed25519-dalek = { workspace = true }
hex = { workspace = true }
httpmock = { workspace = true }

[features]
it = []
47 changes: 35 additions & 12 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ pub enum Error {
/// its own `TempDir` where it will save test-specific configuration.
pub struct TestEnv {
pub temp_dir: TempDir,
pub rpc_url: String,
pub network_passphrase: String,
pub network: network::Network,
}

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(),
network_passphrase: LOCAL_NETWORK_PASSPHRASE.to_string(),
network: network::Network {
rpc_url: "http://localhost:8889/soroban/rpc".to_string(),
network_passphrase: LOCAL_NETWORK_PASSPHRASE.to_string(),
rpc_headers: [].to_vec(),
},
}
}
}
Expand Down Expand Up @@ -102,12 +104,21 @@ impl TestEnv {
}

pub fn with_rpc_url(rpc_url: &str) -> TestEnv {
let mut env = TestEnv {
rpc_url: rpc_url.to_string(),
..Default::default()
let mut env = TestEnv::default();
env.network.rpc_url = rpc_url.to_string();
if let Ok(network_passphrase) = std::env::var("STELLAR_NETWORK_PASSPHRASE") {
env.network.network_passphrase = network_passphrase;
};
env.generate_account("test", None).assert().success();
env
}

pub fn with_rpc_provider(rpc_url: &str, rpc_headers: Vec<(String, String)>) -> TestEnv {
let mut env = TestEnv::default();
env.network.rpc_url = rpc_url.to_string();
env.network.rpc_headers = rpc_headers;
if let Ok(network_passphrase) = std::env::var("STELLAR_NETWORK_PASSPHRASE") {
env.network_passphrase = network_passphrase;
env.network.network_passphrase = network_passphrase;
};
env.generate_account("test", None).assert().success();
env
Expand All @@ -131,13 +142,25 @@ impl TestEnv {
/// 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_RPC_URL", &self.network.rpc_url)
.env("SOROBAN_NETWORK_PASSPHRASE", LOCAL_NETWORK_PASSPHRASE)
.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);

if !self.network.rpc_headers.is_empty() {
cmd.env(
"STELLAR_RPC_HEADERS",
format!(
"{}:{}",
&self.network.rpc_headers[0].0, &self.network.rpc_headers[0].1
),
);
}

cmd
}

Expand Down Expand Up @@ -234,7 +257,7 @@ impl TestEnv {
let config_dir = Some(self.dir().to_path_buf());
config::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
rpc_url: Some(self.network.rpc_url.clone()),
rpc_headers: [].to_vec(),
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
Expand Down Expand Up @@ -285,7 +308,7 @@ impl TestEnv {

/// Returns the private key corresponding to the test keys's `hd_path`
pub fn test_show(&self, hd_path: usize) -> String {
self.cmd::<keys::show::Cmd>(&format!("--hd-path={hd_path}"))
self.cmd::<keys::secret::Cmd>(&format!("--hd-path={hd_path}"))
.private_key()
.unwrap()
.to_string()
Expand All @@ -305,7 +328,7 @@ impl TestEnv {
}

pub fn client(&self) -> soroban_rpc::Client {
soroban_rpc::Client::new(&self.rpc_url).unwrap()
self.network.rpc_client().unwrap()
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn use_env() {

sandbox
.new_assert_cmd("keys")
.arg("show")
.arg("secret")
.arg("bob")
.assert()
.success()
Expand Down Expand Up @@ -330,7 +330,7 @@ fn config_dirs_precedence() {

sandbox
.new_assert_cmd("keys")
.arg("show")
.arg("secret")
.arg("alice")
.arg("--verbose")
.assert()
Expand Down
4 changes: 2 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn invoke_test_generate_typescript_bindings() {
"--network-passphrase",
LOCAL_NETWORK_PASSPHRASE,
"--rpc-url",
&sandbox.rpc_url,
&sandbox.network.rpc_url,
"--output-dir",
&outdir.display().to_string(),
"--overwrite",
Expand Down Expand Up @@ -43,7 +43,7 @@ async fn invoke_test_bindings_context_failure() {
"--network-passphrase",
LOCAL_NETWORK_PASSPHRASE,
"--rpc-url",
&sandbox.rpc_url,
&sandbox.network.rpc_url,
"--output-dir",
&outdir.display().to_string(),
"--overwrite",
Expand Down
10 changes: 5 additions & 5 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn invoke_view_with_non_existent_source_account() {
#[allow(clippy::too_many_lines)]
async fn invoke() {
let sandbox = &TestEnv::new();
let c = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let c = sandbox.network.rpc_client().unwrap();
let GetLatestLedgerResponse { sequence, .. } = c.get_latest_ledger().await.unwrap();
sandbox
.new_assert_cmd("keys")
Expand All @@ -53,7 +53,7 @@ async fn invoke() {

let secret_key = sandbox
.new_assert_cmd("keys")
.arg("show")
.arg("secret")
.arg("test")
.assert()
.stdout_as_str();
Expand All @@ -65,7 +65,7 @@ async fn invoke() {
.stdout_as_str();
let secret_key_1 = sandbox
.new_assert_cmd("keys")
.arg("show")
.arg("secret")
.arg("test")
.arg("--hd-path=1")
.assert()
Expand Down Expand Up @@ -115,7 +115,7 @@ async fn invoke() {
assert_eq!(sk_from_file, format!("secret_key = \"{secret_key_1}\"\n"));
let secret_key_1_readin = sandbox
.new_assert_cmd("keys")
.arg("show")
.arg("secret")
.arg("testone")
.assert()
.stdout_as_str();
Expand Down Expand Up @@ -365,7 +365,7 @@ async fn fetch(sandbox: &TestEnv, id: &str) {
let f = sandbox.dir().join("contract.wasm");
let cmd = sandbox.cmd_arr::<fetch::Cmd>(&[
"--rpc-url",
&sandbox.rpc_url,
&sandbox.network.rpc_url,
"--network-passphrase",
LOCAL_NETWORK_PASSPHRASE,
"--id",
Expand Down
24 changes: 12 additions & 12 deletions cmd/crates/soroban-test/tests/it/integration/tx/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn create_account() {
.success()
.stdout_as_str();
let test = test_address(sandbox);
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let test_account = client.get_account(&test).await.unwrap();
println!("test account has a balance of {}", test_account.balance);
let starting_balance = ONE_XLM * 100;
Expand All @@ -92,7 +92,7 @@ async fn create_account() {
#[tokio::test]
async fn payment() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let (test, test1) = setup_accounts(sandbox);
let test_account = client.get_account(&test).await.unwrap();
println!("test account has a balance of {}", test_account.balance);
Expand Down Expand Up @@ -125,7 +125,7 @@ async fn payment() {
#[tokio::test]
async fn bump_sequence() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let test = test_address(sandbox);
let before = client.get_account(&test).await.unwrap();
let amount = 50;
Expand All @@ -148,7 +148,7 @@ async fn bump_sequence() {
#[tokio::test]
async fn account_merge() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let (test, test1) = setup_accounts(sandbox);
let before = client.get_account(&test).await.unwrap();
let before1 = client.get_account(&test1).await.unwrap();
Expand Down Expand Up @@ -188,7 +188,7 @@ async fn set_trustline_flags() {
.success();
let id = contract_id_hash_from_asset(
asset.parse::<builder::Asset>().unwrap(),
&sandbox.network_passphrase,
&sandbox.network.network_passphrase,
);
// sandbox
// .new_assert_cmd("contract")
Expand Down Expand Up @@ -224,7 +224,7 @@ async fn set_trustline_flags() {
#[tokio::test]
async fn set_options_add_signer() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let (test, test1) = setup_accounts(sandbox);
let before = client.get_account(&test).await.unwrap();
sandbox
Expand Down Expand Up @@ -286,7 +286,7 @@ fn build_and_run(sandbox: &TestEnv, cmd: &str, args: &[&str]) -> String {
#[tokio::test]
async fn set_options() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let (test, alice) = setup_accounts(sandbox);
let before = client.get_account(&test).await.unwrap();
assert!(before.inflation_dest.is_none());
Expand Down Expand Up @@ -356,7 +356,7 @@ async fn set_options() {
#[tokio::test]
async fn set_some_options() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let test = test_address(sandbox);
let before = client.get_account(&test).await.unwrap();
assert!(before.inflation_dest.is_none());
Expand Down Expand Up @@ -451,7 +451,7 @@ async fn change_trust() {
// wrap_cmd(&asset).run().await.unwrap();
let id = contract_id_hash_from_asset(
asset.parse::<builder::Asset>().unwrap(),
&sandbox.network_passphrase,
&sandbox.network.network_passphrase,
);
sandbox
.new_assert_cmd("contract")
Expand Down Expand Up @@ -529,7 +529,7 @@ async fn change_trust() {
async fn manage_data() {
let sandbox = &TestEnv::new();
let (test, _) = setup_accounts(sandbox);
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let key = "test";
let value = "beefface";
sandbox
Expand Down Expand Up @@ -573,7 +573,7 @@ async fn manage_data() {
}

async fn issue_asset(sandbox: &TestEnv, test: &str, asset: &str, limit: u64, initial_balance: u64) {
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let test_before = client.get_account(test).await.unwrap();
sandbox
.new_assert_cmd("tx")
Expand Down Expand Up @@ -633,7 +633,7 @@ async fn issue_asset(sandbox: &TestEnv, test: &str, asset: &str, limit: u64, ini
#[tokio::test]
async fn multi_create_accounts() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let client = sandbox.network.rpc_client().unwrap();
let nums: Vec<u8> = (1..=3).collect();
let mut accounts: Vec<(String, String)> = nums
.iter()
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ mod init;
// #[cfg(feature = "it")]
mod integration;
mod plugin;
mod rpc_provider;
mod util;
mod version;
Loading

0 comments on commit 52502e2

Please sign in to comment.