Skip to content

Commit

Permalink
feat: add --network testnet default setting
Browse files Browse the repository at this point in the history
Similar to how we support `--network futurenet` before you even set it.

No need to make people go look it up on https://developers.stellar.org/docs/reference/networks
  • Loading branch information
chadoh committed Jun 27, 2024
1 parent dba96f3 commit bff30ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
30 changes: 30 additions & 0 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ fn set_and_remove_network() {
});
}

#[test]
fn use_default_futurenet() {
TestEnv::with_default(|sandbox| {
sandbox
.new_assert_cmd("keys")
.args(["generate", "alice", "--network", "futurenet"])
.assert()
.success();
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(), "futurenet.toml");
});
}

#[test]
fn use_default_testnet() {
TestEnv::with_default(|sandbox| {
sandbox
.new_assert_cmd("keys")
.args(["generate", "alice", "--network", "testnet"])
.assert()
.success();
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(), "testnet.toml");
});
}

fn add_network(sandbox: &TestEnv, name: &str) {
sandbox
.new_assert_cmd("network")
Expand Down
16 changes: 12 additions & 4 deletions cmd/soroban-cli/src/commands/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,18 @@ impl Args {
pub fn read_network(&self, name: &str) -> Result<Network, Error> {
let res = KeyType::Network.read_with_global(name, &self.local_config()?);
if let Err(Error::ConfigMissing(_, _)) = &res {
if name == "futurenet" {
let network = Network::futurenet();
self.write_network(name, &network)?;
return Ok(network);
match name {
"futurenet" => {
let network = Network::futurenet();
self.write_network(name, &network)?;
return Ok(network);
}
"testnet" => {
let network = Network::testnet();
self.write_network(name, &network)?;
return Ok(network);
}
_ => {}
}
}
res
Expand Down
6 changes: 6 additions & 0 deletions cmd/soroban-cli/src/commands/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ impl Network {

impl Network {
pub fn futurenet() -> Self {
Network {
rpc_url: "https://soroban-testnet.stellar.org".to_owned(),
network_passphrase: "Test SDF Network ; September 2015".to_owned(),
}
}
pub fn testnet() -> Self {
Network {
rpc_url: "https://rpc-futurenet.stellar.org:443".to_owned(),
network_passphrase: "Test SDF Future Network ; October 2022".to_owned(),
Expand Down

0 comments on commit bff30ea

Please sign in to comment.