2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-07-25 16:09:47 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-07-10 12:57:40 +02:00
|
|
|
use std::{str, fs, fmt, path};
|
2016-07-25 16:09:47 +02:00
|
|
|
use std::time::Duration;
|
2016-09-26 19:21:25 +02:00
|
|
|
use util::{Address, U256, version_data};
|
2016-07-25 16:09:47 +02:00
|
|
|
use util::journaldb::Algorithm;
|
|
|
|
use ethcore::spec::Spec;
|
2016-11-14 11:04:34 +01:00
|
|
|
use ethcore::ethereum;
|
2016-11-05 10:38:00 +01:00
|
|
|
use ethcore::client::Mode;
|
2016-07-25 16:09:47 +02:00
|
|
|
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
|
2016-09-26 19:21:25 +02:00
|
|
|
use user_defaults::UserDefaults;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum SpecType {
|
2017-03-03 13:33:49 +01:00
|
|
|
Foundation,
|
2016-12-30 15:52:49 +01:00
|
|
|
Morden,
|
2016-11-20 16:38:45 +01:00
|
|
|
Ropsten,
|
2017-03-02 20:24:27 +01:00
|
|
|
Kovan,
|
2016-07-25 16:09:47 +02:00
|
|
|
Olympic,
|
|
|
|
Classic,
|
2016-09-28 14:21:59 +02:00
|
|
|
Expanse,
|
2016-11-11 18:27:20 +01:00
|
|
|
Dev,
|
2016-07-25 16:09:47 +02:00
|
|
|
Custom(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SpecType {
|
|
|
|
fn default() -> Self {
|
2017-03-03 13:33:49 +01:00
|
|
|
SpecType::Foundation
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
impl str::FromStr for SpecType {
|
2016-07-25 16:09:47 +02:00
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
let spec = match s {
|
2017-03-03 13:33:49 +01:00
|
|
|
"foundation" | "frontier" | "homestead" | "mainnet" => SpecType::Foundation,
|
2016-07-25 16:09:47 +02:00
|
|
|
"frontier-dogmatic" | "homestead-dogmatic" | "classic" => SpecType::Classic,
|
2016-12-30 15:52:49 +01:00
|
|
|
"morden" | "classic-testnet" => SpecType::Morden,
|
2017-03-02 20:24:27 +01:00
|
|
|
"ropsten" => SpecType::Ropsten,
|
|
|
|
"kovan" | "testnet" => SpecType::Kovan,
|
2016-07-25 16:09:47 +02:00
|
|
|
"olympic" => SpecType::Olympic,
|
2016-09-28 14:21:59 +02:00
|
|
|
"expanse" => SpecType::Expanse,
|
2016-11-11 18:27:20 +01:00
|
|
|
"dev" => SpecType::Dev,
|
2016-07-25 16:09:47 +02:00
|
|
|
other => SpecType::Custom(other.into()),
|
|
|
|
};
|
|
|
|
Ok(spec)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:51:27 +01:00
|
|
|
impl fmt::Display for SpecType {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.write_str(match *self {
|
2017-03-03 13:33:49 +01:00
|
|
|
SpecType::Foundation => "foundation",
|
2017-01-04 16:51:27 +01:00
|
|
|
SpecType::Morden => "morden",
|
|
|
|
SpecType::Ropsten => "ropsten",
|
|
|
|
SpecType::Olympic => "olympic",
|
|
|
|
SpecType::Classic => "classic",
|
|
|
|
SpecType::Expanse => "expanse",
|
2017-03-02 20:24:27 +01:00
|
|
|
SpecType::Kovan => "kovan",
|
2017-01-04 16:51:27 +01:00
|
|
|
SpecType::Dev => "dev",
|
|
|
|
SpecType::Custom(ref custom) => custom,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
impl SpecType {
|
2017-07-10 12:57:40 +02:00
|
|
|
pub fn spec<T: AsRef<path::Path>>(&self, cache_dir: T) -> Result<Spec, String> {
|
|
|
|
let cache_dir = cache_dir.as_ref();
|
2016-07-25 16:09:47 +02:00
|
|
|
match *self {
|
2017-07-10 12:57:40 +02:00
|
|
|
SpecType::Foundation => Ok(ethereum::new_foundation(cache_dir)),
|
|
|
|
SpecType::Morden => Ok(ethereum::new_morden(cache_dir)),
|
|
|
|
SpecType::Ropsten => Ok(ethereum::new_ropsten(cache_dir)),
|
|
|
|
SpecType::Olympic => Ok(ethereum::new_olympic(cache_dir)),
|
|
|
|
SpecType::Classic => Ok(ethereum::new_classic(cache_dir)),
|
|
|
|
SpecType::Expanse => Ok(ethereum::new_expanse(cache_dir)),
|
|
|
|
SpecType::Kovan => Ok(ethereum::new_kovan(cache_dir)),
|
2016-11-11 18:27:20 +01:00
|
|
|
SpecType::Dev => Ok(Spec::new_instant()),
|
2016-09-05 17:41:34 +02:00
|
|
|
SpecType::Custom(ref filename) => {
|
2017-07-10 12:57:40 +02:00
|
|
|
let file = fs::File::open(filename).map_err(|e| format!("Could not load specification file at {}: {}", filename, e))?;
|
|
|
|
Spec::load(cache_dir, file)
|
2016-09-05 17:41:34 +02:00
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-12 16:51:07 +01:00
|
|
|
|
|
|
|
pub fn legacy_fork_name(&self) -> Option<String> {
|
|
|
|
match *self {
|
|
|
|
SpecType::Classic => Some("classic".to_owned()),
|
|
|
|
SpecType::Expanse => Some("expanse".to_owned()),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum Pruning {
|
|
|
|
Specific(Algorithm),
|
|
|
|
Auto,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Pruning {
|
|
|
|
fn default() -> Self {
|
|
|
|
Pruning::Auto
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
impl str::FromStr for Pruning {
|
2016-07-25 16:09:47 +02:00
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"auto" => Ok(Pruning::Auto),
|
|
|
|
other => other.parse().map(Pruning::Specific),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Pruning {
|
2016-09-26 19:21:25 +02:00
|
|
|
pub fn to_algorithm(&self, user_defaults: &UserDefaults) -> Algorithm {
|
2016-07-25 16:09:47 +02:00
|
|
|
match *self {
|
|
|
|
Pruning::Specific(algo) => algo,
|
2016-09-26 19:21:25 +02:00
|
|
|
Pruning::Auto => user_defaults.pruning,
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct ResealPolicy {
|
|
|
|
pub own: bool,
|
|
|
|
pub external: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ResealPolicy {
|
|
|
|
fn default() -> Self {
|
|
|
|
ResealPolicy {
|
|
|
|
own: true,
|
|
|
|
external: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
impl str::FromStr for ResealPolicy {
|
2016-07-25 16:09:47 +02:00
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
let (own, external) = match s {
|
|
|
|
"none" => (false, false),
|
|
|
|
"own" => (true, false),
|
|
|
|
"ext" => (false, true),
|
|
|
|
"all" => (true, true),
|
|
|
|
x => return Err(format!("Invalid reseal value: {}", x)),
|
|
|
|
};
|
|
|
|
|
|
|
|
let reseal = ResealPolicy {
|
|
|
|
own: own,
|
|
|
|
external: external,
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(reseal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct AccountsConfig {
|
|
|
|
pub iterations: u32,
|
|
|
|
pub testnet: bool,
|
|
|
|
pub password_files: Vec<String>,
|
|
|
|
pub unlocked_accounts: Vec<Address>,
|
2017-02-10 01:07:06 +01:00
|
|
|
pub enable_hardware_wallets: bool,
|
2017-06-06 18:06:40 +02:00
|
|
|
pub enable_fast_unlock: bool,
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AccountsConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
AccountsConfig {
|
|
|
|
iterations: 10240,
|
|
|
|
testnet: false,
|
|
|
|
password_files: Vec::new(),
|
|
|
|
unlocked_accounts: Vec::new(),
|
2017-02-10 01:07:06 +01:00
|
|
|
enable_hardware_wallets: true,
|
2017-06-06 18:06:40 +02:00
|
|
|
enable_fast_unlock: false,
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum GasPricerConfig {
|
|
|
|
Fixed(U256),
|
|
|
|
Calibrated {
|
2017-01-18 19:44:24 +01:00
|
|
|
initial_minimum: U256,
|
2016-07-25 16:09:47 +02:00
|
|
|
usd_per_tx: f32,
|
|
|
|
recalibration_period: Duration,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 19:44:24 +01:00
|
|
|
impl GasPricerConfig {
|
|
|
|
pub fn initial_min(&self) -> U256 {
|
|
|
|
match *self {
|
|
|
|
GasPricerConfig::Fixed(ref min) => min.clone(),
|
|
|
|
GasPricerConfig::Calibrated { ref initial_minimum, .. } => initial_minimum.clone(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
impl Default for GasPricerConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
GasPricerConfig::Calibrated {
|
2017-01-18 19:44:24 +01:00
|
|
|
initial_minimum: 11904761856u64.into(),
|
2016-11-25 15:12:57 +01:00
|
|
|
usd_per_tx: 0.0025f32,
|
2016-07-25 16:09:47 +02:00
|
|
|
recalibration_period: Duration::from_secs(3600),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<GasPricer> for GasPricerConfig {
|
|
|
|
fn into(self) -> GasPricer {
|
|
|
|
match self {
|
|
|
|
GasPricerConfig::Fixed(u) => GasPricer::Fixed(u),
|
2017-01-18 19:44:24 +01:00
|
|
|
GasPricerConfig::Calibrated { usd_per_tx, recalibration_period, .. } => {
|
2016-07-25 16:09:47 +02:00
|
|
|
GasPricer::new_calibrated(GasPriceCalibratorOptions {
|
|
|
|
usd_per_tx: usd_per_tx,
|
|
|
|
recalibration_period: recalibration_period,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct MinerExtras {
|
|
|
|
pub author: Address,
|
|
|
|
pub extra_data: Vec<u8>,
|
|
|
|
pub gas_floor_target: U256,
|
|
|
|
pub gas_ceil_target: U256,
|
|
|
|
pub transactions_limit: usize,
|
2016-12-05 22:31:38 +01:00
|
|
|
pub engine_signer: Address,
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MinerExtras {
|
|
|
|
fn default() -> Self {
|
|
|
|
MinerExtras {
|
|
|
|
author: Default::default(),
|
|
|
|
extra_data: version_data(),
|
|
|
|
gas_floor_target: U256::from(4_700_000),
|
|
|
|
gas_ceil_target: U256::from(6_283_184),
|
2016-10-15 14:46:33 +02:00
|
|
|
transactions_limit: 1024,
|
2016-12-05 22:31:38 +01:00
|
|
|
engine_signer: Default::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
/// 3-value enum.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum Switch {
|
|
|
|
/// True.
|
|
|
|
On,
|
|
|
|
/// False.
|
|
|
|
Off,
|
|
|
|
/// Auto.
|
|
|
|
Auto,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Switch {
|
|
|
|
fn default() -> Self {
|
|
|
|
Switch::Auto
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl str::FromStr for Switch {
|
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"on" => Ok(Switch::On),
|
|
|
|
"off" => Ok(Switch::Off),
|
|
|
|
"auto" => Ok(Switch::Auto),
|
|
|
|
other => Err(format!("Invalid switch value: {}", other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tracing_switch_to_bool(switch: Switch, user_defaults: &UserDefaults) -> Result<bool, String> {
|
|
|
|
match (user_defaults.is_first_launch, switch, user_defaults.tracing) {
|
|
|
|
(false, Switch::On, false) => Err("TraceDB resync required".into()),
|
|
|
|
(_, Switch::On, _) => Ok(true),
|
|
|
|
(_, Switch::Off, _) => Ok(false),
|
|
|
|
(_, Switch::Auto, def) => Ok(def),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 12:58:14 +01:00
|
|
|
pub fn fatdb_switch_to_bool(switch: Switch, user_defaults: &UserDefaults, _algorithm: Algorithm) -> Result<bool, String> {
|
2016-10-03 19:31:50 +02:00
|
|
|
let result = match (user_defaults.is_first_launch, switch, user_defaults.fat_db) {
|
2016-10-03 11:13:10 +02:00
|
|
|
(false, Switch::On, false) => Err("FatDB resync required".into()),
|
|
|
|
(_, Switch::On, _) => Ok(true),
|
|
|
|
(_, Switch::Off, _) => Ok(false),
|
|
|
|
(_, Switch::Auto, def) => Ok(def),
|
2016-10-03 19:31:50 +02:00
|
|
|
};
|
|
|
|
result
|
2016-10-03 11:13:10 +02:00
|
|
|
}
|
|
|
|
|
2016-11-05 10:38:00 +01:00
|
|
|
pub fn mode_switch_to_bool(switch: Option<Mode>, user_defaults: &UserDefaults) -> Result<Mode, String> {
|
|
|
|
Ok(switch.unwrap_or(user_defaults.mode.clone()))
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use util::journaldb::Algorithm;
|
2016-09-26 19:21:25 +02:00
|
|
|
use user_defaults::UserDefaults;
|
|
|
|
use super::{SpecType, Pruning, ResealPolicy, Switch, tracing_switch_to_bool};
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_spec_type_parsing() {
|
2017-03-03 13:33:49 +01:00
|
|
|
assert_eq!(SpecType::Foundation, "frontier".parse().unwrap());
|
|
|
|
assert_eq!(SpecType::Foundation, "homestead".parse().unwrap());
|
|
|
|
assert_eq!(SpecType::Foundation, "mainnet".parse().unwrap());
|
|
|
|
assert_eq!(SpecType::Foundation, "foundation".parse().unwrap());
|
2017-03-02 20:24:27 +01:00
|
|
|
assert_eq!(SpecType::Kovan, "testnet".parse().unwrap());
|
|
|
|
assert_eq!(SpecType::Kovan, "kovan".parse().unwrap());
|
2016-12-30 15:52:49 +01:00
|
|
|
assert_eq!(SpecType::Morden, "morden".parse().unwrap());
|
2016-11-20 16:38:45 +01:00
|
|
|
assert_eq!(SpecType::Ropsten, "ropsten".parse().unwrap());
|
2016-07-25 16:09:47 +02:00
|
|
|
assert_eq!(SpecType::Olympic, "olympic".parse().unwrap());
|
2016-12-11 14:25:02 +01:00
|
|
|
assert_eq!(SpecType::Classic, "classic".parse().unwrap());
|
2016-12-30 15:52:49 +01:00
|
|
|
assert_eq!(SpecType::Morden, "classic-testnet".parse().unwrap());
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_spec_type_default() {
|
2017-03-03 13:33:49 +01:00
|
|
|
assert_eq!(SpecType::Foundation, SpecType::default());
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:51:27 +01:00
|
|
|
#[test]
|
|
|
|
fn test_spec_type_display() {
|
2017-03-03 13:33:49 +01:00
|
|
|
assert_eq!(format!("{}", SpecType::Foundation), "foundation");
|
2017-01-04 16:51:27 +01:00
|
|
|
assert_eq!(format!("{}", SpecType::Ropsten), "ropsten");
|
|
|
|
assert_eq!(format!("{}", SpecType::Morden), "morden");
|
|
|
|
assert_eq!(format!("{}", SpecType::Olympic), "olympic");
|
|
|
|
assert_eq!(format!("{}", SpecType::Classic), "classic");
|
|
|
|
assert_eq!(format!("{}", SpecType::Expanse), "expanse");
|
2017-03-02 20:24:27 +01:00
|
|
|
assert_eq!(format!("{}", SpecType::Kovan), "kovan");
|
2017-01-04 16:51:27 +01:00
|
|
|
assert_eq!(format!("{}", SpecType::Dev), "dev");
|
|
|
|
assert_eq!(format!("{}", SpecType::Custom("foo/bar".into())), "foo/bar");
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[test]
|
|
|
|
fn test_pruning_parsing() {
|
|
|
|
assert_eq!(Pruning::Auto, "auto".parse().unwrap());
|
|
|
|
assert_eq!(Pruning::Specific(Algorithm::Archive), "archive".parse().unwrap());
|
|
|
|
assert_eq!(Pruning::Specific(Algorithm::EarlyMerge), "light".parse().unwrap());
|
|
|
|
assert_eq!(Pruning::Specific(Algorithm::OverlayRecent), "fast".parse().unwrap());
|
|
|
|
assert_eq!(Pruning::Specific(Algorithm::RefCounted), "basic".parse().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_pruning_default() {
|
|
|
|
assert_eq!(Pruning::Auto, Pruning::default());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_reseal_policy_parsing() {
|
|
|
|
let none = ResealPolicy { own: false, external: false };
|
|
|
|
let own = ResealPolicy { own: true, external: false };
|
|
|
|
let ext = ResealPolicy { own: false, external: true };
|
|
|
|
let all = ResealPolicy { own: true, external: true };
|
|
|
|
assert_eq!(none, "none".parse().unwrap());
|
|
|
|
assert_eq!(own, "own".parse().unwrap());
|
|
|
|
assert_eq!(ext, "ext".parse().unwrap());
|
|
|
|
assert_eq!(all, "all".parse().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_reseal_policy_default() {
|
|
|
|
let all = ResealPolicy { own: true, external: true };
|
|
|
|
assert_eq!(all, ResealPolicy::default());
|
|
|
|
}
|
2016-09-26 19:21:25 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_switch_parsing() {
|
|
|
|
assert_eq!(Switch::On, "on".parse().unwrap());
|
|
|
|
assert_eq!(Switch::Off, "off".parse().unwrap());
|
|
|
|
assert_eq!(Switch::Auto, "auto".parse().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_switch_default() {
|
|
|
|
assert_eq!(Switch::default(), Switch::Auto);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn user_defaults_with_tracing(first_launch: bool, tracing: bool) -> UserDefaults {
|
|
|
|
let mut ud = UserDefaults::default();
|
|
|
|
ud.is_first_launch = first_launch;
|
|
|
|
ud.tracing = tracing;
|
|
|
|
ud
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_switch_to_bool() {
|
|
|
|
assert!(!tracing_switch_to_bool(Switch::Off, &user_defaults_with_tracing(true, true)).unwrap());
|
|
|
|
assert!(!tracing_switch_to_bool(Switch::Off, &user_defaults_with_tracing(true, false)).unwrap());
|
|
|
|
assert!(!tracing_switch_to_bool(Switch::Off, &user_defaults_with_tracing(false, true)).unwrap());
|
|
|
|
assert!(!tracing_switch_to_bool(Switch::Off, &user_defaults_with_tracing(false, false)).unwrap());
|
|
|
|
|
|
|
|
assert!(tracing_switch_to_bool(Switch::On, &user_defaults_with_tracing(true, true)).unwrap());
|
|
|
|
assert!(tracing_switch_to_bool(Switch::On, &user_defaults_with_tracing(true, false)).unwrap());
|
|
|
|
assert!(tracing_switch_to_bool(Switch::On, &user_defaults_with_tracing(false, true)).unwrap());
|
|
|
|
assert!(tracing_switch_to_bool(Switch::On, &user_defaults_with_tracing(false, false)).is_err());
|
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|