aa8487c1d0
* fix broken sync * correct seal fields * ethcore: fix comment * parity: remove duplicate params * clique: fix whitespaces * ethcore: fix goerli chain spec * refactor signer_snapshot into pending/finalized state * move close_block_extra_data after seal is applied * refactor most of the logic into the signer_snapshot * clique: refactor locking logic out of the consensus engine interface * Fix jsonspec and add an unittest * Replace space with tabs * Unbroke sync * Fix broken sync * 1/2 state tracking without votes * 2/2 implement vote tracking * ci: use travis for goerli * ci: setup a clique network * ci: sync a görli node * add clique deploy script * ci: fix paths in clique deploy script * ci: use docker compose * ci: fix travis job names * ci: fix build deps * ci: massively reduce tests * Revert "ci: massively reduce tests" This reverts commit 6369f0b069ed2607a7e9f2e1d85489bacdc43384. * ci: run cargo test directly * ci: separate build and test stages * ci: cache rust installation * ci: simplify ci stages * ci: make clique deploy script executable * ci: shutdown goerli sync after 20min * ci: remove slow sync stage * ci: use timeout to finish jobs * ci: fix build path * ci: use absolute paths to end this confusion * ci: add geth and parity to path * ci: be more verbose * ci: allow for more relaxed caching timeout * ci: update repositories for custom ppa * ci: fix typo in file name * ci: fix docker compose file * ci: add ethkey to docker * ci: make sure deploy script is up to date with upstream * ci: stop docker container after certain time * ci: force superuser to update permissions on docker files * ci: reduce run time of script to ~30 min * ci: remove duplicate caching in travis * remove trace statements * clique: add more validation involving the recent signer list * ethcore: enable constantinople for rinkeby * ethcore: fix whitespaces in rinkeby spec * ethcore: reformat goerli.json * Revert "ci: remove duplicate caching in travis" This reverts commit a562838d3d194d37f9871dcbe00b783637978f89. * tmp commit * another tmp commit * it builds! * add sealing capabilities * add seal_header hook to allow separation of block seal/importing code paths * clique: remove populate_from_parent. * add panic * make turn delay random * initialize OpenBlock properly in 'enact' * misc: remove duplicate lines * misc: fix license headers * misc: convert spaces to tabs * misc: fix tabs * Update Cargo.toml * Update Cargo.toml * Update Cargo.toml * clique: ensure validator restores state before trying to seal * clique: make 'state' return an Error. Make some error messages more clear * Fix compile error after rebase & toolchain upgrade * fix a bunch of import warnings * Refactor code * Fix permissions * Refactoring syncing * Implement full validator checks * Refactor util functions to seperate file * mining 1 * ethcore: add chainspec for kotti * ethcore: rename pre-goerli configs * ethcore: load kotti chain spec * cli: add kotti to params * Implement working local sealing * making sealing & syncing work together * Relax timestamp checking * ethcore: prepare for the real goerli to launch * Implement NOTURN wiggle properly & cleanupnup warnings * Implement vote casting * Update docs & skip signing if no signer * Optimize step-service interval * Record state on local sealed block * Fix script filemode * Cleaning up codebase * restore enact trace logging * Delete clique.sh and move sync.sh * remove travis.yml * Remove dead code * Cleanup compile warning * address review comments * adding more comments and removing unwrap() * ci: remove sync script * Address review comments * fix compile error * adding better debugging for timing * Implement an dedicated thread for sealing timing * fix(add helper for timestamp overflows) (#10330) * fix(add helper timestamp overflows) * fix(simplify code) * fix(make helper private) * snap: official image / test (#10168) * official image / test * fix / test * bit more necromancy * fix paths * add source bin/df /test * add source bin/df /test2 * something w paths /test * something w paths /test * add source-type /test * show paths /test * copy plugin /test * plugin -> nil * install rhash * no questions while installing rhash * publish snap only for release * fix(docker): fix not receives SIGINT (#10059) * fix(docker): fix not receives SIGINT * fix: update with reviews * update with review * update * update * Don't add discovery initiators to the node table (#10305) * Don't add discovery initiators to the node table * Use enums for tracking state of the nodes in discovery * Dont try to ping ourselves * Fix minor nits * Update timeouts when observing an outdated node * Extracted update_bucket_record from update_node * Fixed typo * Fix two final nits from @todr * change docker image based on debian instead of ubuntu due to the chan… (#10336) * change docker image based on debian instead of ubuntu due to the changes of the build container * role back docker build image and docker deploy image to ubuntu:xenial based (#10338) * Bundle protocol and packet_id together in chain sync (#10315) Define a new `enum` where devp2p subprotocol packet ids (currently eth and par) are defined. Additionally provide functionality to query id value and protocol of a given id object. * snap: prefix version and populate candidate channel (#10343) * snap: populate candidate releases with beta snaps to avoid stale channel * snap: prefix version with v* * addressing review comments * engine: fix copyright header * scripts: restore permissions on sign command * ethcore: enforce tabs * ethcore: enforce tabs * ethcore: enforce tabs * addressing comments * addressing comments * addressing more comments * addressing more comments * addressing more comments * addressing more comments * addressing more comments * json-spec: fix clique epoch to non-zero u64 * ci: enable travis for parity goerli * ci: don't separate build and test step * ci: don't run c++ tests on travis * ci: simplify cargo test to squeeze into travis timeout * ci: don't run tests on travis at all * style(fixes) * fix(add tests) * fix(recent_signer bug) * fix(complete all tests) * fix(nits) * fix(simplify asserts) * fix(cliqueState): simplify code * fix(nits) * docs(comments what's need to fixed) * fix(revert unintended changes) * fix(tests) * fix(logs): voting logs * fix(readability + more logs) * fix(sync) * docs(add missing licens header) * fix(log): info! -> trace! * docs(fix nits) + fix(remove assert) * perf(use counter instead of vec) * fix(remove needless block in match) * fix(faulty comment) * grumbles(docs for tests) * fix(nits) * fix(revert_vote): only remove vote when votes == 0 * fix(vote counter): checked arithmetics * fix(simplify tests) * fix(nits) * fix(clique): err types * fix(clique utils): make use of errors * fix(cleanup nits) * fix(clique sealing): don't read state no signer * fix(replace Vec<Signers> with BTreeSet<Signers>) * fix(tests): BTreeSet and more generic helpers * fix(nits) * fix(ethcore_block_seal): remove needless `Box` * fix(faulty log): info -> trace * fix(checked SystemTime): prevent SystemTime panics * style(chain cfg): space after `:` * style(fn enact): fix whitespace * docs(clique): StepService * docs(nit): fix faulty comment * docs(fix typo) * style(fix bad indentation) * fix(bad regex match) * grumble(on_seal_block): make `&mut` to avoid clone * docs(on_seal_block): fix faulty documentation * Delete .travis.yml * docs: remove eth hf references in spec * Update client.rs * fix(nits) * fix(clique step): `RwLock` -> `AtomicBool` * fix(clique): use `Duration::as_millis` * Clean up some Clique documentation Co-authored-by: soc1c <soc1c@users.noreply.github.com> Co-authored-by: HCastano <HCastano@users.noreply.github.com> Co-authored-by: niklasad1 <niklasad1@users.noreply.github.com> Co-authored-by: jwasinger <jwasinger@users.noreply.github.com> Co-authored-by: ChainSafe <ChainSafe@users.noreply.github.com> Co-authored-by: thefallentree <thefallentree@users.noreply.github.com> Co-authored-by: 5chdn <5chdn@users.noreply.github.com>
501 lines
15 KiB
Rust
501 lines
15 KiB
Rust
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Ethereum.
|
|
|
|
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use std::collections::HashSet;
|
|
use std::time::Duration;
|
|
use std::{str, fs, fmt};
|
|
use std::num::NonZeroU32;
|
|
|
|
use ethcore::client::Mode;
|
|
use ethcore::ethereum;
|
|
use ethcore::spec::{Spec, SpecParams};
|
|
use ethereum_types::{U256, Address};
|
|
use parity_runtime::Executor;
|
|
use hash_fetch::fetch::Client as FetchClient;
|
|
use journaldb::Algorithm;
|
|
use miner::gas_pricer::GasPricer;
|
|
use miner::gas_price_calibrator::{GasPriceCalibratorOptions, GasPriceCalibrator};
|
|
use parity_version::version_data;
|
|
use user_defaults::UserDefaults;
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum SpecType {
|
|
Foundation,
|
|
Classic,
|
|
Poanet,
|
|
Tobalaba,
|
|
Expanse,
|
|
Musicoin,
|
|
Ellaism,
|
|
Easthub,
|
|
Social,
|
|
Mix,
|
|
Callisto,
|
|
Morden,
|
|
Ropsten,
|
|
Kovan,
|
|
Rinkeby,
|
|
Goerli,
|
|
Kotti,
|
|
Sokol,
|
|
Dev,
|
|
Custom(String),
|
|
}
|
|
|
|
impl Default for SpecType {
|
|
fn default() -> Self {
|
|
SpecType::Foundation
|
|
}
|
|
}
|
|
|
|
impl str::FromStr for SpecType {
|
|
type Err = String;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
let spec = match s {
|
|
"ethereum" | "frontier" | "homestead" | "byzantium" | "foundation" | "mainnet" => SpecType::Foundation,
|
|
"classic" | "frontier-dogmatic" | "homestead-dogmatic" => SpecType::Classic,
|
|
"poanet" | "poacore" => SpecType::Poanet,
|
|
"tobalaba" => SpecType::Tobalaba,
|
|
"expanse" => SpecType::Expanse,
|
|
"musicoin" => SpecType::Musicoin,
|
|
"ellaism" => SpecType::Ellaism,
|
|
"easthub" => SpecType::Easthub,
|
|
"social" => SpecType::Social,
|
|
"mix" => SpecType::Mix,
|
|
"callisto" => SpecType::Callisto,
|
|
"morden" | "classic-testnet" => SpecType::Morden,
|
|
"ropsten" => SpecType::Ropsten,
|
|
"kovan" | "testnet" => SpecType::Kovan,
|
|
"rinkeby" => SpecType::Rinkeby,
|
|
"goerli" | "görli" => SpecType::Goerli,
|
|
"kotti" => SpecType::Kotti,
|
|
"sokol" | "poasokol" => SpecType::Sokol,
|
|
"dev" => SpecType::Dev,
|
|
other => SpecType::Custom(other.into()),
|
|
};
|
|
Ok(spec)
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for SpecType {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
f.write_str(match *self {
|
|
SpecType::Foundation => "foundation",
|
|
SpecType::Classic => "classic",
|
|
SpecType::Poanet => "poanet",
|
|
SpecType::Tobalaba => "tobalaba",
|
|
SpecType::Expanse => "expanse",
|
|
SpecType::Musicoin => "musicoin",
|
|
SpecType::Ellaism => "ellaism",
|
|
SpecType::Easthub => "easthub",
|
|
SpecType::Social => "social",
|
|
SpecType::Mix => "mix",
|
|
SpecType::Callisto => "callisto",
|
|
SpecType::Morden => "morden",
|
|
SpecType::Ropsten => "ropsten",
|
|
SpecType::Kovan => "kovan",
|
|
SpecType::Rinkeby => "rinkeby",
|
|
SpecType::Goerli => "goerli",
|
|
SpecType::Kotti => "kotti",
|
|
SpecType::Sokol => "sokol",
|
|
SpecType::Dev => "dev",
|
|
SpecType::Custom(ref custom) => custom,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl SpecType {
|
|
pub fn spec<'a, T: Into<SpecParams<'a>>>(&self, params: T) -> Result<Spec, String> {
|
|
let params = params.into();
|
|
match *self {
|
|
SpecType::Foundation => Ok(ethereum::new_foundation(params)),
|
|
SpecType::Classic => Ok(ethereum::new_classic(params)),
|
|
SpecType::Poanet => Ok(ethereum::new_poanet(params)),
|
|
SpecType::Tobalaba => Ok(ethereum::new_tobalaba(params)),
|
|
SpecType::Expanse => Ok(ethereum::new_expanse(params)),
|
|
SpecType::Musicoin => Ok(ethereum::new_musicoin(params)),
|
|
SpecType::Ellaism => Ok(ethereum::new_ellaism(params)),
|
|
SpecType::Easthub => Ok(ethereum::new_easthub(params)),
|
|
SpecType::Social => Ok(ethereum::new_social(params)),
|
|
SpecType::Mix => Ok(ethereum::new_mix(params)),
|
|
SpecType::Callisto => Ok(ethereum::new_callisto(params)),
|
|
SpecType::Morden => Ok(ethereum::new_morden(params)),
|
|
SpecType::Ropsten => Ok(ethereum::new_ropsten(params)),
|
|
SpecType::Kovan => Ok(ethereum::new_kovan(params)),
|
|
SpecType::Rinkeby => Ok(ethereum::new_rinkeby(params)),
|
|
SpecType::Goerli => Ok(ethereum::new_goerli(params)),
|
|
SpecType::Kotti => Ok(ethereum::new_kotti(params)),
|
|
SpecType::Sokol => Ok(ethereum::new_sokol(params)),
|
|
SpecType::Dev => Ok(Spec::new_instant()),
|
|
SpecType::Custom(ref filename) => {
|
|
let file = fs::File::open(filename).map_err(|e| format!("Could not load specification file at {}: {}", filename, e))?;
|
|
Spec::load(params, file)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn legacy_fork_name(&self) -> Option<String> {
|
|
match *self {
|
|
SpecType::Classic => Some("classic".to_owned()),
|
|
SpecType::Expanse => Some("expanse".to_owned()),
|
|
SpecType::Musicoin => Some("musicoin".to_owned()),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum Pruning {
|
|
Specific(Algorithm),
|
|
Auto,
|
|
}
|
|
|
|
impl Default for Pruning {
|
|
fn default() -> Self {
|
|
Pruning::Auto
|
|
}
|
|
}
|
|
|
|
impl str::FromStr for Pruning {
|
|
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 {
|
|
pub fn to_algorithm(&self, user_defaults: &UserDefaults) -> Algorithm {
|
|
match *self {
|
|
Pruning::Specific(algo) => algo,
|
|
Pruning::Auto => user_defaults.pruning,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct ResealPolicy {
|
|
pub own: bool,
|
|
pub external: bool,
|
|
}
|
|
|
|
impl Default for ResealPolicy {
|
|
fn default() -> Self {
|
|
ResealPolicy {
|
|
own: true,
|
|
external: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl str::FromStr for ResealPolicy {
|
|
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: NonZeroU32,
|
|
pub refresh_time: u64,
|
|
pub testnet: bool,
|
|
pub password_files: Vec<String>,
|
|
pub unlocked_accounts: Vec<Address>,
|
|
pub enable_hardware_wallets: bool,
|
|
pub enable_fast_unlock: bool,
|
|
}
|
|
|
|
impl Default for AccountsConfig {
|
|
fn default() -> Self {
|
|
AccountsConfig {
|
|
iterations: NonZeroU32::new(10240).expect("10240 > 0; qed"),
|
|
refresh_time: 5,
|
|
testnet: false,
|
|
password_files: Vec::new(),
|
|
unlocked_accounts: Vec::new(),
|
|
enable_hardware_wallets: true,
|
|
enable_fast_unlock: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum GasPricerConfig {
|
|
Fixed(U256),
|
|
Calibrated {
|
|
usd_per_tx: f32,
|
|
recalibration_period: Duration,
|
|
}
|
|
}
|
|
|
|
impl Default for GasPricerConfig {
|
|
fn default() -> Self {
|
|
GasPricerConfig::Calibrated {
|
|
usd_per_tx: 0.0001f32,
|
|
recalibration_period: Duration::from_secs(3600),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl GasPricerConfig {
|
|
pub fn to_gas_pricer(&self, fetch: FetchClient, p: Executor) -> GasPricer {
|
|
match *self {
|
|
GasPricerConfig::Fixed(u) => GasPricer::Fixed(u),
|
|
GasPricerConfig::Calibrated { usd_per_tx, recalibration_period, .. } => {
|
|
GasPricer::new_calibrated(
|
|
GasPriceCalibrator::new(
|
|
GasPriceCalibratorOptions {
|
|
usd_per_tx: usd_per_tx,
|
|
recalibration_period: recalibration_period,
|
|
},
|
|
fetch,
|
|
p,
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct MinerExtras {
|
|
pub author: Address,
|
|
pub engine_signer: Address,
|
|
pub extra_data: Vec<u8>,
|
|
pub gas_range_target: (U256, U256),
|
|
pub work_notify: Vec<String>,
|
|
pub local_accounts: HashSet<Address>,
|
|
}
|
|
|
|
impl Default for MinerExtras {
|
|
fn default() -> Self {
|
|
MinerExtras {
|
|
author: Default::default(),
|
|
engine_signer: Default::default(),
|
|
extra_data: version_data(),
|
|
gas_range_target: (8_000_000.into(), 10_000_000.into()),
|
|
work_notify: Default::default(),
|
|
local_accounts: Default::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 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),
|
|
}
|
|
}
|
|
|
|
pub fn fatdb_switch_to_bool(switch: Switch, user_defaults: &UserDefaults, _algorithm: Algorithm) -> Result<bool, String> {
|
|
let result = match (user_defaults.is_first_launch, switch, user_defaults.fat_db) {
|
|
(false, Switch::On, false) => Err("FatDB resync required".into()),
|
|
(_, Switch::On, _) => Ok(true),
|
|
(_, Switch::Off, _) => Ok(false),
|
|
(_, Switch::Auto, def) => Ok(def),
|
|
};
|
|
result
|
|
}
|
|
|
|
pub fn mode_switch_to_bool(switch: Option<Mode>, user_defaults: &UserDefaults) -> Result<Mode, String> {
|
|
Ok(switch.unwrap_or(user_defaults.mode().clone()))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use journaldb::Algorithm;
|
|
use user_defaults::UserDefaults;
|
|
use super::{SpecType, Pruning, ResealPolicy, Switch, tracing_switch_to_bool};
|
|
|
|
#[test]
|
|
fn test_spec_type_parsing() {
|
|
assert_eq!(SpecType::Foundation, "foundation".parse().unwrap());
|
|
assert_eq!(SpecType::Foundation, "frontier".parse().unwrap());
|
|
assert_eq!(SpecType::Foundation, "homestead".parse().unwrap());
|
|
assert_eq!(SpecType::Foundation, "byzantium".parse().unwrap());
|
|
assert_eq!(SpecType::Foundation, "mainnet".parse().unwrap());
|
|
assert_eq!(SpecType::Foundation, "ethereum".parse().unwrap());
|
|
assert_eq!(SpecType::Classic, "classic".parse().unwrap());
|
|
assert_eq!(SpecType::Classic, "frontier-dogmatic".parse().unwrap());
|
|
assert_eq!(SpecType::Classic, "homestead-dogmatic".parse().unwrap());
|
|
assert_eq!(SpecType::Poanet, "poanet".parse().unwrap());
|
|
assert_eq!(SpecType::Poanet, "poacore".parse().unwrap());
|
|
assert_eq!(SpecType::Tobalaba, "tobalaba".parse().unwrap());
|
|
assert_eq!(SpecType::Expanse, "expanse".parse().unwrap());
|
|
assert_eq!(SpecType::Musicoin, "musicoin".parse().unwrap());
|
|
assert_eq!(SpecType::Ellaism, "ellaism".parse().unwrap());
|
|
assert_eq!(SpecType::Easthub, "easthub".parse().unwrap());
|
|
assert_eq!(SpecType::Social, "social".parse().unwrap());
|
|
assert_eq!(SpecType::Mix, "mix".parse().unwrap());
|
|
assert_eq!(SpecType::Callisto, "callisto".parse().unwrap());
|
|
assert_eq!(SpecType::Morden, "morden".parse().unwrap());
|
|
assert_eq!(SpecType::Morden, "classic-testnet".parse().unwrap());
|
|
assert_eq!(SpecType::Ropsten, "ropsten".parse().unwrap());
|
|
assert_eq!(SpecType::Kovan, "kovan".parse().unwrap());
|
|
assert_eq!(SpecType::Kovan, "testnet".parse().unwrap());
|
|
assert_eq!(SpecType::Rinkeby, "rinkeby".parse().unwrap());
|
|
assert_eq!(SpecType::Goerli, "goerli".parse().unwrap());
|
|
assert_eq!(SpecType::Goerli, "görli".parse().unwrap());
|
|
assert_eq!(SpecType::Kotti, "kotti".parse().unwrap());
|
|
assert_eq!(SpecType::Sokol, "sokol".parse().unwrap());
|
|
assert_eq!(SpecType::Sokol, "poasokol".parse().unwrap());
|
|
}
|
|
|
|
#[test]
|
|
fn test_spec_type_default() {
|
|
assert_eq!(SpecType::Foundation, SpecType::default());
|
|
}
|
|
|
|
#[test]
|
|
fn test_spec_type_display() {
|
|
assert_eq!(format!("{}", SpecType::Foundation), "foundation");
|
|
assert_eq!(format!("{}", SpecType::Classic), "classic");
|
|
assert_eq!(format!("{}", SpecType::Poanet), "poanet");
|
|
assert_eq!(format!("{}", SpecType::Tobalaba), "tobalaba");
|
|
assert_eq!(format!("{}", SpecType::Expanse), "expanse");
|
|
assert_eq!(format!("{}", SpecType::Musicoin), "musicoin");
|
|
assert_eq!(format!("{}", SpecType::Ellaism), "ellaism");
|
|
assert_eq!(format!("{}", SpecType::Easthub), "easthub");
|
|
assert_eq!(format!("{}", SpecType::Social), "social");
|
|
assert_eq!(format!("{}", SpecType::Mix), "mix");
|
|
assert_eq!(format!("{}", SpecType::Callisto), "callisto");
|
|
assert_eq!(format!("{}", SpecType::Morden), "morden");
|
|
assert_eq!(format!("{}", SpecType::Ropsten), "ropsten");
|
|
assert_eq!(format!("{}", SpecType::Kovan), "kovan");
|
|
assert_eq!(format!("{}", SpecType::Rinkeby), "rinkeby");
|
|
assert_eq!(format!("{}", SpecType::Goerli), "goerli");
|
|
assert_eq!(format!("{}", SpecType::Kotti), "kotti");
|
|
assert_eq!(format!("{}", SpecType::Sokol), "sokol");
|
|
assert_eq!(format!("{}", SpecType::Dev), "dev");
|
|
assert_eq!(format!("{}", SpecType::Custom("foo/bar".into())), "foo/bar");
|
|
}
|
|
|
|
#[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());
|
|
}
|
|
|
|
#[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());
|
|
}
|
|
}
|