Skip to content

Commit

Permalink
Change the default devnet data dir (#3570)
Browse files Browse the repository at this point in the history
* Change the default devnet data dir

* format code

* remove unnecessary clone

* recode: add --data-dir TMP as a option

* clean code

* add --data-dir TMP in dev test

* change config tests

* cargo clippy
  • Loading branch information
YouNeedWork authored Jul 29, 2022
1 parent eef95e5 commit 6de02c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
17 changes: 8 additions & 9 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,20 @@ pub struct BaseConfig {
impl BaseConfig {
pub fn load_with_opt(opt: &StarcoinOpt) -> Result<Self> {
let id = opt.net.clone().unwrap_or_default();
let base_data_dir = opt.base_data_dir.clone();
let base_data_dir = match base_data_dir {
Some(base_data_dir) => DataDirPath::PathBuf(base_data_dir),
None => {
if id.is_dev() || id.is_test() {
temp_dir()
} else {
DataDirPath::PathBuf(G_DEFAULT_BASE_DATA_DIR.to_path_buf())
}
let base_data_dir = if id.is_test() {
temp_dir()
} else {
match opt.base_data_dir.clone() {
Some(base_data_dir) if base_data_dir.to_str() == Some("TMP") => temp_dir(),
_ => DataDirPath::PathBuf(G_DEFAULT_BASE_DATA_DIR.to_path_buf()),
}
};

let data_dir = base_data_dir.as_ref().join(id.dir_name());
if !data_dir.exists() {
create_dir_all(data_dir.as_path())?;
}

let genesis_config = Self::load_genesis_config_by_opt(
id.clone(),
data_dir.as_path(),
Expand Down
32 changes: 22 additions & 10 deletions config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ use starcoin_vm_types::gas_schedule::GasAlgebra;
#[test]
fn test_generate_and_load() -> Result<()> {
for net in BuiltinNetworkID::networks() {
let mut opt = StarcoinOpt::default();
let temp_path = temp_dir();
opt.net = Some(net.into());
opt.base_data_dir = Some(temp_path.path().to_path_buf());
let opt = StarcoinOpt {
net: Some(net.into()),
base_data_dir: Some(temp_dir().path().to_path_buf()),
..Default::default()
};

let config = NodeConfig::load_with_opt(&opt)?;
let config2 = NodeConfig::load_with_opt(&opt)?;
assert_eq!(
to_toml(&config)?,
to_toml(&config2)?,
"test config for network {} fail.",
net
);

if net == BuiltinNetworkID::Test {
assert_ne!(
to_toml(&config)?,
to_toml(&config2)?,
"test config for network {} fail.",
net
);
} else {
assert_eq!(
to_toml(&config)?,
to_toml(&config2)?,
"test config for network {} fail.",
net
);
}
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions testsuite/tests/steps/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn steps() -> Steps<MyWorld> {
let mut opt = StarcoinOpt::default();
opt.net = Some(ChainNetworkID::DEV);
opt.metrics.disable_metrics = Some(false);
opt.base_data_dir = Some(PathBuf::from(r"TMP"));
let config = NodeConfig::load_with_opt(&opt).unwrap();
world.node_config = Some(config)
})
Expand Down

0 comments on commit 6de02c7

Please sign in to comment.