Skip to content

Commit

Permalink
env add test net (#846)
Browse files Browse the repository at this point in the history
* fix env

* fix test fun name
  • Loading branch information
wow-sven authored Sep 21, 2023
1 parent 529a876 commit abd6a90
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
10 changes: 10 additions & 0 deletions crates/rooch-rpc-client/src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use serde_with::serde_as;
use std::fmt::{Display, Formatter, Write};

pub const DEFAULT_EXPIRATION_SECS: u64 = 30;
pub const ROOCH_TEST_NET_URL: &str = "https://seed-testnet.rooch.network/";

#[serde_as]
#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -89,6 +90,15 @@ impl Env {

builder.build(&self.rpc).await
}

pub fn testnet() -> Self {
Self {
chain_id: RoochChainID::TEST.chain_id().id(),
alias: "test".to_string(),
rpc: ROOCH_TEST_NET_URL.into(),
ws: None,
}
}
}

impl Default for Env {
Expand Down
8 changes: 4 additions & 4 deletions crates/rooch/src/commands/env/commands/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ pub struct SwitchCommand {
#[clap(flatten)]
pub context_options: WalletContextOptions,
#[clap(long)]
env: String,
alias: String,
}

impl SwitchCommand {
pub async fn execute(self) -> RoochResult<()> {
let mut context = self.context_options.build().await?;
let env = Some(self.env.clone());
let env = Some(self.alias.clone());

if context.config.get_env(&env).is_none() {
return Err(RoochError::SwitchEnvError(format!(
"The environment config for `{}` does not exist",
self.env
self.alias
)));
}

Expand All @@ -31,7 +31,7 @@ impl SwitchCommand {

println!(
"The active environment was successfully switched to `{}`",
self.env
self.alias
);

Ok(())
Expand Down
24 changes: 16 additions & 8 deletions crates/rooch/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ impl CommandAction<String> for Init {
// Prompt user for connect to devnet fullnode if config does not exist.
if !client_config_path.exists() {
let env = match std::env::var_os("ROOCH_CONFIG_WITH_RPC_URL") {
Some(v) => Some(Env {
//TODO get chain id from env
chain_id: RoochChainID::DEV.chain_id().id(),
alias: "custom".to_string(),
rpc: v.into_string().unwrap(),
ws: None,
}),
Some(v) => {
let chain_url: Vec<String> = v
.into_string()
.unwrap()
.split(',')
.map(|s| s.to_owned())
.collect();
Some(Env {
chain_id: chain_url[0].parse().unwrap(),
alias: "custom".to_string(),
rpc: chain_url[1].to_owned(),
ws: None,
})
}

None => {
println!(
"Creating config file [{:?}] with server and rooch native validator.",
Expand Down Expand Up @@ -119,7 +127,7 @@ impl CommandAction<String> for Init {
let alias = env.alias.clone();
ClientConfig {
keystore,
envs: vec![env],
envs: vec![env, Env::testnet()],
active_address: Some(new_address),
active_env: Some(alias),
}
Expand Down

0 comments on commit abd6a90

Please sign in to comment.