Skip to content
Merged
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
33 changes: 32 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use predicates::prelude::{predicate, PredicateBooleanExt};
use soroban_test::TestEnv;
use soroban_test::{AssertExt, TestEnv};

#[tokio::test]
#[allow(clippy::too_many_lines)]
Expand Down Expand Up @@ -52,3 +52,34 @@ async fn unset_default_network() {
.stdout(predicate::str::contains("STELLAR_NETWORK=").not())
.success();
}

#[tokio::test]
async fn network_info_includes_id_in_text_output() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("network")
.arg("info")
.assert()
.success()
.stderr(predicate::str::contains(
"Network Id: baefd734b8d3e48472cff83912375fedbc7573701912fe308af730180f97d74a",
));
}

#[tokio::test]
async fn network_info_includes_id_in_json_output() {
let sandbox = &TestEnv::new();
let output = sandbox
.new_assert_cmd("network")
.arg("info")
.arg("--output")
.arg("json")
.assert()
.success()
.stdout_as_str();
let info: serde_json::Value = serde_json::from_str(&output).unwrap();
assert_eq!(
info["id"],
"baefd734b8d3e48472cff83912375fedbc7573701912fe308af730180f97d74a"
);
}
6 changes: 6 additions & 0 deletions cmd/soroban-cli/src/commands/network/info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use sha2::{Digest, Sha256};

use crate::commands::global;
use crate::config::network;
use crate::{config, print, rpc};
Expand Down Expand Up @@ -37,6 +39,7 @@ pub struct Cmd {

#[derive(serde::Deserialize, serde::Serialize)]
struct Info {
pub id: String,
pub version: String,
pub commit_hash: String,
pub build_timestamp: String,
Expand All @@ -48,6 +51,7 @@ struct Info {

impl Info {
fn print_text(&self, print: &print::Print) {
print.infoln(format!("Network Id: {}", self.id));
print.infoln(format!("Version: {}", self.version));
print.infoln(format!("Commit Hash: {}", self.commit_hash));
print.infoln(format!("Build Timestamp: {}", self.build_timestamp));
Expand Down Expand Up @@ -81,7 +85,9 @@ impl Cmd {
let rpc_client = self.config.get_network()?.rpc_client()?;
let network_result = rpc_client.get_network().await?;
let version_result = rpc_client.get_version_info().await?;
let id = hex::encode(Sha256::digest(network_result.passphrase.as_bytes()));
let info = Info {
id,
version: version_result.version,
commit_hash: version_result.commmit_hash,
build_timestamp: version_result.build_timestamp,
Expand Down