From e495f3f72849709fcd3093a22ef1fc4627f8f30d Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 6 Aug 2019 16:14:51 +0200 Subject: [PATCH 1/5] bundle_* macros for spec --- ethcore/src/block.rs | 10 +- ethcore/src/client/evm_test_client.rs | 22 +- ethcore/src/client/test_client.rs | 4 +- ethcore/src/engines/authority_round/mod.rs | 32 +-- ethcore/src/engines/block_reward.rs | 6 +- ethcore/src/engines/clique/mod.rs | 4 +- ethcore/src/engines/ethash.rs | 2 +- ethcore/src/engines/instant_seal.rs | 6 +- ethcore/src/engines/validator_set/contract.rs | 6 +- ethcore/src/engines/validator_set/multi.rs | 6 +- .../engines/validator_set/safe_contract.rs | 14 +- ethcore/src/ethereum.rs | 225 ------------------ ethcore/src/executive.rs | 13 +- ethcore/src/executive_state.rs | 12 +- ethcore/src/externalities.rs | 3 +- ethcore/src/lib.rs | 1 - ethcore/src/machine.rs | 5 +- ethcore/src/miner/miner.rs | 28 +-- ethcore/src/snapshot/service.rs | 8 +- ethcore/src/snapshot/tests/proof_of_work.rs | 5 +- ethcore/src/snapshot/tests/service.rs | 16 +- ethcore/src/spec/bundle.rs | 166 +++++++++++++ ethcore/src/spec/mod.rs | 1 + ethcore/src/spec/spec.rs | 190 ++------------- ethcore/src/test_helpers.rs | 22 +- ethcore/src/tests/client.rs | 17 +- ethcore/src/tests/evm.rs | 3 +- ethcore/src/tests/trace.rs | 4 +- ethcore/src/verification/queue/mod.rs | 16 +- ethcore/src/verification/verification.rs | 6 +- 30 files changed, 320 insertions(+), 533 deletions(-) delete mode 100644 ethcore/src/ethereum.rs create mode 100644 ethcore/src/spec/bundle.rs diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 19a4a70b6a6..f88ab2d3cc7 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -563,6 +563,7 @@ mod tests { errors::EthcoreError as Error, }; use hash_db::EMPTY_PREFIX; + use crate::spec::bundle; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header fn enact_bytes( @@ -633,8 +634,7 @@ mod tests { #[test] fn open_block() { - use spec::*; - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); @@ -645,8 +645,7 @@ mod tests { #[test] fn enact_block() { - use spec::*; - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); @@ -670,8 +669,7 @@ mod tests { #[test] fn enact_block_with_uncle() { - use spec::*; - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index 8d0419e2e11..ada59e28560 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -29,13 +29,14 @@ use types::{ receipt, transaction }; +use ethjson::spec::ForkSpec; use trie_vm_factories::Factories; use evm::{VMType, FinalizationResult}; use vm::{self, ActionParams, CreateContractAddress}; use ethtrie; use account_state::{CleanupMode, State}; use substate::Substate; - +use crate::spec::bundle; use executive_state::ExecutiveState; /// EVM test Error. @@ -70,9 +71,6 @@ impl fmt::Display for EvmTestError { } } -use ethereum; -use ethjson::spec::ForkSpec; - /// Simplified, single-block EVM test client. pub struct EvmTestClient<'a> { state: State, @@ -101,14 +99,14 @@ impl<'a> EvmTestClient<'a> { /// Converts a json spec definition into spec. pub fn spec_from_json(spec: &ForkSpec) -> Option { match *spec { - ForkSpec::Frontier => Some(ethereum::new_frontier_test()), - ForkSpec::Homestead => Some(ethereum::new_homestead_test()), - ForkSpec::EIP150 => Some(ethereum::new_eip150_test()), - ForkSpec::EIP158 => Some(ethereum::new_eip161_test()), - ForkSpec::Byzantium => Some(ethereum::new_byzantium_test()), - ForkSpec::Constantinople => Some(ethereum::new_constantinople_test()), - ForkSpec::ConstantinopleFix => Some(ethereum::new_constantinople_fix_test()), - ForkSpec::EIP158ToByzantiumAt5 => Some(ethereum::new_transition_test()), + ForkSpec::Frontier => Some(bundle::new_frontier_test()), + ForkSpec::Homestead => Some(bundle::new_homestead_test()), + ForkSpec::EIP150 => Some(bundle::new_eip150_test()), + ForkSpec::EIP158 => Some(bundle::new_eip161_test()), + ForkSpec::Byzantium => Some(bundle::new_byzantium_test()), + ForkSpec::Constantinople => Some(bundle::new_constantinople_test()), + ForkSpec::ConstantinopleFix => Some(bundle::new_constantinople_fix_test()), + ForkSpec::EIP158ToByzantiumAt5 => Some(bundle::new_transition_test()), ForkSpec::FrontierToHomesteadAt5 | ForkSpec::HomesteadToDaoAt5 | ForkSpec::HomesteadToEIP150At5 => None, } } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 6b0ae3c81e3..17970323141 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -65,7 +65,7 @@ use engines::Engine; use executive::Executed; use journaldb; use miner::{self, Miner, MinerService}; -use spec::Spec; +use spec::{Spec, bundle}; use account_state::state::StateInfo; use state_db::StateDB; use trace::LocalizedTrace; @@ -151,7 +151,7 @@ impl TestBlockChainClient { /// Creates new test client with specified extra data for each block pub fn new_with_extra_data(extra_data: Bytes) -> Self { - let spec = Spec::new_test(); + let spec = bundle::new_test(); TestBlockChainClient::new_with_spec_and_extra(spec, extra_data) } diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 951e66a2d32..e27cf662005 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -1636,7 +1636,7 @@ mod tests { generate_dummy_client_with_spec, get_temp_state_db, TestNotify }; - use spec::Spec; + use spec::{Spec, bundle}; use engines::{Seal, Engine}; use engines::validator_set::{TestSet, SimpleList}; use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score}; @@ -1673,13 +1673,13 @@ mod tests { #[test] fn has_valid_metadata() { - let engine = Spec::new_test_round().engine; + let engine = bundle::new_test_round().engine; assert!(!engine.name().is_empty()); } #[test] fn can_return_schedule() { - let engine = Spec::new_test_round().engine; + let engine = bundle::new_test_round().engine; let schedule = engine.schedule(10000000); assert!(schedule.stack_limit > 0); @@ -1687,7 +1687,7 @@ mod tests { #[test] fn can_do_signature_verification_fail() { - let engine = Spec::new_test_round().engine; + let engine = bundle::new_test_round().engine; let mut header: Header = Header::default(); header.set_seal(vec![encode(&H520::default())]); @@ -1701,7 +1701,7 @@ mod tests { let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); let addr2 = tap.insert_account(keccak("2").into(), &"2".into()).unwrap(); - let spec = Spec::new_test_round(); + let spec = bundle::new_test_round(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let db1 = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); @@ -1733,7 +1733,7 @@ mod tests { let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); let addr2 = tap.insert_account(keccak("0").into(), &"0".into()).unwrap(); - let spec = Spec::new_test_round(); + let spec = bundle::new_test_round(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); @@ -1773,7 +1773,7 @@ mod tests { header.set_gas_limit("222222".parse::().unwrap()); header.set_author(addr); - let engine = Spec::new_test_round().engine; + let engine = bundle::new_test_round().engine; // Two validators. // Spec starts with step 2. @@ -1802,7 +1802,7 @@ mod tests { header.set_gas_limit("222222".parse::().unwrap()); header.set_author(addr); - let engine = Spec::new_test_round().engine; + let engine = bundle::new_test_round().engine; // Two validators. // Spec starts with step 2. @@ -1828,7 +1828,7 @@ mod tests { header.set_gas_limit("222222".parse::().unwrap()); header.set_author(addr); - let engine = Spec::new_test_round().engine; + let engine = bundle::new_test_round().engine; let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap(); // Two validators. @@ -1931,7 +1931,7 @@ mod tests { } fn setup_empty_steps() -> (Spec, Arc, Vec
) { - let spec = Spec::new_test_round_empty_steps(); + let spec = bundle::new_test_round_empty_steps(); let tap = Arc::new(AccountProvider::transient_provider()); let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); @@ -1984,7 +1984,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(Spec::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); let notify = Arc::new(TestNotify::default()); client.add_notify(notify.clone()); engine.register_client(Arc::downgrade(&client) as _); @@ -2023,7 +2023,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(Spec::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); let notify = Arc::new(TestNotify::default()); client.add_notify(notify.clone()); engine.register_client(Arc::downgrade(&client) as _); @@ -2076,7 +2076,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(Spec::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); let notify = Arc::new(TestNotify::default()); client.add_notify(notify.clone()); engine.register_client(Arc::downgrade(&client) as _); @@ -2128,7 +2128,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(Spec::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); engine.register_client(Arc::downgrade(&client) as _); // step 2 @@ -2215,7 +2215,7 @@ mod tests { #[test] fn block_reward_contract() { - let spec = Spec::new_test_round_block_reward_contract(); + let spec = bundle::new_test_round_block_reward_contract(); let tap = Arc::new(AccountProvider::transient_provider()); let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); @@ -2227,7 +2227,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(Spec::new_test_round_block_reward_contract); + let client = generate_dummy_client_with_spec(bundle::new_test_round_block_reward_contract); engine.register_client(Arc::downgrade(&client) as _); // step 2 diff --git a/ethcore/src/engines/block_reward.rs b/ethcore/src/engines/block_reward.rs index 8df88d9f282..1dd3d4105c2 100644 --- a/ethcore/src/engines/block_reward.rs +++ b/ethcore/src/engines/block_reward.rs @@ -164,7 +164,7 @@ mod test { use std::str::FromStr; use client::PrepareOpenBlock; use ethereum_types::{U256, Address}; - use spec::Spec; + use crate::spec::bundle; use test_helpers::generate_dummy_client_with_spec; use engines::SystemOrCodeCallKind; @@ -172,9 +172,9 @@ mod test { #[test] fn block_reward_contract() { - let client = generate_dummy_client_with_spec(Spec::new_test_round_block_reward_contract); + let client = generate_dummy_client_with_spec(bundle::new_test_round_block_reward_contract); - let machine = Spec::new_test_machine(); + let machine = bundle::new_test_machine(); // the spec has a block reward contract defined at the given address let block_reward_contract = BlockRewardContract::new_from_address( diff --git a/ethcore/src/engines/clique/mod.rs b/ethcore/src/engines/clique/mod.rs index 84d45a2840d..d19f2fc5faa 100644 --- a/ethcore/src/engines/clique/mod.rs +++ b/ethcore/src/engines/clique/mod.rs @@ -227,7 +227,7 @@ impl Clique { /// Note we need to `mock` the miner and it is introduced to test block verification to trigger new blocks /// to mainly test consensus edge cases pub fn with_test(epoch_length: u64, period: u64) -> Self { - use spec::Spec; + use crate::spec::bundle; Self { epoch_length, @@ -236,7 +236,7 @@ impl Clique { block_state_by_hash: RwLock::new(LruCache::new(STATE_CACHE_NUM)), proposals: Default::default(), signer: Default::default(), - machine: Spec::new_test_machine(), + machine: bundle::new_test_machine(), } } diff --git a/ethcore/src/engines/ethash.rs b/ethcore/src/engines/ethash.rs index 21aeca87c99..581c86900ed 100644 --- a/ethcore/src/engines/ethash.rs +++ b/ethcore/src/engines/ethash.rs @@ -501,7 +501,7 @@ mod tests { }; use spec::Spec; use engines::Engine; - use ethereum::{new_morden, new_mcip3_test, new_homestead_test_machine}; + use crate::spec::bundle::{new_morden, new_mcip3_test, new_homestead_test_machine}; use super::{Ethash, EthashParams, ecip1017_eras_block_reward}; use rlp; use tempdir::TempDir; diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 51dd8ff3c18..a619123ffd7 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -107,14 +107,14 @@ mod tests { use std::sync::Arc; use ethereum_types::{H520, Address}; use test_helpers::get_temp_state_db; - use spec::Spec; + use spec::bundle; use types::header::Header; use block::*; use engines::Seal; #[test] fn instant_can_seal() { - let spec = Spec::new_instant(); + let spec = bundle::new_instant(); let engine = &*spec.engine; let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); let genesis_header = spec.genesis_header(); @@ -128,7 +128,7 @@ mod tests { #[test] fn instant_cant_verify() { - let engine = Spec::new_instant().engine; + let engine = bundle::new_instant().engine; let mut header: Header = Header::default(); assert!(engine.verify_block_basic(&header).is_ok()); diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index ca3f3cd3d8e..7de9906b804 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -144,7 +144,7 @@ mod tests { use ethereum_types::{H520, Address}; use bytes::ToPretty; use rlp::encode; - use spec::Spec; + use spec::bundle; use types::header::Header; use accounts::AccountProvider; use miner::{self, MinerService}; @@ -158,7 +158,7 @@ mod tests { #[test] fn fetches_validators() { - let client = generate_dummy_client_with_spec(Spec::new_validator_contract); + let client = generate_dummy_client_with_spec(bundle::new_validator_contract); let vc = Arc::new(ValidatorContract::new("0000000000000000000000000000000000000005".parse::
().unwrap())); vc.register_client(Arc::downgrade(&client) as _); let last_hash = client.best_block_header().hash(); @@ -171,7 +171,7 @@ mod tests { let _ = ::env_logger::try_init(); let tap = Arc::new(AccountProvider::transient_provider()); let v1 = tap.insert_account(keccak("1").into(), &"".into()).unwrap(); - let client = generate_dummy_client_with_spec(Spec::new_validator_contract); + let client = generate_dummy_client_with_spec(bundle::new_validator_contract); client.engine().register_client(Arc::downgrade(&client) as _); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index d43edf10f29..51065dd077d 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -162,7 +162,7 @@ mod tests { use ethkey::Secret; use types::header::Header; use miner::{self, MinerService}; - use spec::Spec; + use spec::bundle; use test_helpers::{generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data}; use types::ids::BlockId; use ethereum_types::Address; @@ -176,7 +176,7 @@ mod tests { let s0: Secret = keccak("0").into(); let v0 = tap.insert_account(s0.clone(), &"".into()).unwrap(); let v1 = tap.insert_account(keccak("1").into(), &"".into()).unwrap(); - let client = generate_dummy_client_with_spec(Spec::new_validator_multi); + let client = generate_dummy_client_with_spec(bundle::new_validator_multi); client.engine().register_client(Arc::downgrade(&client) as _); // Make sure txs go through. @@ -207,7 +207,7 @@ mod tests { assert_eq!(client.chain_info().best_block_number, 3); // Check syncing. - let sync_client = generate_dummy_client_with_spec_and_data(Spec::new_validator_multi, 0, 0, &[]); + let sync_client = generate_dummy_client_with_spec_and_data(bundle::new_validator_multi, 0, 0, &[]); sync_client.engine().register_client(Arc::downgrade(&sync_client) as _); for i in 1..4 { sync_client.import_block(Unverified::from_rlp(client.block(BlockId::Number(i)).unwrap().into_inner()).unwrap()).unwrap(); diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index cc2aafc4cf7..ec27f31c9ad 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -454,7 +454,7 @@ mod tests { use hash::keccak; use ethereum_types::Address; use types::ids::BlockId; - use spec::Spec; + use spec::bundle; use accounts::AccountProvider; use types::transaction::{Transaction, Action}; use client::{ChainInfo, ImportBlock}; @@ -468,7 +468,7 @@ mod tests { #[test] fn fetches_validators() { - let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); + let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); let vc = Arc::new(ValidatorSafeContract::new("0000000000000000000000000000000000000005".parse::
().unwrap())); vc.register_client(Arc::downgrade(&client) as _); let last_hash = client.best_block_header().hash(); @@ -483,8 +483,8 @@ mod tests { let s0: Secret = keccak("1").into(); let v0 = tap.insert_account(s0.clone(), &"".into()).unwrap(); let v1 = tap.insert_account(keccak("0").into(), &"".into()).unwrap(); - let chain_id = Spec::new_validator_safe_contract().chain_id(); - let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); + let chain_id = bundle::new_validator_safe_contract().chain_id(); + let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); client.engine().register_client(Arc::downgrade(&client) as _); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); let signer = Box::new((tap.clone(), v1, "".into())); @@ -538,7 +538,7 @@ mod tests { assert_eq!(client.chain_info().best_block_number, 3); // Check syncing. - let sync_client = generate_dummy_client_with_spec_and_data(Spec::new_validator_safe_contract, 0, 0, &[]); + let sync_client = generate_dummy_client_with_spec_and_data(bundle::new_validator_safe_contract, 0, 0, &[]); sync_client.engine().register_client(Arc::downgrade(&sync_client) as _); for i in 1..4 { sync_client.import_block(Unverified::from_rlp(client.block(BlockId::Number(i)).unwrap().into_inner()).unwrap()).unwrap(); @@ -556,7 +556,7 @@ mod tests { engines::machine::AuxiliaryRequest, }; - let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); + let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); let engine = client.engine().clone(); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); @@ -593,7 +593,7 @@ mod tests { use types::header::Header; use engines::{EpochChange, Proof}; - let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); + let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); let engine = client.engine().clone(); let mut new_header = Header::default(); diff --git a/ethcore/src/ethereum.rs b/ethcore/src/ethereum.rs deleted file mode 100644 index 458da478101..00000000000 --- a/ethcore/src/ethereum.rs +++ /dev/null @@ -1,225 +0,0 @@ -// 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 . - -//! Ethereum protocol module. -//! -//! Contains all Ethereum network specific stuff, such as denominations and -//! consensus specifications. - -use machine::Machine; -use crate::spec::{Spec, SpecParams}; - -/// Load chain spec from `SpecParams` and JSON. -pub fn load<'a, T: Into>>>(params: T, b: &[u8]) -> Spec { - match params.into() { - Some(params) => Spec::load(params, b), - None => Spec::load(&::std::env::temp_dir(), b) - }.expect("chain spec is invalid") -} - -fn load_machine(b: &[u8]) -> Machine { - Spec::load_machine(b).expect("chain spec is invalid") -} - -/// Create a new Foundation mainnet chain spec. -pub fn new_foundation<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/foundation.json")) -} - -/// Create a new Classic mainnet chain spec without the DAO hardfork. -pub fn new_classic<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/classic.json")) -} - -/// Create a new POA Network mainnet chain spec. -pub fn new_poanet<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/poacore.json")) -} - -/// Create a new Tobalaba mainnet chain spec. -pub fn new_tobalaba<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/tobalaba.json")) -} - -/// Create a new Expanse mainnet chain spec. -pub fn new_expanse<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/expanse.json")) -} - -/// Create a new Musicoin mainnet chain spec. -pub fn new_musicoin<'a, T: Into>>(params: T) -> Spec { - // The musicoin chain spec uses a block reward contract which can be found at - // https://gist.github.com/andresilva/6f2afaf9486732a0797f4bdeae018ee9 - load(params.into(), include_bytes!("../res/ethereum/musicoin.json")) -} - -/// Create a new Ellaism mainnet chain spec. -pub fn new_ellaism<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/ellaism.json")) -} - -/// Create a new MIX mainnet chain spec. -pub fn new_mix<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/mix.json")) -} - -/// Create a new Callisto chain spec -pub fn new_callisto<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/callisto.json")) -} - -/// Create a new Morden testnet chain spec. -pub fn new_morden<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/morden.json")) -} - -/// Create a new Ropsten testnet chain spec. -pub fn new_ropsten<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/ropsten.json")) -} - -/// Create a new Kovan testnet chain spec. -pub fn new_kovan<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/kovan.json")) -} - -/// Create a new Rinkeby testnet chain spec. -pub fn new_rinkeby<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/rinkeby.json")) -} - -/// Create a new Görli testnet chain spec. -pub fn new_goerli<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/goerli.json")) -} - -/// Create a new Kotti testnet chain spec. -pub fn new_kotti<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/kotti.json")) -} - -/// Create a new POA Sokol testnet chain spec. -pub fn new_sokol<'a, T: Into>>(params: T) -> Spec { - load(params.into(), include_bytes!("../res/ethereum/poasokol.json")) -} - -// For tests - -/// Create a new Foundation Frontier-era chain spec as though it never changes to Homestead. -pub fn new_frontier_test() -> Spec { load(None, include_bytes!("../res/ethereum/frontier_test.json")) } - -/// Create a new Ropsten chain spec. -pub fn new_ropsten_test() -> Spec { load(None, include_bytes!("../res/ethereum/ropsten.json")) } - -/// Create a new Foundation Homestead-era chain spec as though it never changed from Frontier. -pub fn new_homestead_test() -> Spec { load(None, include_bytes!("../res/ethereum/homestead_test.json")) } - -/// Create a new Foundation Homestead-EIP150-era chain spec as though it never changed from Homestead/Frontier. -pub fn new_eip150_test() -> Spec { load(None, include_bytes!("../res/ethereum/eip150_test.json")) } - -/// Create a new Foundation Homestead-EIP161-era chain spec as though it never changed from Homestead/Frontier. -pub fn new_eip161_test() -> Spec { load(None, include_bytes!("../res/ethereum/eip161_test.json")) } - -/// Create a new Foundation Frontier/Homestead/DAO chain spec with transition points at #5 and #8. -pub fn new_transition_test() -> Spec { load(None, include_bytes!("../res/ethereum/transition_test.json")) } - -/// Create a new Foundation Mainnet chain spec without genesis accounts. -pub fn new_mainnet_like() -> Spec { load(None, include_bytes!("../res/ethereum/frontier_like_test.json")) } - -/// Create a new Foundation Byzantium era spec. -pub fn new_byzantium_test() -> Spec { load(None, include_bytes!("../res/ethereum/byzantium_test.json")) } - -/// Create a new Foundation Constantinople era spec. -pub fn new_constantinople_test() -> Spec { load(None, include_bytes!("../res/ethereum/constantinople_test.json")) } - -/// Create a new Foundation St. Peter's (Contantinople Fix) era spec. -pub fn new_constantinople_fix_test() -> Spec { load(None, include_bytes!("../res/ethereum/st_peters_test.json")) } - -/// Create a new Musicoin-MCIP3-era spec. -pub fn new_mcip3_test() -> Spec { load(None, include_bytes!("../res/ethereum/mcip3_test.json")) } - -// For tests - -/// Create a new Foundation Frontier-era chain spec as though it never changes to Homestead. -pub fn new_frontier_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/frontier_test.json")) } - -/// Create a new Foundation Homestead-era chain spec as though it never changed from Frontier. -pub fn new_homestead_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/homestead_test.json")) } - -/// Create a new Foundation Homestead-EIP210-era chain spec as though it never changed from Homestead/Frontier. -pub fn new_eip210_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/eip210_test.json")) } - -/// Create a new Foundation Byzantium era spec. -pub fn new_byzantium_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/byzantium_test.json")) } - -/// Create a new Foundation Constantinople era spec. -pub fn new_constantinople_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/constantinople_test.json")) } - -/// Create a new Foundation St. Peter's (Contantinople Fix) era spec. -pub fn new_constantinople_fix_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/st_peters_test.json")) } - -/// Create a new Musicoin-MCIP3-era spec. -pub fn new_mcip3_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/mcip3_test.json")) } - -/// Create new Kovan spec with wasm activated at certain block -pub fn new_kovan_wasm_test_machine() -> Machine { load_machine(include_bytes!("../res/ethereum/kovan_wasm_test.json")) } - -#[cfg(test)] -mod tests { - use account_state::State; - use ethereum_types::U256; - use tempdir::TempDir; - use test_helpers::get_temp_state_db; - use types::{view, views::BlockView}; - - use super::{new_morden, new_foundation}; - - #[test] - fn ensure_db_good() { - let tempdir = TempDir::new("").unwrap(); - let spec = new_morden(&tempdir.path()); - let engine = &spec.engine; - let genesis_header = spec.genesis_header(); - let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); - let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(0), Default::default()).unwrap(); - assert_eq!(s.balance(&"0000000000000000000000000000000000000001".parse().unwrap()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"0000000000000000000000000000000000000002".parse().unwrap()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"0000000000000000000000000000000000000003".parse().unwrap()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"0000000000000000000000000000000000000004".parse().unwrap()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c".parse().unwrap()).unwrap(), U256::from(1u64) << 200); - assert_eq!(s.balance(&"0000000000000000000000000000000000000000".parse().unwrap()).unwrap(), 0u64.into()); - } - - #[test] - fn morden() { - let tempdir = TempDir::new("").unwrap(); - let morden = new_morden(&tempdir.path()); - - assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".parse().unwrap()); - let genesis = morden.genesis_block(); - assert_eq!(view!(BlockView, &genesis).header_view().hash(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".parse().unwrap()); - } - - #[test] - fn frontier() { - let tempdir = TempDir::new("").unwrap(); - let frontier = new_foundation(&tempdir.path()); - - assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".parse().unwrap()); - let genesis = frontier.genesis_block(); - assert_eq!(view!(BlockView, &genesis).header_view().hash(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".parse().unwrap()); - } -} diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index ae48ac92fc3..039cd4edd9e 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -1228,15 +1228,16 @@ mod tests { errors::ExecutionError, transaction::{Action, Transaction}, }; + use crate::spec::bundle; fn make_frontier_machine(max_depth: usize) -> Machine { - let mut machine = ::ethereum::new_frontier_test_machine(); + let mut machine = bundle::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } fn make_byzantium_machine(max_depth: usize) -> Machine { - let mut machine = ::ethereum::new_byzantium_test_machine(); + let mut machine = bundle::new_byzantium_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } @@ -1590,7 +1591,7 @@ mod tests { let mut state = get_temp_state(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); let info = EnvInfo::default(); - let machine = ::ethereum::new_byzantium_test_machine(); + let machine = bundle::new_byzantium_test_machine(); let schedule = machine.schedule(info.number); let mut substate = Substate::new(); let mut tracer = ExecutiveTracer::default(); @@ -2122,7 +2123,7 @@ mod tests { params.code = Some(Arc::new(code)); params.value = ActionValue::Transfer(U256::zero()); let info = EnvInfo::default(); - let machine = ::ethereum::new_byzantium_test_machine(); + let machine = bundle::new_byzantium_test_machine(); let schedule = machine.schedule(info.number); let mut substate = Substate::new(); @@ -2158,7 +2159,7 @@ mod tests { state.init_code(&y2, "600060006000600061100162fffffff4".from_hex().unwrap()).unwrap(); let info = EnvInfo::default(); - let machine = ::ethereum::new_constantinople_test_machine(); + let machine = bundle::new_constantinople_test_machine(); let schedule = machine.schedule(info.number); assert_eq!(state.storage_at(&operating_address, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); @@ -2228,7 +2229,7 @@ mod tests { info.number = 100; // Network with wasm activated at block 10 - let machine = ::ethereum::new_kovan_wasm_test_machine(); + let machine = bundle::new_kovan_wasm_test_machine(); let mut output = [0u8; 20]; let FinalizationResult { gas_left: result, return_data, .. } = { diff --git a/ethcore/src/executive_state.rs b/ethcore/src/executive_state.rs index 0931c45811b..e9c9feaef47 100644 --- a/ethcore/src/executive_state.rs +++ b/ethcore/src/executive_state.rs @@ -268,7 +268,6 @@ mod tests { use test_helpers::{get_temp_state, get_temp_state_db}; use machine::Machine; use vm::EnvInfo; - use spec::*; use types::transaction::*; use trace::{FlatTrace, TraceError, trace}; use evm::CallType; @@ -276,13 +275,14 @@ mod tests { use pod::PodState; use executive_state::ExecutiveState; use account_state::{Account, CleanupMode}; + use crate::spec::bundle; fn secret() -> Secret { keccak("").into() } fn make_frontier_machine(max_depth: usize) -> Machine { - let mut machine = ::ethereum::new_frontier_test_machine(); + let mut machine = bundle::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } @@ -472,7 +472,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let machine = Spec::new_test_machine(); + let machine = bundle::new_test_machine(); let t = Transaction { nonce: 0.into(), @@ -513,7 +513,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let machine = Spec::new_test_machine(); + let machine = bundle::new_test_machine(); let t = Transaction { nonce: 0.into(), @@ -555,7 +555,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let machine = Spec::new_test_machine(); + let machine = bundle::new_test_machine(); let t = Transaction { nonce: 0.into(), @@ -614,7 +614,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); info.number = 0x789b0; - let machine = Spec::new_test_machine(); + let machine = bundle::new_test_machine(); let t = Transaction { nonce: 0.into(), diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 272e642bd97..6942376d851 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -442,6 +442,7 @@ mod tests { use super::*; use trace::{NoopTracer, NoopVMTracer}; use std::str::FromStr; + use crate::spec::bundle; fn get_test_origin() -> OriginInfo { OriginInfo { @@ -480,7 +481,7 @@ mod tests { impl TestSetup { fn new() -> Self { - let machine = ::spec::Spec::new_test_machine(); + let machine = bundle::new_test_machine(); let env_info = get_test_env_info(); let schedule = machine.schedule(env_info.number); TestSetup { diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index e7aa7385647..dad4e2e9db4 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -151,7 +151,6 @@ extern crate parity_runtime; pub mod block; pub mod client; pub mod engines; -pub mod ethereum; pub mod executed; pub mod executive; pub mod executive_state; diff --git a/ethcore/src/machine.rs b/ethcore/src/machine.rs index 1e7acb649c6..f3cb660b4df 100644 --- a/ethcore/src/machine.rs +++ b/ethcore/src/machine.rs @@ -402,6 +402,7 @@ fn round_block_gas_limit(gas_limit: U256, lower_limit: U256, upper_limit: U256) mod tests { use super::*; use std::str::FromStr; + use crate::spec::bundle; fn get_default_ethash_extensions() -> EthashExtensions { EthashExtensions { @@ -416,7 +417,7 @@ mod tests { fn should_disallow_unsigned_transactions() { let rlp = "ea80843b9aca0083015f90948921ebb5f79e9e3920abe571004d0b1d5119c154865af3107a400080038080"; let transaction: UnverifiedTransaction = ::rlp::decode(&::rustc_hex::FromHex::from_hex(rlp).unwrap()).unwrap(); - let spec = ::ethereum::new_ropsten_test(); + let spec = bundle::new_ropsten_test(); let ethparams = get_default_ethash_extensions(); let machine = Machine::with_ethash_extensions( @@ -435,7 +436,7 @@ mod tests { fn ethash_gas_limit_is_multiple_of_determinant() { use ethereum_types::U256; - let spec = ::ethereum::new_homestead_test(); + let spec = bundle::new_homestead_test(); let ethparams = get_default_ethash_extensions(); let machine = Machine::with_ethash_extensions( diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index ad6ecaae8c2..631dac9730c 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -60,7 +60,7 @@ use client::{ use client::BlockId; use engines::{Engine, Seal, EngineSigner}; use executive::contract_address; -use spec::Spec; +use spec::{Spec, bundle}; use account_state::State; use vm::CreateContractAddress; @@ -1490,7 +1490,7 @@ mod tests { fn should_prepare_block_to_seal() { // given let client = TestBlockChainClient::default(); - let miner = Miner::new_for_tests(&Spec::new_test(), None); + let miner = Miner::new_for_tests(&bundle::new_test(), None); // when let sealing_work = miner.work_package(&client); @@ -1501,7 +1501,7 @@ mod tests { fn should_still_work_after_a_couple_of_blocks() { // given let client = TestBlockChainClient::default(); - let miner = Miner::new_for_tests(&Spec::new_test(), None); + let miner = Miner::new_for_tests(&bundle::new_test(), None); let res = miner.work_package(&client); let hash = res.unwrap().0; @@ -1545,7 +1545,7 @@ mod tests { }, }, GasPricer::new_fixed(0u64.into()), - &Spec::new_test(), + &bundle::new_test(), ::std::collections::HashSet::new(), // local accounts ) } @@ -1668,7 +1668,7 @@ mod tests { ..miner().options }, GasPricer::new_fixed(0u64.into()), - &Spec::new_test(), + &bundle::new_test(), local_accounts, ); let transaction = transaction(); @@ -1711,7 +1711,7 @@ mod tests { ..miner().options }, GasPricer::new_fixed(0u64.into()), - &Spec::new_test(), + &bundle::new_test(), HashSet::from_iter(vec![transaction.sender()].into_iter()), ); let best_block = 0; @@ -1743,7 +1743,7 @@ mod tests { #[test] fn internal_seals_without_work() { let _ = env_logger::try_init(); - let spec = Spec::new_instant(); + let spec = bundle::new_instant(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1772,7 +1772,7 @@ mod tests { #[test] fn should_not_fail_setting_engine_signer_without_account_provider() { - let spec = Spec::new_test_round; + let spec = bundle::new_test_round; let tap = Arc::new(AccountProvider::transient_provider()); let addr = tap.insert_account(keccak("1").into(), &"".into()).unwrap(); let client = generate_dummy_client_with_spec(spec); @@ -1788,7 +1788,7 @@ mod tests { #[test] fn should_mine_if_internal_sealing_is_enabled() { - let spec = Spec::new_instant(); + let spec = bundle::new_instant(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1799,7 +1799,7 @@ mod tests { #[test] fn should_not_mine_if_internal_sealing_is_disabled() { - let spec = Spec::new_test_round(); + let spec = bundle::new_test_round(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1810,7 +1810,7 @@ mod tests { #[test] fn should_not_mine_if_no_fetch_work_request() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1828,7 +1828,7 @@ mod tests { fn notify(&self, _pow_hash: H256, _difficulty: U256, _number: u64) { } } - let spec = Spec::new_test(); + let spec = bundle::new_test(); let miner = Miner::new_for_tests(&spec, None); miner.add_work_listener(Box::new(DummyNotifyWork)); @@ -1841,7 +1841,7 @@ mod tests { #[test] fn should_set_new_minimum_gas_price() { // Creates a new GasPricer::Fixed behind the scenes - let miner = Miner::new_for_tests(&Spec::new_test(), None); + let miner = Miner::new_for_tests(&bundle::new_test(), None); let expected_minimum_gas_price: U256 = 0x1337.into(); miner.set_minimal_gas_price(expected_minimum_gas_price).unwrap(); @@ -1879,7 +1879,7 @@ mod tests { #[cfg(feature = "price-info")] fn should_fail_to_set_new_minimum_gas_price() { // We get a fixed gas pricer by default, need to change that - let miner = Miner::new_for_tests(&Spec::new_test(), None); + let miner = Miner::new_for_tests(&bundle::new_test(), None); let calibrated_gas_pricer = dynamic_gas_pricer(); *miner.gas_pricer.lock() = calibrated_gas_pricer; diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index d3e2f1ce76c..6b2e3a4869e 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -899,7 +899,7 @@ impl Drop for Service { mod tests { use client::ClientIoMessage; use io::{IoService}; - use spec::Spec; + use spec::bundle; use journaldb::Algorithm; use snapshot::{ManifestData, RestorationStatus, SnapshotService}; use super::*; @@ -909,9 +909,9 @@ mod tests { #[test] fn sends_async_messages() { let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(Spec::new_null, 400, 5, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(bundle::new_null, 400, 5, &gas_prices); let service = IoService::::start().unwrap(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let tempdir = TempDir::new("").unwrap(); let dir = tempdir.path().join("snapshot"); @@ -952,7 +952,7 @@ mod tests { use ethereum_types::H256; use kvdb_rocksdb::DatabaseConfig; - let spec = Spec::new_test(); + let spec = bundle::new_test(); let tempdir = TempDir::new("").unwrap(); let state_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect(); diff --git a/ethcore/src/snapshot/tests/proof_of_work.rs b/ethcore/src/snapshot/tests/proof_of_work.rs index 9be48ab06fa..92de2b85cf1 100644 --- a/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/ethcore/src/snapshot/tests/proof_of_work.rs @@ -29,6 +29,7 @@ use parking_lot::Mutex; use snappy; use kvdb::DBTransaction; use test_helpers; +use crate::spec::bundle; const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { blocks: 30000, max_restore_blocks: 30000 }; @@ -38,7 +39,7 @@ fn chunk_and_restore(amount: u64) { let generator = BlockGenerator::new(vec![rest]); let genesis = genesis.last(); - let engine = ::spec::Spec::new_test().engine; + let engine = bundle::new_test().engine; let tempdir = TempDir::new("").unwrap(); let snapshot_path = tempdir.path().join("SNAP"); @@ -128,7 +129,7 @@ fn checks_flag() { let chunk = stream.out(); let db = test_helpers::new_db(); - let engine = ::spec::Spec::new_test().engine; + let engine = bundle::new_test().engine; let chain = BlockChain::new(Default::default(), genesis.last().encoded().raw(), db.clone()); let manifest = ::snapshot::ManifestData { diff --git a/ethcore/src/snapshot/tests/service.rs b/ethcore/src/snapshot/tests/service.rs index 08e716d269a..4e1d824c484 100644 --- a/ethcore/src/snapshot/tests/service.rs +++ b/ethcore/src/snapshot/tests/service.rs @@ -27,7 +27,7 @@ use types::ids::BlockId; use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; use snapshot::service::{Service, ServiceParams}; use snapshot::{chunk_state, chunk_secondary, ManifestData, Progress, SnapshotService, RestorationStatus}; -use spec::Spec; +use spec::bundle; use test_helpers::{new_db, new_temp_db, generate_dummy_client_with_spec_and_data, restoration_db_handler}; use parking_lot::Mutex; @@ -43,7 +43,7 @@ fn restored_is_equivalent() { const TX_PER: usize = 5; let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(Spec::new_null, NUM_BLOCKS, TX_PER, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(bundle::new_null, NUM_BLOCKS, TX_PER, &gas_prices); let tempdir = TempDir::new("").unwrap(); let client_db = tempdir.path().join("client_db"); @@ -53,7 +53,7 @@ fn restored_is_equivalent() { let restoration = restoration_db_handler(db_config); let blockchain_db = restoration.open(&client_db).unwrap(); - let spec = Spec::new_null(); + let spec = bundle::new_null(); let client2 = Client::new( Default::default(), &spec, @@ -107,9 +107,9 @@ fn restored_is_equivalent() { #[test] fn guards_delete_folders() { let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(Spec::new_null, 400, 5, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(bundle::new_null, 400, 5, &gas_prices); - let spec = Spec::new_null(); + let spec = bundle::new_null(); let tempdir = TempDir::new("").unwrap(); let service_params = ServiceParams { engine: spec.engine.clone(), @@ -165,7 +165,7 @@ fn keep_ancient_blocks() { // Generate blocks let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let spec_f = Spec::new_null; + let spec_f = bundle::new_null; let spec = spec_f(); let client = generate_dummy_client_with_spec_and_data(spec_f, NUM_BLOCKS as u32, 5, &gas_prices); @@ -276,9 +276,9 @@ fn recover_aborted_recovery() { const NUM_BLOCKS: u32 = 400; let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(Spec::new_null, NUM_BLOCKS, 5, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(bundle::new_null, NUM_BLOCKS, 5, &gas_prices); - let spec = Spec::new_null(); + let spec = bundle::new_null(); let tempdir = TempDir::new("").unwrap(); let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let client_db = new_db(); diff --git a/ethcore/src/spec/bundle.rs b/ethcore/src/spec/bundle.rs new file mode 100644 index 00000000000..e8a1755bd33 --- /dev/null +++ b/ethcore/src/spec/bundle.rs @@ -0,0 +1,166 @@ +// 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 . + +//! Ethereum protocol module. +//! +//! Contains all Ethereum network specific stuff, such as denominations and +//! consensus specifications. + +macro_rules! bundle_release_spec { + ($($path: expr => $name: ident), *) => { + $( + /// Bundled release spec + pub fn $name<'a, T: Into>>(params: T) -> crate::spec::Spec { + let params = params.into(); + crate::spec::Spec::load( + params, + include_bytes!(concat!("../../res/", $path, ".json")) as &[u8] + ).expect(concat!("Chain spec ", $path, " is invalid.")) + } + )* + } +} + +macro_rules! bundle_test_spec { + ($($path: expr => $name: ident), *) => { + $( + /// Bundled test spec + pub fn $name() -> crate::spec::Spec { + crate::spec::Spec::load( + &::std::env::temp_dir(), + include_bytes!(concat!("../../res/", $path, ".json")) as &[u8] + ).expect(concat!("Chain spec ", $path, " is invalid.")) + } + )* + } +} + +macro_rules! bundle_test_machine { + ($($path: expr => $name: ident), *) => { + $( + /// Bundled test spec + pub fn $name() -> crate::machine::Machine { + crate::spec::Spec::load_machine( + include_bytes!(concat!("../../res/", $path, ".json")) as &[u8] + ).expect(concat!("Chain spec ", $path, " is invalid.")) + } + )* + } +} + +bundle_release_spec! { + "ethereum/callisto" => new_callisto, + "ethereum/classic" => new_classic, + "ethereum/ellaism" => new_ellaism, + "ethereum/expanse" => new_expanse, + "ethereum/foundation" => new_foundation, + "ethereum/goerli" => new_goerli, + "ethereum/kotti" => new_kotti, + "ethereum/kovan" => new_kovan, + "ethereum/mix" => new_mix, + "ethereum/morden" => new_morden, + "ethereum/musicoin" => new_musicoin, + "ethereum/poacore" => new_poanet, + "ethereum/poasokol" => new_sokol, + "ethereum/rinkeby" => new_rinkeby, + "ethereum/ropsten" => new_ropsten, + "ethereum/tobalaba" => new_tobalaba +} + +bundle_test_spec! { + "authority_round" => new_test_round, + "authority_round_block_reward_contract" => new_test_round_block_reward_contract, + "authority_round_empty_steps" => new_test_round_empty_steps, + "constructor" => new_test_constructor, + "ethereum/byzantium_test" => new_byzantium_test, + "ethereum/constantinople_test" => new_constantinople_test, + "ethereum/eip150_test" => new_eip150_test, + "ethereum/eip161_test" => new_eip161_test, + "ethereum/eip210_test" => new_eip210_test, + "ethereum/frontier_like_test" => new_mainnet_like, + "ethereum/frontier_test" => new_frontier_test, + "ethereum/homestead_test" => new_homestead_test, + "ethereum/kovan_wasm_test" => new_kovan_wasm_test, + "ethereum/mcip3_test" => new_mcip3_test, + "ethereum/morden" => new_morden_test, + "ethereum/ropsten" => new_ropsten_test, + "ethereum/st_peters_test" => new_constantinople_fix_test, + "ethereum/transition_test" => new_transition_test, + "instant_seal" => new_instant, + "null" => new_null, + "null_morden" => new_test, + "null_morden_with_reward" => new_test_with_reward, + "validator_contract" => new_validator_contract, + "validator_safe_contract" => new_validator_safe_contract, + "validator_multi" => new_validator_multi +} + +bundle_test_machine! { + "ethereum/byzantium_test" => new_byzantium_test_machine, + "ethereum/constantinople_test" => new_constantinople_test_machine, + "ethereum/eip210_test" => new_eip210_test_machine, + "ethereum/frontier_test" => new_frontier_test_machine, + "ethereum/homestead_test" => new_homestead_test_machine, + "ethereum/kovan_wasm_test" => new_kovan_wasm_test_machine, + "null_morden" => new_test_machine +} + +#[cfg(test)] +mod tests { + use account_state::State; + use ethereum_types::U256; + use tempdir::TempDir; + use test_helpers::get_temp_state_db; + use types::{view, views::BlockView}; + + use super::{new_morden, new_foundation}; + + #[test] + fn ensure_db_good() { + let tempdir = TempDir::new("").unwrap(); + let spec = new_morden(&tempdir.path()); + let engine = &spec.engine; + let genesis_header = spec.genesis_header(); + let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); + let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(0), Default::default()).unwrap(); + assert_eq!(s.balance(&"0000000000000000000000000000000000000001".parse().unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&"0000000000000000000000000000000000000002".parse().unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&"0000000000000000000000000000000000000003".parse().unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&"0000000000000000000000000000000000000004".parse().unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c".parse().unwrap()).unwrap(), U256::from(1u64) << 200); + assert_eq!(s.balance(&"0000000000000000000000000000000000000000".parse().unwrap()).unwrap(), 0u64.into()); + } + + #[test] + fn morden() { + let tempdir = TempDir::new("").unwrap(); + let morden = new_morden(&tempdir.path()); + + assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".parse().unwrap()); + let genesis = morden.genesis_block(); + assert_eq!(view!(BlockView, &genesis).header_view().hash(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".parse().unwrap()); + } + + #[test] + fn frontier() { + let tempdir = TempDir::new("").unwrap(); + let frontier = new_foundation(&tempdir.path()); + + assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".parse().unwrap()); + let genesis = frontier.genesis_block(); + assert_eq!(view!(BlockView, &genesis).header_view().hash(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".parse().unwrap()); + } +} diff --git a/ethcore/src/spec/mod.rs b/ethcore/src/spec/mod.rs index b3710a91b67..004c3e86ca3 100644 --- a/ethcore/src/spec/mod.rs +++ b/ethcore/src/spec/mod.rs @@ -16,6 +16,7 @@ //! Blockchain params. +pub mod bundle; mod genesis; mod seal; mod spec; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 1d732f8f03f..9ae7800df9d 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -186,17 +186,16 @@ fn run_constructors( /// Parameters for a block chain; includes both those intrinsic to the design of the /// chain and those to be interpreted by the active chain engine. +#[derive(Clone)] pub struct Spec { - /// User friendly spec name + /// User friendly spec name. pub name: String, - /// What engine are we using for this? + /// Engine specified by json file. pub engine: Arc, /// Name of the subdir inside the main data dir to use for chain data and settings. pub data_dir: String, - /// Known nodes on the network in enode format. pub nodes: Vec, - /// The genesis block's parent hash field. pub parent_hash: H256, /// The genesis block's author field. @@ -217,44 +216,14 @@ pub struct Spec { pub extra_data: Bytes, /// Each seal field, expressed as RLP, concatenated. pub seal_rlp: Bytes, - /// Hardcoded synchronization. Allows the light client to immediately jump to a specific block. pub hardcoded_sync: Option, - /// Contract constructors to be executed on genesis. - constructors: Vec<(Address, Bytes)>, - + pub constructors: Vec<(Address, Bytes)>, /// May be prepopulated if we know this in advance. - state_root_memo: H256, - + pub state_root_memo: H256, /// Genesis state as plain old data. - genesis_state: PodState, -} - -#[cfg(test)] -impl Clone for Spec { - fn clone(&self) -> Spec { - Spec { - name: self.name.clone(), - engine: self.engine.clone(), - data_dir: self.data_dir.clone(), - nodes: self.nodes.clone(), - parent_hash: self.parent_hash.clone(), - transactions_root: self.transactions_root.clone(), - receipts_root: self.receipts_root.clone(), - author: self.author.clone(), - difficulty: self.difficulty.clone(), - gas_limit: self.gas_limit.clone(), - gas_used: self.gas_used.clone(), - timestamp: self.timestamp.clone(), - extra_data: self.extra_data.clone(), - seal_rlp: self.seal_rlp.clone(), - hardcoded_sync: self.hardcoded_sync.clone(), - constructors: self.constructors.clone(), - state_root_memo: self.state_root_memo, - genesis_state: self.genesis_state.clone(), - } - } + pub genesis_state: PodState, } /// Part of `Spec`. Describes the hardcoded synchronization parameters. @@ -289,13 +258,6 @@ impl fmt::Display for SpecHardcodedSync { } } -fn load_machine_from(s: ethjson::spec::Spec) -> Machine { - let builtins = s.accounts.builtins().into_iter().map(|p| (p.0.into(), From::from(p.1))).collect(); - let params = CommonParams::from(s.params); - - Spec::machine(&s.engine, params, builtins) -} - /// Load from JSON object. fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result { let builtins = s.accounts @@ -355,24 +317,6 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result { - Spec::load( - &::std::env::temp_dir(), - include_bytes!(concat!("../../res/", $e, ".json")) as &[u8] - ).expect(concat!("Chain spec ", $e, " is invalid.")) - }; -} - -#[cfg(any(test, feature = "test-helpers"))] -macro_rules! load_machine_bundled { - ($e:expr) => { - Spec::load_machine( - include_bytes!(concat!("../../res/", $e, ".json")) as &[u8] - ).expect(concat!("Chain spec ", $e, " is invalid.")) - }; -} - impl Spec { // create an instance of an Ethereum state machine, minus consensus logic. fn machine( @@ -420,11 +364,6 @@ impl Spec { &self.engine.params() } - /// Get the known knodes of the network in enode format. - pub fn nodes(&self) -> &[String] { - &self.nodes - } - /// Get the configured Network ID. pub fn network_id(&self) -> u64 { self.params().network_id @@ -513,11 +452,6 @@ impl Spec { Ok(()) } - /// Return genesis state as Plain old data. - pub fn genesis_state(&self) -> &PodState { - &self.genesis_state - } - /// Ensure that the given state DB has the trie nodes in for the genesis state. pub fn ensure_db_good(&self, db: T, factories: &Factories) -> Result { if db.as_hash_db().contains(&self.state_root(), hash_db::EMPTY_PREFIX) { @@ -545,20 +479,19 @@ impl Spec { pub fn load_machine(reader: R) -> Result { ethjson::spec::Spec::load(reader) .map_err(fmt_err) - .map(load_machine_from) + .map(|s| { + let builtins = s.accounts.builtins().into_iter().map(|p| (p.0.into(), From::from(p.1))).collect(); + let params = CommonParams::from(s.params); + Spec::machine(&s.engine, params, builtins) + }) } /// Loads spec from json file. Provide factories for executing contracts and ensuring /// storage goes to the right place. - pub fn load<'a, T: Into>, R>(params: T, reader: R) -> Result - where - R: Read, - { - ethjson::spec::Spec::load(reader).map_err(fmt_err).and_then( - |x| { - load_from(params.into(), x).map_err(fmt_err) - }, - ) + pub fn load<'a, T: Into>, R: Read>(params: T, reader: R) -> Result { + ethjson::spec::Spec::load(reader) + .map_err(fmt_err) + .and_then(|x| load_from(params.into(), x).map_err(fmt_err)) } /// initialize genesis epoch data, using in-memory database for @@ -616,94 +549,6 @@ impl Spec { self.engine.genesis_epoch_data(&genesis, &call) } - - /// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring - /// work). - pub fn new_instant() -> Spec { - load_bundled!("instant_seal") - } - - /// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a - /// NullEngine consensus. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test() -> Spec { - load_bundled!("null_morden") - } - - /// Create the Machine corresponding to Spec::new_test. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_machine() -> Machine { load_machine_bundled!("null_morden") } - - /// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") } - - /// Create a new Spec which is a NullEngine consensus with a premine of address whose - /// secret is keccak(''). - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_null() -> Spec { - load_bundled!("null") - } - - /// Create a new Spec which constructs a contract at address 5 with storage at 0 equal to 1. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_constructor() -> Spec { - load_bundled!("constructor") - } - - /// Create a new Spec with AuthorityRound consensus which does internal sealing (not - /// requiring work). - /// Accounts with secrets keccak("0") and keccak("1") are the validators. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_round() -> Self { - load_bundled!("authority_round") - } - - /// Create a new Spec with AuthorityRound consensus which does internal sealing (not - /// requiring work) with empty step messages enabled. - /// Accounts with secrets keccak("0") and keccak("1") are the validators. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_round_empty_steps() -> Self { - load_bundled!("authority_round_empty_steps") - } - - /// Create a new Spec with AuthorityRound consensus (with empty steps) using a block reward - /// contract. The contract source code can be found at: - /// https://github.com/parity-contracts/block-reward/blob/daf7d44383b6cdb11cb6b953b018648e2b027cfb/contracts/ExampleBlockReward.sol - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_round_block_reward_contract() -> Self { - load_bundled!("authority_round_block_reward_contract") - } - - /// TestList.sol used in both specs: https://github.com/paritytech/contracts/pull/30/files - /// Accounts with secrets keccak("0") and keccak("1") are initially the validators. - /// Create a new Spec with BasicAuthority which uses a contract at address 5 to determine - /// the current validators using `getValidators`. - /// Second validator can be removed with - /// "0xbfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1" and added - /// back in using - /// "0x4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1". - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_validator_safe_contract() -> Self { - load_bundled!("validator_safe_contract") - } - - /// The same as the `safeContract`, but allows reporting and uses AuthorityRound. - /// Account is marked with `reportBenign` it can be checked as disliked with "0xd8f2e0bf". - /// Validator can be removed with `reportMalicious`. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_validator_contract() -> Self { - load_bundled!("validator_contract") - } - - /// Create a new Spec with BasicAuthority which uses multiple validator sets changing with - /// height. - /// Account with secrets keccak("0") is the validator for block 1 and with keccak("1") - /// onwards. - #[cfg(any(test, feature = "test-helpers"))] - pub fn new_validator_multi() -> Self { - load_bundled!("validator_multi") - } } #[cfg(test)] @@ -715,6 +560,7 @@ mod tests { use types::view; use types::views::BlockView; use std::str::FromStr; + use crate::spec::bundle; #[test] fn test_load_empty() { @@ -724,7 +570,7 @@ mod tests { #[test] fn test_chain() { - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); assert_eq!( test_spec.state_root(), @@ -740,7 +586,7 @@ mod tests { #[test] fn genesis_constructor() { let _ = ::env_logger::try_init(); - let spec = Spec::new_test_constructor(); + let spec = bundle::new_test_constructor(); let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()) .unwrap(); let state = State::from_existing( diff --git a/ethcore/src/test_helpers.rs b/ethcore/src/test_helpers.rs index 5c1db24a247..c708ae36d3d 100644 --- a/ethcore/src/test_helpers.rs +++ b/ethcore/src/test_helpers.rs @@ -43,7 +43,7 @@ use block::{OpenBlock, Drain}; use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock}; use trie_vm_factories::Factories; use miner::Miner; -use spec::Spec; +use spec::{bundle, Spec}; use account_state::*; use state_db::StateDB; use verification::queue::kind::blocks::Unverified; @@ -100,16 +100,16 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa /// Generates dummy client (not test client) with corresponding amount of blocks pub fn generate_dummy_client(block_number: u32) -> Arc { - generate_dummy_client_with_spec_and_data(Spec::new_test, block_number, 0, &[]) + generate_dummy_client_with_spec_and_data(bundle::new_test, block_number, 0, &[]) } /// Generates dummy client (not test client) with corresponding amount of blocks and txs per every block pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc { - generate_dummy_client_with_spec_and_data(Spec::new_null, block_number, txs_per_block, tx_gas_prices) + generate_dummy_client_with_spec_and_data(bundle::new_null, block_number, txs_per_block, tx_gas_prices) } /// Generates dummy client (not test client) with corresponding spec and accounts -pub fn generate_dummy_client_with_spec(test_spec: F) -> Arc where F: Fn()->Spec { +pub fn generate_dummy_client_with_spec(test_spec: F) -> Arc where F: Fn() -> Spec { generate_dummy_client_with_spec_and_data(test_spec, 0, 0, &[]) } @@ -188,7 +188,7 @@ pub fn generate_dummy_client_with_spec_and_data(test_spec: F, block_number: u /// Adds blocks to the client pub fn push_blocks_to_client(client: &Arc, timestamp_salt: u64, starting_number: usize, block_number: usize) { - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let state_root = test_spec.genesis_header().state_root().clone(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); @@ -218,7 +218,7 @@ pub fn push_blocks_to_client(client: &Arc, timestamp_salt: u64, starting /// Adds one block with transactions pub fn push_block_with_transactions(client: &Arc, transactions: &[SignedTransaction]) { - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let test_engine = &*test_spec.engine; let block_number = client.chain_info().best_block_number as u64 + 1; @@ -240,7 +240,7 @@ pub fn push_block_with_transactions(client: &Arc, transactions: &[Signed /// Creates dummy client (not test client) with corresponding blocks pub fn get_test_client_with_blocks(blocks: Vec) -> Arc { - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let client_db = new_db(); let client = Client::new( @@ -432,13 +432,13 @@ pub fn get_temp_state_db() -> StateDB { /// Returns sequence of hashes of the dummy blocks pub fn get_good_dummy_block_seq(count: usize) -> Vec { - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); get_good_dummy_block_fork_seq(1, count, &test_spec.genesis_header().hash()) } /// Returns sequence of hashes of the dummy blocks beginning from corresponding parent pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_hash: &H256) -> Vec { - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); let mut rolling_timestamp = start_number as u64 * 10; let mut parent = *parent_hash; @@ -463,7 +463,7 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h /// Returns hash and header of the correct dummy block pub fn get_good_dummy_block_hash() -> (H256, Bytes) { let mut block_header = Header::new(); - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); block_header.set_gas_limit(genesis_gas); block_header.set_difficulty(U256::from(0x20000)); @@ -484,7 +484,7 @@ pub fn get_good_dummy_block() -> Bytes { /// Returns hash of the dummy block with incorrect state root pub fn get_bad_state_dummy_block() -> Bytes { let mut block_header = Header::new(); - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); block_header.set_gas_limit(genesis_gas); diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index b319a85a13a..9e41d1ac7dd 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -29,10 +29,9 @@ use types::views::BlockView; use client::{BlockChainClient, BlockChainReset, Client, ClientConfig, BlockId, ChainInfo, PrepareOpenBlock, ImportSealedBlock, ImportBlock}; use client::BlockInfo; -use ethereum; +use crate::spec::bundle; use executive::{Executive, TransactOptions}; use miner::{Miner, PendingOrdering, MinerService}; -use spec::Spec; use account_state::{State, CleanupMode, backend}; use test_helpers::{ self, @@ -44,7 +43,7 @@ use verification::queue::kind::blocks::Unverified; #[test] fn imports_from_empty() { let db = test_helpers::new_db(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let client = Client::new( ClientConfig::default(), @@ -61,7 +60,7 @@ fn imports_from_empty() { fn should_return_registrar() { let db = test_helpers::new_db(); let tempdir = TempDir::new("").unwrap(); - let spec = ethereum::new_morden(&tempdir.path().to_owned()); + let spec = bundle::new_morden(&tempdir.path().to_owned()); let client = Client::new( ClientConfig::default(), @@ -77,7 +76,7 @@ fn should_return_registrar() { #[test] fn returns_state_root_basic() { let client = generate_dummy_client(6); - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); let genesis_header = test_spec.genesis_header(); assert!(client.state_data(genesis_header.state_root()).is_some()); @@ -86,7 +85,7 @@ fn returns_state_root_basic() { #[test] fn imports_good_block() { let db = test_helpers::new_db(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let client = Client::new( ClientConfig::default(), @@ -109,7 +108,7 @@ fn imports_good_block() { #[test] fn query_none_block() { let db = test_helpers::new_db(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let client = Client::new( ClientConfig::default(), @@ -257,7 +256,7 @@ fn can_mine() { #[test] fn change_history_size() { let db = test_helpers::new_db(); - let test_spec = Spec::new_null(); + let test_spec = bundle::new_null(); let mut config = ClientConfig::default(); config.history = 2; @@ -329,7 +328,7 @@ fn transaction_proof() { let client = generate_dummy_client(0); let address = Address::random(); - let test_spec = Spec::new_test(); + let test_spec = bundle::new_test(); for _ in 0..20 { let mut b = client.prepare_open_block(Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); b.block_mut().state_mut().add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap(); diff --git a/ethcore/src/tests/evm.rs b/ethcore/src/tests/evm.rs index d0b9c821db2..a0d4df76c6e 100644 --- a/ethcore/src/tests/evm.rs +++ b/ethcore/src/tests/evm.rs @@ -29,6 +29,7 @@ use types::transaction::SYSTEM_ADDRESS; use rustc_hex::FromHex; use ethereum_types::{H256, Address}; +use crate::spec::bundle; evm_test!{test_blockhash_eip210: test_blockhash_eip210_int} fn test_blockhash_eip210(factory: Factory) { @@ -38,7 +39,7 @@ fn test_blockhash_eip210(factory: Factory) { let test_blockhash_contract = "73fffffffffffffffffffffffffffffffffffffffe33141561007a57600143036020526000356101006020510755600061010060205107141561005057600035610100610100602051050761010001555b6000620100006020510714156100755760003561010062010000602051050761020001555b61014a565b4360003512151561009057600060405260206040f35b610100600035430312156100b357610100600035075460605260206060f3610149565b62010000600035430312156100d157600061010060003507146100d4565b60005b156100f6576101006101006000350507610100015460805260206080f3610148565b630100000060003543031215610116576000620100006000350714610119565b60005b1561013c57610100620100006000350507610200015460a052602060a0f3610147565b600060c052602060c0f35b5b5b5b5b"; let blockhash_contract_code = Arc::new(test_blockhash_contract.from_hex().unwrap()); let blockhash_contract_code_hash = keccak(blockhash_contract_code.as_ref()); - let machine = ::ethereum::new_eip210_test_machine(); + let machine = bundle::new_eip210_test_machine(); let mut env_info = EnvInfo::default(); // populate state with 256 last hashes diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index b80c7485128..2461ae43216 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -21,7 +21,7 @@ use hash::keccak; use block::*; use ethereum_types::{U256, Address}; use io::*; -use spec::*; +use spec::bundle; use client::*; use test_helpers::get_temp_state_db; use client::{BlockChainClient, Client, ClientConfig}; @@ -40,7 +40,7 @@ use types::views::BlockView; #[test] fn can_trace_block_and_uncle_reward() { let db = test_helpers::new_db(); - let spec = Spec::new_test_with_reward(); + let spec = bundle::new_test_with_reward(); let engine = &*spec.engine; // Create client diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 94bc4943724..21bee8aa50f 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -734,7 +734,7 @@ impl Drop for VerificationQueue { #[cfg(test)] mod tests { use io::*; - use spec::Spec; + use spec::bundle; use super::{BlockQueue, Config, State}; use super::kind::blocks::Unverified; use test_helpers::{get_good_dummy_block_seq, get_good_dummy_block}; @@ -748,7 +748,7 @@ mod tests { // create a test block queue. // auto_scaling enables verifier adjustment. fn get_test_queue(auto_scale: bool) -> BlockQueue { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let mut config = Config::default(); @@ -770,7 +770,7 @@ mod tests { #[test] fn can_be_created() { // TODO better test - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let _ = BlockQueue::new(Config::default(), engine, IoChannel::disconnected(), true); } @@ -848,7 +848,7 @@ mod tests { #[test] fn test_mem_limit() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let mut config = Config::default(); config.max_mem_use = super::MIN_MEM_LIMIT; // empty queue uses about 15000 @@ -899,7 +899,7 @@ mod tests { #[test] fn worker_threads_honor_specified_number_without_scaling() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let config = get_test_config(1, false); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); @@ -909,7 +909,7 @@ mod tests { #[test] fn worker_threads_specified_to_zero_should_set_to_one() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let config = get_test_config(0, false); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); @@ -919,7 +919,7 @@ mod tests { #[test] fn worker_threads_should_only_accept_max_number_cpus() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let config = get_test_config(10_000, false); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); @@ -933,7 +933,7 @@ mod tests { let num_cpus = ::num_cpus::get(); // only run the test with at least 2 CPUs if num_cpus > 1 { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = spec.engine; let config = get_test_config(num_cpus - 1, true); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 0bde0e2859c..89930cd7530 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -372,7 +372,7 @@ mod tests { use hash::keccak; use engines::Engine; use ethkey::{Random, Generator}; - use spec::Spec; + use spec::bundle; use test_helpers::{create_test_block_with_data, create_test_block}; use types::{ encoded, @@ -546,7 +546,7 @@ mod tests { #[test] fn test_verify_block_basic_with_invalid_transactions() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = &*spec.engine; let block = { @@ -571,7 +571,7 @@ mod tests { // Test against morden let mut good = Header::new(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let engine = &*spec.engine; let min_gas_limit = engine.params().min_gas_limit; From 5ac5bd737735215b4017c6be7357cd8301965b04 Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 6 Aug 2019 16:35:32 +0200 Subject: [PATCH 2/5] fixed failing tests --- ethcore/light/src/client/header_chain.rs | 18 ++++----- ethcore/light/src/client/service.rs | 4 +- ethcore/private-tx/tests/private_contract.rs | 5 ++- ethcore/service/src/service.rs | 4 +- ethcore/src/json_tests/difficulty.rs | 4 +- ethcore/src/json_tests/executive.rs | 3 +- ethcore/src/miner/miner.rs | 3 +- ethcore/src/spec/bundle.rs | 4 +- ethcore/sync/src/block_sync.rs | 8 ++-- ethcore/sync/src/light_sync/tests/test_net.rs | 4 +- ethcore/sync/src/tests/chain.rs | 3 +- ethcore/sync/src/tests/consensus.rs | 6 +-- ethcore/sync/src/tests/helpers.rs | 4 +- evmbin/src/info.rs | 10 +++-- evmbin/src/main.rs | 2 +- parity/params.rs | 37 +++++++++---------- rpc/src/v1/tests/eth.rs | 5 +-- 17 files changed, 64 insertions(+), 60 deletions(-) diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index 1722403886d..6d064f87419 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -874,7 +874,7 @@ mod tests { use cache::Cache; use common_types::header::Header; use common_types::ids::BlockId; - use ethcore::spec::Spec; + use ethcore::spec::bundle; use ethereum_types::U256; use kvdb::KeyValueDB; use kvdb_memorydb; @@ -888,7 +888,7 @@ mod tests { #[test] fn basic_chain() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); @@ -922,7 +922,7 @@ mod tests { #[test] fn reorganize() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1005,7 +1005,7 @@ mod tests { #[test] fn earliest_is_latest() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1017,7 +1017,7 @@ mod tests { #[test] fn restore_from_db() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1055,7 +1055,7 @@ mod tests { #[test] fn restore_higher_non_canonical() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1112,7 +1112,7 @@ mod tests { #[test] fn genesis_header_available() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1127,7 +1127,7 @@ mod tests { #[test] fn epoch_transitions_available_after_cht() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1193,7 +1193,7 @@ mod tests { #[test] fn hardcoded_sync_gen() { - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); diff --git a/ethcore/light/src/client/service.rs b/ethcore/light/src/client/service.rs index f08f05975b6..262e7117408 100644 --- a/ethcore/light/src/client/service.rs +++ b/ethcore/light/src/client/service.rs @@ -113,7 +113,7 @@ impl IoHandler for ImportBlocks { #[cfg(test)] mod tests { use super::Service; - use ethcore::spec::Spec; + use ethcore::spec::bundle; use std::sync::Arc; use cache::Cache; @@ -125,7 +125,7 @@ mod tests { #[test] fn it_works() { let db = test_helpers::new_db(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); Service::start(Default::default(), &spec, fetch::unavailable(), db, cache).unwrap(); diff --git a/ethcore/private-tx/tests/private_contract.rs b/ethcore/private-tx/tests/private_contract.rs index 75d73dda4b4..defdc6958c3 100644 --- a/ethcore/private-tx/tests/private_contract.rs +++ b/ethcore/private-tx/tests/private_contract.rs @@ -38,6 +38,7 @@ use ethcore::client::BlockChainClient; use ethcore::executive::contract_address; use ethcore::miner::Miner; use ethcore::test_helpers::{generate_dummy_client, push_block_with_transactions}; +use ethcore::spec::bundle; use ethkey::{Secret, KeyPair, Signature}; use hash::keccak; @@ -63,7 +64,7 @@ fn private_contract() { }; let io = ethcore_io::IoChannel::disconnected(); - let miner = Arc::new(Miner::new_for_tests(&::ethcore::spec::Spec::new_test(), None)); + let miner = Arc::new(Miner::new_for_tests(&bundle::new_test(), None)); let private_keys = Arc::new(StoringKeyProvider::default()); let pm = Arc::new(Provider::new( client.clone(), @@ -198,7 +199,7 @@ fn call_other_private_contract() { }; let io = ethcore_io::IoChannel::disconnected(); - let miner = Arc::new(Miner::new_for_tests(&::ethcore::spec::Spec::new_test(), None)); + let miner = Arc::new(Miner::new_for_tests(&bundle::new_test(), None)); let private_keys = Arc::new(StoringKeyProvider::default()); let pm = Arc::new(Provider::new( client.clone(), diff --git a/ethcore/service/src/service.rs b/ethcore/service/src/service.rs index 8496f5a0d53..663635197bd 100644 --- a/ethcore/service/src/service.rs +++ b/ethcore/service/src/service.rs @@ -283,7 +283,7 @@ mod tests { use ethcore_db::NUM_COLUMNS; use ethcore::client::ClientConfig; use ethcore::miner::Miner; - use ethcore::spec::Spec; + use ethcore::spec::bundle; use ethcore::test_helpers; use kvdb_rocksdb::{DatabaseConfig, CompactionProfile}; use super::*; @@ -306,7 +306,7 @@ mod tests { let client_db = client_db_handler.open(&client_path).unwrap(); let restoration_db_handler = test_helpers::restoration_db_handler(client_db_config); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let service = ClientService::start( ClientConfig::default(), &spec, diff --git a/ethcore/src/json_tests/difficulty.rs b/ethcore/src/json_tests/difficulty.rs index bf3a48fff19..f73956fb4e9 100644 --- a/ethcore/src/json_tests/difficulty.rs +++ b/ethcore/src/json_tests/difficulty.rs @@ -61,7 +61,7 @@ macro_rules! difficulty_json_test { fn do_json_test(json_data: &[u8], h: &mut H) -> Vec { let tempdir = TempDir::new("").unwrap(); - json_difficulty_test(json_data, ::ethereum::$spec(&tempdir.path()), h) + json_difficulty_test(json_data, crate::spec::bundle::$spec(&tempdir.path()), h) } } @@ -74,7 +74,7 @@ macro_rules! difficulty_json_test_nopath { use json_tests::HookType; fn do_json_test(json_data: &[u8], h: &mut H) -> Vec { - json_difficulty_test(json_data, ::ethereum::$spec(), h) + json_difficulty_test(json_data, crate::spec::bundle::$spec(), h) } } diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index 86fa59bb2d8..f8d6379d010 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -37,6 +37,7 @@ use rlp::RlpStream; use hash::keccak; use machine::Machine; use ethereum_types::BigEndianHash; +use crate::spec::bundle; use super::HookType; @@ -271,7 +272,7 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8] state.populate_from(From::from(vm.pre_state.clone())); let info: EnvInfo = From::from(vm.env); let machine = { - let mut machine = ::ethereum::new_frontier_test_machine(); + let mut machine = bundle::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = 1)); machine }; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index cf5a24bd21e..665b20e9286 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -60,7 +60,7 @@ use client::{ use client::BlockId; use engines::{Engine, Seal, EngineSigner}; use executive::contract_address; -use spec::{Spec, bundle}; +use spec::Spec; use account_state::State; use vm::CreateContractAddress; @@ -1488,6 +1488,7 @@ mod tests { use miner::{MinerService, PendingOrdering}; use test_helpers::{generate_dummy_client, generate_dummy_client_with_spec}; use types::transaction::{Transaction}; + use crate::spec::bundle; #[test] fn should_prepare_block_to_seal() { diff --git a/ethcore/src/spec/bundle.rs b/ethcore/src/spec/bundle.rs index e8a1755bd33..3207bc88b16 100644 --- a/ethcore/src/spec/bundle.rs +++ b/ethcore/src/spec/bundle.rs @@ -104,8 +104,8 @@ bundle_test_spec! { "null_morden" => new_test, "null_morden_with_reward" => new_test_with_reward, "validator_contract" => new_validator_contract, - "validator_safe_contract" => new_validator_safe_contract, - "validator_multi" => new_validator_multi + "validator_multi" => new_validator_multi, + "validator_safe_contract" => new_validator_safe_contract } bundle_test_machine! { diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index 1d04c1c6df6..556ff35f8a9 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -636,7 +636,7 @@ fn all_expected(values: &[A], expected_values: &[B], is_expected: F) -> mod tests { use super::*; use ethcore::client::TestBlockChainClient; - use ethcore::spec::Spec; + use ethcore::spec::bundle; use ethkey::{Generator,Random}; use hash::keccak; use parking_lot::RwLock; @@ -681,7 +681,7 @@ mod tests { fn import_headers_in_chain_head_state() { ::env_logger::try_init().ok(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_hash = spec.genesis_header().hash(); let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0); @@ -930,7 +930,7 @@ mod tests { fn reset_after_multiple_sets_of_useless_headers() { ::env_logger::try_init().ok(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_hash = spec.genesis_header().hash(); let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0); @@ -970,7 +970,7 @@ mod tests { fn dont_reset_after_multiple_sets_of_useless_headers_for_chain_head() { ::env_logger::try_init().ok(); - let spec = Spec::new_test(); + let spec = bundle::new_test(); let genesis_hash = spec.genesis_header().hash(); let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0); diff --git a/ethcore/sync/src/light_sync/tests/test_net.rs b/ethcore/sync/src/light_sync/tests/test_net.rs index 74567c11925..da8d26a96a5 100644 --- a/ethcore/sync/src/light_sync/tests/test_net.rs +++ b/ethcore/sync/src/light_sync/tests/test_net.rs @@ -23,7 +23,7 @@ use light_sync::*; use tests::helpers::{TestNet, Peer as PeerLike, TestPacket}; use ethcore::client::TestBlockChainClient; -use ethcore::spec::Spec; +use ethcore::spec::bundle; use io::IoChannel; use kvdb_memorydb; use light::client::fetch::{self, Unavailable}; @@ -229,7 +229,7 @@ impl TestNet { config, Arc::new(db), None, - &Spec::new_test(), + &bundle::new_test(), fetch::unavailable(), // TODO: allow fetch from full nodes. IoChannel::disconnected(), cache diff --git a/ethcore/sync/src/tests/chain.rs b/ethcore/sync/src/tests/chain.rs index d81a876d7a8..b0c994e8495 100644 --- a/ethcore/sync/src/tests/chain.rs +++ b/ethcore/sync/src/tests/chain.rs @@ -19,6 +19,7 @@ use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockId, EachBlock use chain::{SyncState}; use super::helpers::*; use {SyncConfig, WarpSync}; +use ethcore::spec::bundle; #[test] fn two_peers() { @@ -101,7 +102,7 @@ fn forked_with_misbehaving_peer() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); - let mut alt_spec = ::ethcore::spec::Spec::new_test(); + let mut alt_spec = bundle::new_test(); alt_spec.extra_data = b"fork".to_vec(); // peer 0 is on a totally different chain with higher total difficulty net.peer_mut(0).chain = Arc::new(TestBlockChainClient::new_with_spec(alt_spec)); diff --git a/ethcore/sync/src/tests/consensus.rs b/ethcore/sync/src/tests/consensus.rs index ffa3b66d5e9..14b99d0ea61 100644 --- a/ethcore/sync/src/tests/consensus.rs +++ b/ethcore/sync/src/tests/consensus.rs @@ -20,7 +20,7 @@ use ethereum_types::{U256, Address}; use io::{IoHandler, IoChannel}; use ethcore::client::{ChainInfo, ClientIoMessage}; use ethcore::engines; -use ethcore::spec::Spec; +use ethcore::spec::bundle; use ethcore::miner::{self, MinerService}; use ethkey::{KeyPair, Secret}; use types::transaction::{Action, PendingTransaction, Transaction}; @@ -44,8 +44,8 @@ fn authority_round() { let s0 = KeyPair::from_secret_slice(keccak("1").as_bytes()).unwrap(); let s1 = KeyPair::from_secret_slice(keccak("0").as_bytes()).unwrap(); - let chain_id = Spec::new_test_round().chain_id(); - let mut net = TestNet::with_spec(2, SyncConfig::default(), Spec::new_test_round); + let chain_id = bundle::new_test_round().chain_id(); + let mut net = TestNet::with_spec(2, SyncConfig::default(), bundle::new_test_round); let io_handler0: Arc> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone())); let io_handler1: Arc> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone())); // Push transaction to both clients. Only one of them gets lucky to produce a block. diff --git a/ethcore/sync/src/tests/helpers.rs b/ethcore/sync/src/tests/helpers.rs index fbf37dc8b69..3f8f766b16c 100644 --- a/ethcore/sync/src/tests/helpers.rs +++ b/ethcore/sync/src/tests/helpers.rs @@ -25,7 +25,7 @@ use tests::snapshot::*; use ethcore::client::{TestBlockChainClient, BlockChainClient, Client as EthcoreClient, ClientConfig, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage}; use ethcore::snapshot::SnapshotService; -use ethcore::spec::Spec; +use ethcore::spec::{bundle, Spec}; use ethcore::miner::Miner; use ethcore::test_helpers; use sync_io::SyncIo; @@ -351,7 +351,7 @@ impl TestNet> { sync: RwLock::new(sync), snapshot_service: ss, chain: Arc::new(chain), - miner: Arc::new(Miner::new_for_tests(&Spec::new_test(), None)), + miner: Arc::new(Miner::new_for_tests(&bundle::new_test(), None)), queue: RwLock::new(VecDeque::new()), private_tx_handler, io_queue: RwLock::new(VecDeque::new()), diff --git a/evmbin/src/info.rs b/evmbin/src/info.rs index ed6d1fd0dcd..c2557e22b08 100644 --- a/evmbin/src/info.rs +++ b/evmbin/src/info.rs @@ -88,12 +88,12 @@ pub fn run_action( // if the code is not overwritten from CLI, use code from spec file. if params.code.is_none() { - if let Some(acc) = spec.genesis_state().get().get(¶ms.code_address) { + if let Some(acc) = spec.genesis_state.get().get(¶ms.code_address) { params.code = acc.code.clone().map(::std::sync::Arc::new); params.code_hash = None; } } - run(spec, trie_spec, params.gas, spec.genesis_state(), |mut client| { + run(spec, trie_spec, params.gas, &spec.genesis_state, |mut client| { let result = match client.call(params, &mut trace::NoopTracer, &mut informant) { Ok(r) => (Ok(r.return_data.to_vec()), Some(r.gas_left)), Err(err) => (Err(err), None), @@ -211,6 +211,7 @@ pub mod tests { use super::*; use tempdir::TempDir; use ethereum_types::Address; + use ethcore::spec::{bundle, Spec}; pub fn run_test( informant: I, @@ -228,7 +229,7 @@ pub mod tests { params.gas = gas.into(); let tempdir = TempDir::new("").unwrap(); - let spec = ::ethcore::ethereum::new_foundation(&tempdir.path()); + let spec = bundle::new_foundation(&tempdir.path()); let result = run_action(&spec, params, informant, TrieSpec::Secure); match result { Ok(Success { traces, .. }) => { @@ -249,7 +250,8 @@ pub mod tests { params.code_address = Address::from_low_u64_be(0x20); params.gas = 0xffff.into(); - let spec = ::ethcore::ethereum::load(None, include_bytes!("../res/testchain.json")); + let tempdir = TempDir::new("").unwrap(); + let spec = Spec::load(&tempdir.path(), include_bytes!("../res/testchain.json") as &[u8]).unwrap(); let _result = run_action(&spec, params, inf, TrieSpec::Secure); assert_eq!( diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index 845642c6027..47b7153e7fe 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -339,7 +339,7 @@ impl Args { spec::Spec::load(&::std::env::temp_dir(), file)? }, None => { - ethcore::ethereum::new_foundation(&::std::env::temp_dir()) + spec::bundle::new_foundation(&::std::env::temp_dir()) }, }) } diff --git a/parity/params.rs b/parity/params.rs index c8b48f61a12..2b0cf58dce2 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -19,8 +19,7 @@ use std::time::Duration; use std::{str, fs, fmt}; use ethcore::client::Mode; -use ethcore::ethereum; -use ethcore::spec::{Spec, SpecParams}; +use ethcore::spec::{Spec, SpecParams, bundle}; use ethereum_types::{U256, Address}; use parity_runtime::Executor; use hash_fetch::fetch::Client as FetchClient; @@ -115,23 +114,23 @@ impl SpecType { pub fn spec<'a, T: Into>>(&self, params: T) -> Result { 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::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::Foundation => Ok(bundle::new_foundation(params)), + SpecType::Classic => Ok(bundle::new_classic(params)), + SpecType::Poanet => Ok(bundle::new_poanet(params)), + SpecType::Tobalaba => Ok(bundle::new_tobalaba(params)), + SpecType::Expanse => Ok(bundle::new_expanse(params)), + SpecType::Musicoin => Ok(bundle::new_musicoin(params)), + SpecType::Ellaism => Ok(bundle::new_ellaism(params)), + SpecType::Mix => Ok(bundle::new_mix(params)), + SpecType::Callisto => Ok(bundle::new_callisto(params)), + SpecType::Morden => Ok(bundle::new_morden(params)), + SpecType::Ropsten => Ok(bundle::new_ropsten(params)), + SpecType::Kovan => Ok(bundle::new_kovan(params)), + SpecType::Rinkeby => Ok(bundle::new_rinkeby(params)), + SpecType::Goerli => Ok(bundle::new_goerli(params)), + SpecType::Kotti => Ok(bundle::new_kotti(params)), + SpecType::Sokol => Ok(bundle::new_sokol(params)), + SpecType::Dev => Ok(bundle::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) diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 94ef264c250..7a8350ddf3e 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -20,9 +20,8 @@ use std::sync::Arc; use accounts::AccountProvider; use ethcore::client::{BlockChainClient, Client, ClientConfig, ChainInfo, ImportBlock}; -use ethcore::ethereum; use ethcore::miner::Miner; -use ethcore::spec::{Genesis, Spec}; +use ethcore::spec::{Genesis, Spec, bundle}; use ethcore::test_helpers; use ethcore::verification::VerifierType; use ethcore::verification::queue::kind::blocks::Unverified; @@ -64,7 +63,7 @@ fn snapshot_service() -> Arc { fn make_spec(chain: &BlockChain) -> Spec { let genesis = Genesis::from(chain.genesis()); - let mut spec = ethereum::new_frontier_test(); + let mut spec = bundle::new_frontier_test(); let state = chain.pre_state.clone().into(); spec.set_genesis_state(state).expect("unable to set genesis state"); spec.overwrite_genesis_params(genesis); From d7213b93a2422e2ecb3e409860c8f18b551b8ee4 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 7 Aug 2019 13:49:57 +0200 Subject: [PATCH 3/5] renamed bundle.rs to chain.rs --- ethcore/light/src/client/header_chain.rs | 18 +++++----- ethcore/light/src/client/service.rs | 4 +-- ethcore/private-tx/tests/private_contract.rs | 6 ++-- ethcore/service/src/service.rs | 4 +-- ethcore/src/block.rs | 8 ++--- ethcore/src/client/evm_test_client.rs | 17 +++++---- ethcore/src/client/test_client.rs | 4 +-- ethcore/src/engines/authority_round/mod.rs | 32 ++++++++--------- ethcore/src/engines/block_reward.rs | 6 ++-- ethcore/src/engines/clique/mod.rs | 4 +-- ethcore/src/engines/ethash.rs | 2 +- ethcore/src/engines/instant_seal.rs | 6 ++-- ethcore/src/engines/validator_set/contract.rs | 6 ++-- ethcore/src/engines/validator_set/multi.rs | 6 ++-- .../engines/validator_set/safe_contract.rs | 14 ++++---- ethcore/src/executive.rs | 14 ++++---- ethcore/src/executive_state.rs | 12 +++---- ethcore/src/externalities.rs | 4 +-- ethcore/src/json_tests/difficulty.rs | 4 +-- ethcore/src/json_tests/executive.rs | 4 +-- ethcore/src/machine.rs | 6 ++-- ethcore/src/miner/miner.rs | 28 +++++++-------- ethcore/src/snapshot/service.rs | 8 ++--- ethcore/src/snapshot/tests/proof_of_work.rs | 6 ++-- ethcore/src/snapshot/tests/service.rs | 16 ++++----- ethcore/src/spec/{bundle.rs => chain.rs} | 0 ethcore/src/spec/mod.rs | 3 +- ethcore/src/spec/spec.rs | 6 ++-- ethcore/src/test_helpers.rs | 20 +++++------ ethcore/src/tests/client.rs | 16 ++++----- ethcore/src/tests/evm.rs | 4 +-- ethcore/src/tests/trace.rs | 4 +-- ethcore/src/verification/queue/mod.rs | 16 ++++----- ethcore/src/verification/verification.rs | 6 ++-- ethcore/sync/src/block_sync.rs | 8 ++--- ethcore/sync/src/light_sync/tests/test_net.rs | 4 +-- ethcore/sync/src/tests/chain.rs | 4 +-- ethcore/sync/src/tests/consensus.rs | 6 ++-- ethcore/sync/src/tests/helpers.rs | 4 +-- evmbin/src/info.rs | 4 +-- evmbin/src/main.rs | 2 +- parity/params.rs | 36 +++++++++---------- rpc/src/v1/tests/eth.rs | 4 +-- 43 files changed, 193 insertions(+), 193 deletions(-) rename ethcore/src/spec/{bundle.rs => chain.rs} (100%) diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index 6d064f87419..3b9d2beec4b 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -874,7 +874,7 @@ mod tests { use cache::Cache; use common_types::header::Header; use common_types::ids::BlockId; - use ethcore::spec::bundle; + use ethcore::spec; use ethereum_types::U256; use kvdb::KeyValueDB; use kvdb_memorydb; @@ -888,7 +888,7 @@ mod tests { #[test] fn basic_chain() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); @@ -922,7 +922,7 @@ mod tests { #[test] fn reorganize() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1005,7 +1005,7 @@ mod tests { #[test] fn earliest_is_latest() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1017,7 +1017,7 @@ mod tests { #[test] fn restore_from_db() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1055,7 +1055,7 @@ mod tests { #[test] fn restore_higher_non_canonical() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1112,7 +1112,7 @@ mod tests { #[test] fn genesis_header_available() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1127,7 +1127,7 @@ mod tests { #[test] fn epoch_transitions_available_after_cht() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); @@ -1193,7 +1193,7 @@ mod tests { #[test] fn hardcoded_sync_gen() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = make_db(); diff --git a/ethcore/light/src/client/service.rs b/ethcore/light/src/client/service.rs index 262e7117408..ee002e02b89 100644 --- a/ethcore/light/src/client/service.rs +++ b/ethcore/light/src/client/service.rs @@ -113,7 +113,7 @@ impl IoHandler for ImportBlocks { #[cfg(test)] mod tests { use super::Service; - use ethcore::spec::bundle; + use ethcore::spec; use std::sync::Arc; use cache::Cache; @@ -125,7 +125,7 @@ mod tests { #[test] fn it_works() { let db = test_helpers::new_db(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::from_secs(6 * 3600)))); Service::start(Default::default(), &spec, fetch::unavailable(), db, cache).unwrap(); diff --git a/ethcore/private-tx/tests/private_contract.rs b/ethcore/private-tx/tests/private_contract.rs index defdc6958c3..f35693b5037 100644 --- a/ethcore/private-tx/tests/private_contract.rs +++ b/ethcore/private-tx/tests/private_contract.rs @@ -38,7 +38,7 @@ use ethcore::client::BlockChainClient; use ethcore::executive::contract_address; use ethcore::miner::Miner; use ethcore::test_helpers::{generate_dummy_client, push_block_with_transactions}; -use ethcore::spec::bundle; +use ethcore::spec; use ethkey::{Secret, KeyPair, Signature}; use hash::keccak; @@ -64,7 +64,7 @@ fn private_contract() { }; let io = ethcore_io::IoChannel::disconnected(); - let miner = Arc::new(Miner::new_for_tests(&bundle::new_test(), None)); + let miner = Arc::new(Miner::new_for_tests(&spec::new_test(), None)); let private_keys = Arc::new(StoringKeyProvider::default()); let pm = Arc::new(Provider::new( client.clone(), @@ -199,7 +199,7 @@ fn call_other_private_contract() { }; let io = ethcore_io::IoChannel::disconnected(); - let miner = Arc::new(Miner::new_for_tests(&bundle::new_test(), None)); + let miner = Arc::new(Miner::new_for_tests(&spec::new_test(), None)); let private_keys = Arc::new(StoringKeyProvider::default()); let pm = Arc::new(Provider::new( client.clone(), diff --git a/ethcore/service/src/service.rs b/ethcore/service/src/service.rs index 663635197bd..737d77254f2 100644 --- a/ethcore/service/src/service.rs +++ b/ethcore/service/src/service.rs @@ -283,7 +283,7 @@ mod tests { use ethcore_db::NUM_COLUMNS; use ethcore::client::ClientConfig; use ethcore::miner::Miner; - use ethcore::spec::bundle; + use ethcore::spec; use ethcore::test_helpers; use kvdb_rocksdb::{DatabaseConfig, CompactionProfile}; use super::*; @@ -306,7 +306,7 @@ mod tests { let client_db = client_db_handler.open(&client_path).unwrap(); let restoration_db_handler = test_helpers::restoration_db_handler(client_db_config); - let spec = bundle::new_test(); + let spec = spec::new_test(); let service = ClientService::start( ClientConfig::default(), &spec, diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index f88ab2d3cc7..10e0312a5e0 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -563,7 +563,7 @@ mod tests { errors::EthcoreError as Error, }; use hash_db::EMPTY_PREFIX; - use crate::spec::bundle; + use crate::spec; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header fn enact_bytes( @@ -634,7 +634,7 @@ mod tests { #[test] fn open_block() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_header = spec.genesis_header(); let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); @@ -645,7 +645,7 @@ mod tests { #[test] fn enact_block() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); @@ -669,7 +669,7 @@ mod tests { #[test] fn enact_block_with_uncle() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index ada59e28560..37d07d8d962 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -36,7 +36,6 @@ use vm::{self, ActionParams, CreateContractAddress}; use ethtrie; use account_state::{CleanupMode, State}; use substate::Substate; -use crate::spec::bundle; use executive_state::ExecutiveState; /// EVM test Error. @@ -99,14 +98,14 @@ impl<'a> EvmTestClient<'a> { /// Converts a json spec definition into spec. pub fn spec_from_json(spec: &ForkSpec) -> Option { match *spec { - ForkSpec::Frontier => Some(bundle::new_frontier_test()), - ForkSpec::Homestead => Some(bundle::new_homestead_test()), - ForkSpec::EIP150 => Some(bundle::new_eip150_test()), - ForkSpec::EIP158 => Some(bundle::new_eip161_test()), - ForkSpec::Byzantium => Some(bundle::new_byzantium_test()), - ForkSpec::Constantinople => Some(bundle::new_constantinople_test()), - ForkSpec::ConstantinopleFix => Some(bundle::new_constantinople_fix_test()), - ForkSpec::EIP158ToByzantiumAt5 => Some(bundle::new_transition_test()), + ForkSpec::Frontier => Some(spec::new_frontier_test()), + ForkSpec::Homestead => Some(spec::new_homestead_test()), + ForkSpec::EIP150 => Some(spec::new_eip150_test()), + ForkSpec::EIP158 => Some(spec::new_eip161_test()), + ForkSpec::Byzantium => Some(spec::new_byzantium_test()), + ForkSpec::Constantinople => Some(spec::new_constantinople_test()), + ForkSpec::ConstantinopleFix => Some(spec::new_constantinople_fix_test()), + ForkSpec::EIP158ToByzantiumAt5 => Some(spec::new_transition_test()), ForkSpec::FrontierToHomesteadAt5 | ForkSpec::HomesteadToDaoAt5 | ForkSpec::HomesteadToEIP150At5 => None, } } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 85122f3adde..8095db1fd3b 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -66,7 +66,7 @@ use engines::Engine; use executive::Executed; use journaldb; use miner::{self, Miner, MinerService}; -use spec::{Spec, bundle}; +use spec::{Spec, self}; use account_state::state::StateInfo; use state_db::StateDB; use trace::LocalizedTrace; @@ -152,7 +152,7 @@ impl TestBlockChainClient { /// Creates new test client with specified extra data for each block pub fn new_with_extra_data(extra_data: Bytes) -> Self { - let spec = bundle::new_test(); + let spec = spec::new_test(); TestBlockChainClient::new_with_spec_and_extra(spec, extra_data) } diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index e27cf662005..ad06a80e7d6 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -1636,7 +1636,7 @@ mod tests { generate_dummy_client_with_spec, get_temp_state_db, TestNotify }; - use spec::{Spec, bundle}; + use crate::spec::{Spec, self}; use engines::{Seal, Engine}; use engines::validator_set::{TestSet, SimpleList}; use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score}; @@ -1673,13 +1673,13 @@ mod tests { #[test] fn has_valid_metadata() { - let engine = bundle::new_test_round().engine; + let engine = spec::new_test_round().engine; assert!(!engine.name().is_empty()); } #[test] fn can_return_schedule() { - let engine = bundle::new_test_round().engine; + let engine = spec::new_test_round().engine; let schedule = engine.schedule(10000000); assert!(schedule.stack_limit > 0); @@ -1687,7 +1687,7 @@ mod tests { #[test] fn can_do_signature_verification_fail() { - let engine = bundle::new_test_round().engine; + let engine = spec::new_test_round().engine; let mut header: Header = Header::default(); header.set_seal(vec![encode(&H520::default())]); @@ -1701,7 +1701,7 @@ mod tests { let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); let addr2 = tap.insert_account(keccak("2").into(), &"2".into()).unwrap(); - let spec = bundle::new_test_round(); + let spec = spec::new_test_round(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); let db1 = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); @@ -1733,7 +1733,7 @@ mod tests { let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); let addr2 = tap.insert_account(keccak("0").into(), &"0".into()).unwrap(); - let spec = bundle::new_test_round(); + let spec = spec::new_test_round(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); @@ -1773,7 +1773,7 @@ mod tests { header.set_gas_limit("222222".parse::().unwrap()); header.set_author(addr); - let engine = bundle::new_test_round().engine; + let engine = spec::new_test_round().engine; // Two validators. // Spec starts with step 2. @@ -1802,7 +1802,7 @@ mod tests { header.set_gas_limit("222222".parse::().unwrap()); header.set_author(addr); - let engine = bundle::new_test_round().engine; + let engine = spec::new_test_round().engine; // Two validators. // Spec starts with step 2. @@ -1828,7 +1828,7 @@ mod tests { header.set_gas_limit("222222".parse::().unwrap()); header.set_author(addr); - let engine = bundle::new_test_round().engine; + let engine = spec::new_test_round().engine; let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap(); // Two validators. @@ -1931,7 +1931,7 @@ mod tests { } fn setup_empty_steps() -> (Spec, Arc, Vec
) { - let spec = bundle::new_test_round_empty_steps(); + let spec = spec::new_test_round_empty_steps(); let tap = Arc::new(AccountProvider::transient_provider()); let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); @@ -1984,7 +1984,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(spec::new_test_round_empty_steps); let notify = Arc::new(TestNotify::default()); client.add_notify(notify.clone()); engine.register_client(Arc::downgrade(&client) as _); @@ -2023,7 +2023,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(spec::new_test_round_empty_steps); let notify = Arc::new(TestNotify::default()); client.add_notify(notify.clone()); engine.register_client(Arc::downgrade(&client) as _); @@ -2076,7 +2076,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(spec::new_test_round_empty_steps); let notify = Arc::new(TestNotify::default()); client.add_notify(notify.clone()); engine.register_client(Arc::downgrade(&client) as _); @@ -2128,7 +2128,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(bundle::new_test_round_empty_steps); + let client = generate_dummy_client_with_spec(spec::new_test_round_empty_steps); engine.register_client(Arc::downgrade(&client) as _); // step 2 @@ -2215,7 +2215,7 @@ mod tests { #[test] fn block_reward_contract() { - let spec = bundle::new_test_round_block_reward_contract(); + let spec = spec::new_test_round_block_reward_contract(); let tap = Arc::new(AccountProvider::transient_provider()); let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); @@ -2227,7 +2227,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); - let client = generate_dummy_client_with_spec(bundle::new_test_round_block_reward_contract); + let client = generate_dummy_client_with_spec(spec::new_test_round_block_reward_contract); engine.register_client(Arc::downgrade(&client) as _); // step 2 diff --git a/ethcore/src/engines/block_reward.rs b/ethcore/src/engines/block_reward.rs index 1dd3d4105c2..58ae4a8ad74 100644 --- a/ethcore/src/engines/block_reward.rs +++ b/ethcore/src/engines/block_reward.rs @@ -164,7 +164,7 @@ mod test { use std::str::FromStr; use client::PrepareOpenBlock; use ethereum_types::{U256, Address}; - use crate::spec::bundle; + use crate::spec; use test_helpers::generate_dummy_client_with_spec; use engines::SystemOrCodeCallKind; @@ -172,9 +172,9 @@ mod test { #[test] fn block_reward_contract() { - let client = generate_dummy_client_with_spec(bundle::new_test_round_block_reward_contract); + let client = generate_dummy_client_with_spec(spec::new_test_round_block_reward_contract); - let machine = bundle::new_test_machine(); + let machine = spec::new_test_machine(); // the spec has a block reward contract defined at the given address let block_reward_contract = BlockRewardContract::new_from_address( diff --git a/ethcore/src/engines/clique/mod.rs b/ethcore/src/engines/clique/mod.rs index d19f2fc5faa..e9602f5181a 100644 --- a/ethcore/src/engines/clique/mod.rs +++ b/ethcore/src/engines/clique/mod.rs @@ -227,7 +227,7 @@ impl Clique { /// Note we need to `mock` the miner and it is introduced to test block verification to trigger new blocks /// to mainly test consensus edge cases pub fn with_test(epoch_length: u64, period: u64) -> Self { - use crate::spec::bundle; + use crate::spec; Self { epoch_length, @@ -236,7 +236,7 @@ impl Clique { block_state_by_hash: RwLock::new(LruCache::new(STATE_CACHE_NUM)), proposals: Default::default(), signer: Default::default(), - machine: bundle::new_test_machine(), + machine: spec::new_test_machine(), } } diff --git a/ethcore/src/engines/ethash.rs b/ethcore/src/engines/ethash.rs index 581c86900ed..1b75b9a4622 100644 --- a/ethcore/src/engines/ethash.rs +++ b/ethcore/src/engines/ethash.rs @@ -501,7 +501,7 @@ mod tests { }; use spec::Spec; use engines::Engine; - use crate::spec::bundle::{new_morden, new_mcip3_test, new_homestead_test_machine}; + use crate::spec::{new_morden, new_mcip3_test, new_homestead_test_machine}; use super::{Ethash, EthashParams, ecip1017_eras_block_reward}; use rlp; use tempdir::TempDir; diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index a619123ffd7..b6f3213c86b 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -107,14 +107,14 @@ mod tests { use std::sync::Arc; use ethereum_types::{H520, Address}; use test_helpers::get_temp_state_db; - use spec::bundle; + use crate::spec; use types::header::Header; use block::*; use engines::Seal; #[test] fn instant_can_seal() { - let spec = bundle::new_instant(); + let spec = spec::new_instant(); let engine = &*spec.engine; let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); let genesis_header = spec.genesis_header(); @@ -128,7 +128,7 @@ mod tests { #[test] fn instant_cant_verify() { - let engine = bundle::new_instant().engine; + let engine = spec::new_instant().engine; let mut header: Header = Header::default(); assert!(engine.verify_block_basic(&header).is_ok()); diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index 7de9906b804..7fd4c4981cc 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -144,7 +144,7 @@ mod tests { use ethereum_types::{H520, Address}; use bytes::ToPretty; use rlp::encode; - use spec::bundle; + use crate::spec; use types::header::Header; use accounts::AccountProvider; use miner::{self, MinerService}; @@ -158,7 +158,7 @@ mod tests { #[test] fn fetches_validators() { - let client = generate_dummy_client_with_spec(bundle::new_validator_contract); + let client = generate_dummy_client_with_spec(spec::new_validator_contract); let vc = Arc::new(ValidatorContract::new("0000000000000000000000000000000000000005".parse::
().unwrap())); vc.register_client(Arc::downgrade(&client) as _); let last_hash = client.best_block_header().hash(); @@ -171,7 +171,7 @@ mod tests { let _ = ::env_logger::try_init(); let tap = Arc::new(AccountProvider::transient_provider()); let v1 = tap.insert_account(keccak("1").into(), &"".into()).unwrap(); - let client = generate_dummy_client_with_spec(bundle::new_validator_contract); + let client = generate_dummy_client_with_spec(spec::new_validator_contract); client.engine().register_client(Arc::downgrade(&client) as _); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 51065dd077d..c833625936b 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -162,7 +162,7 @@ mod tests { use ethkey::Secret; use types::header::Header; use miner::{self, MinerService}; - use spec::bundle; + use crate::spec; use test_helpers::{generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data}; use types::ids::BlockId; use ethereum_types::Address; @@ -176,7 +176,7 @@ mod tests { let s0: Secret = keccak("0").into(); let v0 = tap.insert_account(s0.clone(), &"".into()).unwrap(); let v1 = tap.insert_account(keccak("1").into(), &"".into()).unwrap(); - let client = generate_dummy_client_with_spec(bundle::new_validator_multi); + let client = generate_dummy_client_with_spec(spec::new_validator_multi); client.engine().register_client(Arc::downgrade(&client) as _); // Make sure txs go through. @@ -207,7 +207,7 @@ mod tests { assert_eq!(client.chain_info().best_block_number, 3); // Check syncing. - let sync_client = generate_dummy_client_with_spec_and_data(bundle::new_validator_multi, 0, 0, &[]); + let sync_client = generate_dummy_client_with_spec_and_data(spec::new_validator_multi, 0, 0, &[]); sync_client.engine().register_client(Arc::downgrade(&sync_client) as _); for i in 1..4 { sync_client.import_block(Unverified::from_rlp(client.block(BlockId::Number(i)).unwrap().into_inner()).unwrap()).unwrap(); diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index ec27f31c9ad..2815c23900d 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -454,7 +454,7 @@ mod tests { use hash::keccak; use ethereum_types::Address; use types::ids::BlockId; - use spec::bundle; + use crate::spec; use accounts::AccountProvider; use types::transaction::{Transaction, Action}; use client::{ChainInfo, ImportBlock}; @@ -468,7 +468,7 @@ mod tests { #[test] fn fetches_validators() { - let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); + let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract); let vc = Arc::new(ValidatorSafeContract::new("0000000000000000000000000000000000000005".parse::
().unwrap())); vc.register_client(Arc::downgrade(&client) as _); let last_hash = client.best_block_header().hash(); @@ -483,8 +483,8 @@ mod tests { let s0: Secret = keccak("1").into(); let v0 = tap.insert_account(s0.clone(), &"".into()).unwrap(); let v1 = tap.insert_account(keccak("0").into(), &"".into()).unwrap(); - let chain_id = bundle::new_validator_safe_contract().chain_id(); - let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); + let chain_id = spec::new_validator_safe_contract().chain_id(); + let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract); client.engine().register_client(Arc::downgrade(&client) as _); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); let signer = Box::new((tap.clone(), v1, "".into())); @@ -538,7 +538,7 @@ mod tests { assert_eq!(client.chain_info().best_block_number, 3); // Check syncing. - let sync_client = generate_dummy_client_with_spec_and_data(bundle::new_validator_safe_contract, 0, 0, &[]); + let sync_client = generate_dummy_client_with_spec_and_data(spec::new_validator_safe_contract, 0, 0, &[]); sync_client.engine().register_client(Arc::downgrade(&sync_client) as _); for i in 1..4 { sync_client.import_block(Unverified::from_rlp(client.block(BlockId::Number(i)).unwrap().into_inner()).unwrap()).unwrap(); @@ -556,7 +556,7 @@ mod tests { engines::machine::AuxiliaryRequest, }; - let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); + let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract); let engine = client.engine().clone(); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); @@ -593,7 +593,7 @@ mod tests { use types::header::Header; use engines::{EpochChange, Proof}; - let client = generate_dummy_client_with_spec(bundle::new_validator_safe_contract); + let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract); let engine = client.engine().clone(); let mut new_header = Header::default(); diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 039cd4edd9e..70ea3a81b13 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -1228,16 +1228,16 @@ mod tests { errors::ExecutionError, transaction::{Action, Transaction}, }; - use crate::spec::bundle; + use crate::spec; fn make_frontier_machine(max_depth: usize) -> Machine { - let mut machine = bundle::new_frontier_test_machine(); + let mut machine = spec::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } fn make_byzantium_machine(max_depth: usize) -> Machine { - let mut machine = bundle::new_byzantium_test_machine(); + let mut machine = spec::new_byzantium_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } @@ -1591,7 +1591,7 @@ mod tests { let mut state = get_temp_state(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); let info = EnvInfo::default(); - let machine = bundle::new_byzantium_test_machine(); + let machine = spec::new_byzantium_test_machine(); let schedule = machine.schedule(info.number); let mut substate = Substate::new(); let mut tracer = ExecutiveTracer::default(); @@ -2123,7 +2123,7 @@ mod tests { params.code = Some(Arc::new(code)); params.value = ActionValue::Transfer(U256::zero()); let info = EnvInfo::default(); - let machine = bundle::new_byzantium_test_machine(); + let machine = spec::new_byzantium_test_machine(); let schedule = machine.schedule(info.number); let mut substate = Substate::new(); @@ -2159,7 +2159,7 @@ mod tests { state.init_code(&y2, "600060006000600061100162fffffff4".from_hex().unwrap()).unwrap(); let info = EnvInfo::default(); - let machine = bundle::new_constantinople_test_machine(); + let machine = spec::new_constantinople_test_machine(); let schedule = machine.schedule(info.number); assert_eq!(state.storage_at(&operating_address, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); @@ -2229,7 +2229,7 @@ mod tests { info.number = 100; // Network with wasm activated at block 10 - let machine = bundle::new_kovan_wasm_test_machine(); + let machine = spec::new_kovan_wasm_test_machine(); let mut output = [0u8; 20]; let FinalizationResult { gas_left: result, return_data, .. } = { diff --git a/ethcore/src/executive_state.rs b/ethcore/src/executive_state.rs index e9c9feaef47..046f9f65128 100644 --- a/ethcore/src/executive_state.rs +++ b/ethcore/src/executive_state.rs @@ -275,14 +275,14 @@ mod tests { use pod::PodState; use executive_state::ExecutiveState; use account_state::{Account, CleanupMode}; - use crate::spec::bundle; + use crate::spec; fn secret() -> Secret { keccak("").into() } fn make_frontier_machine(max_depth: usize) -> Machine { - let mut machine = bundle::new_frontier_test_machine(); + let mut machine = spec::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } @@ -472,7 +472,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let machine = bundle::new_test_machine(); + let machine = spec::new_test_machine(); let t = Transaction { nonce: 0.into(), @@ -513,7 +513,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let machine = bundle::new_test_machine(); + let machine = spec::new_test_machine(); let t = Transaction { nonce: 0.into(), @@ -555,7 +555,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); - let machine = bundle::new_test_machine(); + let machine = spec::new_test_machine(); let t = Transaction { nonce: 0.into(), @@ -614,7 +614,7 @@ mod tests { let mut info = EnvInfo::default(); info.gas_limit = 1_000_000.into(); info.number = 0x789b0; - let machine = bundle::new_test_machine(); + let machine = spec::new_test_machine(); let t = Transaction { nonce: 0.into(), diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 6942376d851..bfca8c0395d 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -442,7 +442,7 @@ mod tests { use super::*; use trace::{NoopTracer, NoopVMTracer}; use std::str::FromStr; - use crate::spec::bundle; + use crate::spec; fn get_test_origin() -> OriginInfo { OriginInfo { @@ -481,7 +481,7 @@ mod tests { impl TestSetup { fn new() -> Self { - let machine = bundle::new_test_machine(); + let machine = spec::new_test_machine(); let env_info = get_test_env_info(); let schedule = machine.schedule(env_info.number); TestSetup { diff --git a/ethcore/src/json_tests/difficulty.rs b/ethcore/src/json_tests/difficulty.rs index f73956fb4e9..399803bcb35 100644 --- a/ethcore/src/json_tests/difficulty.rs +++ b/ethcore/src/json_tests/difficulty.rs @@ -61,7 +61,7 @@ macro_rules! difficulty_json_test { fn do_json_test(json_data: &[u8], h: &mut H) -> Vec { let tempdir = TempDir::new("").unwrap(); - json_difficulty_test(json_data, crate::spec::bundle::$spec(&tempdir.path()), h) + json_difficulty_test(json_data, crate::spec::$spec(&tempdir.path()), h) } } @@ -74,7 +74,7 @@ macro_rules! difficulty_json_test_nopath { use json_tests::HookType; fn do_json_test(json_data: &[u8], h: &mut H) -> Vec { - json_difficulty_test(json_data, crate::spec::bundle::$spec(), h) + json_difficulty_test(json_data, crate::spec::$spec(), h) } } diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index f8d6379d010..c5f3afe25f0 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -37,7 +37,7 @@ use rlp::RlpStream; use hash::keccak; use machine::Machine; use ethereum_types::BigEndianHash; -use crate::spec::bundle; +use crate::spec; use super::HookType; @@ -272,7 +272,7 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8] state.populate_from(From::from(vm.pre_state.clone())); let info: EnvInfo = From::from(vm.env); let machine = { - let mut machine = bundle::new_frontier_test_machine(); + let mut machine = spec::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = 1)); machine }; diff --git a/ethcore/src/machine.rs b/ethcore/src/machine.rs index f3cb660b4df..18cf982d554 100644 --- a/ethcore/src/machine.rs +++ b/ethcore/src/machine.rs @@ -402,7 +402,7 @@ fn round_block_gas_limit(gas_limit: U256, lower_limit: U256, upper_limit: U256) mod tests { use super::*; use std::str::FromStr; - use crate::spec::bundle; + use crate::spec; fn get_default_ethash_extensions() -> EthashExtensions { EthashExtensions { @@ -417,7 +417,7 @@ mod tests { fn should_disallow_unsigned_transactions() { let rlp = "ea80843b9aca0083015f90948921ebb5f79e9e3920abe571004d0b1d5119c154865af3107a400080038080"; let transaction: UnverifiedTransaction = ::rlp::decode(&::rustc_hex::FromHex::from_hex(rlp).unwrap()).unwrap(); - let spec = bundle::new_ropsten_test(); + let spec = spec::new_ropsten_test(); let ethparams = get_default_ethash_extensions(); let machine = Machine::with_ethash_extensions( @@ -436,7 +436,7 @@ mod tests { fn ethash_gas_limit_is_multiple_of_determinant() { use ethereum_types::U256; - let spec = bundle::new_homestead_test(); + let spec = spec::new_homestead_test(); let ethparams = get_default_ethash_extensions(); let machine = Machine::with_ethash_extensions( diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 665b20e9286..78f874415e9 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -1488,13 +1488,13 @@ mod tests { use miner::{MinerService, PendingOrdering}; use test_helpers::{generate_dummy_client, generate_dummy_client_with_spec}; use types::transaction::{Transaction}; - use crate::spec::bundle; + use crate::spec; #[test] fn should_prepare_block_to_seal() { // given let client = TestBlockChainClient::default(); - let miner = Miner::new_for_tests(&bundle::new_test(), None); + let miner = Miner::new_for_tests(&spec::new_test(), None); // when let sealing_work = miner.work_package(&client); @@ -1505,7 +1505,7 @@ mod tests { fn should_still_work_after_a_couple_of_blocks() { // given let client = TestBlockChainClient::default(); - let miner = Miner::new_for_tests(&bundle::new_test(), None); + let miner = Miner::new_for_tests(&spec::new_test(), None); let res = miner.work_package(&client); let hash = res.unwrap().0; @@ -1549,7 +1549,7 @@ mod tests { }, }, GasPricer::new_fixed(0u64.into()), - &bundle::new_test(), + &spec::new_test(), ::std::collections::HashSet::new(), // local accounts ) } @@ -1672,7 +1672,7 @@ mod tests { ..miner().options }, GasPricer::new_fixed(0u64.into()), - &bundle::new_test(), + &spec::new_test(), local_accounts, ); let transaction = transaction(); @@ -1715,7 +1715,7 @@ mod tests { ..miner().options }, GasPricer::new_fixed(0u64.into()), - &bundle::new_test(), + &spec::new_test(), HashSet::from_iter(vec![transaction.sender()].into_iter()), ); let best_block = 0; @@ -1747,7 +1747,7 @@ mod tests { #[test] fn internal_seals_without_work() { let _ = env_logger::try_init(); - let spec = bundle::new_instant(); + let spec = spec::new_instant(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1776,7 +1776,7 @@ mod tests { #[test] fn should_not_fail_setting_engine_signer_without_account_provider() { - let spec = bundle::new_test_round; + let spec = spec::new_test_round; let tap = Arc::new(AccountProvider::transient_provider()); let addr = tap.insert_account(keccak("1").into(), &"".into()).unwrap(); let client = generate_dummy_client_with_spec(spec); @@ -1792,7 +1792,7 @@ mod tests { #[test] fn should_mine_if_internal_sealing_is_enabled() { - let spec = bundle::new_instant(); + let spec = spec::new_instant(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1803,7 +1803,7 @@ mod tests { #[test] fn should_not_mine_if_internal_sealing_is_disabled() { - let spec = bundle::new_test_round(); + let spec = spec::new_test_round(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1814,7 +1814,7 @@ mod tests { #[test] fn should_not_mine_if_no_fetch_work_request() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let miner = Miner::new_for_tests(&spec, None); let client = generate_dummy_client(2); @@ -1832,7 +1832,7 @@ mod tests { fn notify(&self, _pow_hash: H256, _difficulty: U256, _number: u64) { } } - let spec = bundle::new_test(); + let spec = spec::new_test(); let miner = Miner::new_for_tests(&spec, None); miner.add_work_listener(Box::new(DummyNotifyWork)); @@ -1845,7 +1845,7 @@ mod tests { #[test] fn should_set_new_minimum_gas_price() { // Creates a new GasPricer::Fixed behind the scenes - let miner = Miner::new_for_tests(&bundle::new_test(), None); + let miner = Miner::new_for_tests(&spec::new_test(), None); let expected_minimum_gas_price: U256 = 0x1337.into(); miner.set_minimal_gas_price(expected_minimum_gas_price).unwrap(); @@ -1883,7 +1883,7 @@ mod tests { #[cfg(feature = "price-info")] fn should_fail_to_set_new_minimum_gas_price() { // We get a fixed gas pricer by default, need to change that - let miner = Miner::new_for_tests(&bundle::new_test(), None); + let miner = Miner::new_for_tests(&spec::new_test(), None); let calibrated_gas_pricer = dynamic_gas_pricer(); *miner.gas_pricer.lock() = calibrated_gas_pricer; diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index 6b2e3a4869e..44ae22e8181 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -899,7 +899,7 @@ impl Drop for Service { mod tests { use client::ClientIoMessage; use io::{IoService}; - use spec::bundle; + use crate::spec; use journaldb::Algorithm; use snapshot::{ManifestData, RestorationStatus, SnapshotService}; use super::*; @@ -909,9 +909,9 @@ mod tests { #[test] fn sends_async_messages() { let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(bundle::new_null, 400, 5, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(spec::new_null, 400, 5, &gas_prices); let service = IoService::::start().unwrap(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let tempdir = TempDir::new("").unwrap(); let dir = tempdir.path().join("snapshot"); @@ -952,7 +952,7 @@ mod tests { use ethereum_types::H256; use kvdb_rocksdb::DatabaseConfig; - let spec = bundle::new_test(); + let spec = spec::new_test(); let tempdir = TempDir::new("").unwrap(); let state_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect(); diff --git a/ethcore/src/snapshot/tests/proof_of_work.rs b/ethcore/src/snapshot/tests/proof_of_work.rs index 92de2b85cf1..eee12a0c271 100644 --- a/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/ethcore/src/snapshot/tests/proof_of_work.rs @@ -29,7 +29,7 @@ use parking_lot::Mutex; use snappy; use kvdb::DBTransaction; use test_helpers; -use crate::spec::bundle; +use crate::spec; const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { blocks: 30000, max_restore_blocks: 30000 }; @@ -39,7 +39,7 @@ fn chunk_and_restore(amount: u64) { let generator = BlockGenerator::new(vec![rest]); let genesis = genesis.last(); - let engine = bundle::new_test().engine; + let engine = spec::new_test().engine; let tempdir = TempDir::new("").unwrap(); let snapshot_path = tempdir.path().join("SNAP"); @@ -129,7 +129,7 @@ fn checks_flag() { let chunk = stream.out(); let db = test_helpers::new_db(); - let engine = bundle::new_test().engine; + let engine = spec::new_test().engine; let chain = BlockChain::new(Default::default(), genesis.last().encoded().raw(), db.clone()); let manifest = ::snapshot::ManifestData { diff --git a/ethcore/src/snapshot/tests/service.rs b/ethcore/src/snapshot/tests/service.rs index 4e1d824c484..9e4f8631696 100644 --- a/ethcore/src/snapshot/tests/service.rs +++ b/ethcore/src/snapshot/tests/service.rs @@ -27,7 +27,7 @@ use types::ids::BlockId; use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; use snapshot::service::{Service, ServiceParams}; use snapshot::{chunk_state, chunk_secondary, ManifestData, Progress, SnapshotService, RestorationStatus}; -use spec::bundle; +use crate::spec; use test_helpers::{new_db, new_temp_db, generate_dummy_client_with_spec_and_data, restoration_db_handler}; use parking_lot::Mutex; @@ -43,7 +43,7 @@ fn restored_is_equivalent() { const TX_PER: usize = 5; let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(bundle::new_null, NUM_BLOCKS, TX_PER, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(spec::new_null, NUM_BLOCKS, TX_PER, &gas_prices); let tempdir = TempDir::new("").unwrap(); let client_db = tempdir.path().join("client_db"); @@ -53,7 +53,7 @@ fn restored_is_equivalent() { let restoration = restoration_db_handler(db_config); let blockchain_db = restoration.open(&client_db).unwrap(); - let spec = bundle::new_null(); + let spec = spec::new_null(); let client2 = Client::new( Default::default(), &spec, @@ -107,9 +107,9 @@ fn restored_is_equivalent() { #[test] fn guards_delete_folders() { let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(bundle::new_null, 400, 5, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(spec::new_null, 400, 5, &gas_prices); - let spec = bundle::new_null(); + let spec = spec::new_null(); let tempdir = TempDir::new("").unwrap(); let service_params = ServiceParams { engine: spec.engine.clone(), @@ -165,7 +165,7 @@ fn keep_ancient_blocks() { // Generate blocks let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let spec_f = bundle::new_null; + let spec_f = spec::new_null; let spec = spec_f(); let client = generate_dummy_client_with_spec_and_data(spec_f, NUM_BLOCKS as u32, 5, &gas_prices); @@ -276,9 +276,9 @@ fn recover_aborted_recovery() { const NUM_BLOCKS: u32 = 400; let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; - let client = generate_dummy_client_with_spec_and_data(bundle::new_null, NUM_BLOCKS, 5, &gas_prices); + let client = generate_dummy_client_with_spec_and_data(spec::new_null, NUM_BLOCKS, 5, &gas_prices); - let spec = bundle::new_null(); + let spec = spec::new_null(); let tempdir = TempDir::new("").unwrap(); let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let client_db = new_db(); diff --git a/ethcore/src/spec/bundle.rs b/ethcore/src/spec/chain.rs similarity index 100% rename from ethcore/src/spec/bundle.rs rename to ethcore/src/spec/chain.rs diff --git a/ethcore/src/spec/mod.rs b/ethcore/src/spec/mod.rs index 004c3e86ca3..5ac0b8a9b48 100644 --- a/ethcore/src/spec/mod.rs +++ b/ethcore/src/spec/mod.rs @@ -16,10 +16,11 @@ //! Blockchain params. -pub mod bundle; +mod chain; mod genesis; mod seal; mod spec; +pub use self::chain::*; pub use self::genesis::Genesis; pub use self::spec::{Spec, SpecHardcodedSync, SpecParams, OptimizeFor}; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 9ae7800df9d..7040c6fb17d 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -560,7 +560,7 @@ mod tests { use types::view; use types::views::BlockView; use std::str::FromStr; - use crate::spec::bundle; + use crate::spec; #[test] fn test_load_empty() { @@ -570,7 +570,7 @@ mod tests { #[test] fn test_chain() { - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); assert_eq!( test_spec.state_root(), @@ -586,7 +586,7 @@ mod tests { #[test] fn genesis_constructor() { let _ = ::env_logger::try_init(); - let spec = bundle::new_test_constructor(); + let spec = spec::new_test_constructor(); let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()) .unwrap(); let state = State::from_existing( diff --git a/ethcore/src/test_helpers.rs b/ethcore/src/test_helpers.rs index c708ae36d3d..2349b781cc6 100644 --- a/ethcore/src/test_helpers.rs +++ b/ethcore/src/test_helpers.rs @@ -43,7 +43,7 @@ use block::{OpenBlock, Drain}; use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock}; use trie_vm_factories::Factories; use miner::Miner; -use spec::{bundle, Spec}; +use spec::{Spec, self}; use account_state::*; use state_db::StateDB; use verification::queue::kind::blocks::Unverified; @@ -100,12 +100,12 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa /// Generates dummy client (not test client) with corresponding amount of blocks pub fn generate_dummy_client(block_number: u32) -> Arc { - generate_dummy_client_with_spec_and_data(bundle::new_test, block_number, 0, &[]) + generate_dummy_client_with_spec_and_data(spec::new_test, block_number, 0, &[]) } /// Generates dummy client (not test client) with corresponding amount of blocks and txs per every block pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc { - generate_dummy_client_with_spec_and_data(bundle::new_null, block_number, txs_per_block, tx_gas_prices) + generate_dummy_client_with_spec_and_data(spec::new_null, block_number, txs_per_block, tx_gas_prices) } /// Generates dummy client (not test client) with corresponding spec and accounts @@ -188,7 +188,7 @@ pub fn generate_dummy_client_with_spec_and_data(test_spec: F, block_number: u /// Adds blocks to the client pub fn push_blocks_to_client(client: &Arc, timestamp_salt: u64, starting_number: usize, block_number: usize) { - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let state_root = test_spec.genesis_header().state_root().clone(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); @@ -218,7 +218,7 @@ pub fn push_blocks_to_client(client: &Arc, timestamp_salt: u64, starting /// Adds one block with transactions pub fn push_block_with_transactions(client: &Arc, transactions: &[SignedTransaction]) { - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let test_engine = &*test_spec.engine; let block_number = client.chain_info().best_block_number as u64 + 1; @@ -240,7 +240,7 @@ pub fn push_block_with_transactions(client: &Arc, transactions: &[Signed /// Creates dummy client (not test client) with corresponding blocks pub fn get_test_client_with_blocks(blocks: Vec) -> Arc { - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let client_db = new_db(); let client = Client::new( @@ -432,13 +432,13 @@ pub fn get_temp_state_db() -> StateDB { /// Returns sequence of hashes of the dummy blocks pub fn get_good_dummy_block_seq(count: usize) -> Vec { - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); get_good_dummy_block_fork_seq(1, count, &test_spec.genesis_header().hash()) } /// Returns sequence of hashes of the dummy blocks beginning from corresponding parent pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_hash: &H256) -> Vec { - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); let mut rolling_timestamp = start_number as u64 * 10; let mut parent = *parent_hash; @@ -463,7 +463,7 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h /// Returns hash and header of the correct dummy block pub fn get_good_dummy_block_hash() -> (H256, Bytes) { let mut block_header = Header::new(); - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); block_header.set_gas_limit(genesis_gas); block_header.set_difficulty(U256::from(0x20000)); @@ -484,7 +484,7 @@ pub fn get_good_dummy_block() -> Bytes { /// Returns hash of the dummy block with incorrect state root pub fn get_bad_state_dummy_block() -> Bytes { let mut block_header = Header::new(); - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let genesis_gas = test_spec.genesis_header().gas_limit().clone(); block_header.set_gas_limit(genesis_gas); diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 9e41d1ac7dd..b7d280a48eb 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -29,7 +29,7 @@ use types::views::BlockView; use client::{BlockChainClient, BlockChainReset, Client, ClientConfig, BlockId, ChainInfo, PrepareOpenBlock, ImportSealedBlock, ImportBlock}; use client::BlockInfo; -use crate::spec::bundle; +use crate::spec; use executive::{Executive, TransactOptions}; use miner::{Miner, PendingOrdering, MinerService}; use account_state::{State, CleanupMode, backend}; @@ -43,7 +43,7 @@ use verification::queue::kind::blocks::Unverified; #[test] fn imports_from_empty() { let db = test_helpers::new_db(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let client = Client::new( ClientConfig::default(), @@ -60,7 +60,7 @@ fn imports_from_empty() { fn should_return_registrar() { let db = test_helpers::new_db(); let tempdir = TempDir::new("").unwrap(); - let spec = bundle::new_morden(&tempdir.path().to_owned()); + let spec = spec::new_morden(&tempdir.path().to_owned()); let client = Client::new( ClientConfig::default(), @@ -76,7 +76,7 @@ fn should_return_registrar() { #[test] fn returns_state_root_basic() { let client = generate_dummy_client(6); - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); let genesis_header = test_spec.genesis_header(); assert!(client.state_data(genesis_header.state_root()).is_some()); @@ -85,7 +85,7 @@ fn returns_state_root_basic() { #[test] fn imports_good_block() { let db = test_helpers::new_db(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let client = Client::new( ClientConfig::default(), @@ -108,7 +108,7 @@ fn imports_good_block() { #[test] fn query_none_block() { let db = test_helpers::new_db(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let client = Client::new( ClientConfig::default(), @@ -256,7 +256,7 @@ fn can_mine() { #[test] fn change_history_size() { let db = test_helpers::new_db(); - let test_spec = bundle::new_null(); + let test_spec = spec::new_null(); let mut config = ClientConfig::default(); config.history = 2; @@ -328,7 +328,7 @@ fn transaction_proof() { let client = generate_dummy_client(0); let address = Address::random(); - let test_spec = bundle::new_test(); + let test_spec = spec::new_test(); for _ in 0..20 { let mut b = client.prepare_open_block(Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); b.block_mut().state_mut().add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap(); diff --git a/ethcore/src/tests/evm.rs b/ethcore/src/tests/evm.rs index a0d4df76c6e..7a1a40d4dad 100644 --- a/ethcore/src/tests/evm.rs +++ b/ethcore/src/tests/evm.rs @@ -29,7 +29,7 @@ use types::transaction::SYSTEM_ADDRESS; use rustc_hex::FromHex; use ethereum_types::{H256, Address}; -use crate::spec::bundle; +use crate::spec; evm_test!{test_blockhash_eip210: test_blockhash_eip210_int} fn test_blockhash_eip210(factory: Factory) { @@ -39,7 +39,7 @@ fn test_blockhash_eip210(factory: Factory) { let test_blockhash_contract = "73fffffffffffffffffffffffffffffffffffffffe33141561007a57600143036020526000356101006020510755600061010060205107141561005057600035610100610100602051050761010001555b6000620100006020510714156100755760003561010062010000602051050761020001555b61014a565b4360003512151561009057600060405260206040f35b610100600035430312156100b357610100600035075460605260206060f3610149565b62010000600035430312156100d157600061010060003507146100d4565b60005b156100f6576101006101006000350507610100015460805260206080f3610148565b630100000060003543031215610116576000620100006000350714610119565b60005b1561013c57610100620100006000350507610200015460a052602060a0f3610147565b600060c052602060c0f35b5b5b5b5b"; let blockhash_contract_code = Arc::new(test_blockhash_contract.from_hex().unwrap()); let blockhash_contract_code_hash = keccak(blockhash_contract_code.as_ref()); - let machine = bundle::new_eip210_test_machine(); + let machine = spec::new_eip210_test_machine(); let mut env_info = EnvInfo::default(); // populate state with 256 last hashes diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index 2461ae43216..0a65c6c7a8c 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -21,7 +21,7 @@ use hash::keccak; use block::*; use ethereum_types::{U256, Address}; use io::*; -use spec::bundle; +use crate::spec; use client::*; use test_helpers::get_temp_state_db; use client::{BlockChainClient, Client, ClientConfig}; @@ -40,7 +40,7 @@ use types::views::BlockView; #[test] fn can_trace_block_and_uncle_reward() { let db = test_helpers::new_db(); - let spec = bundle::new_test_with_reward(); + let spec = spec::new_test_with_reward(); let engine = &*spec.engine; // Create client diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 21bee8aa50f..9b736807d09 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -734,7 +734,6 @@ impl Drop for VerificationQueue { #[cfg(test)] mod tests { use io::*; - use spec::bundle; use super::{BlockQueue, Config, State}; use super::kind::blocks::Unverified; use test_helpers::{get_good_dummy_block_seq, get_good_dummy_block}; @@ -744,11 +743,12 @@ mod tests { views::BlockView, errors::{EthcoreError, ImportError}, }; + use crate::spec; // create a test block queue. // auto_scaling enables verifier adjustment. fn get_test_queue(auto_scale: bool) -> BlockQueue { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let mut config = Config::default(); @@ -770,7 +770,7 @@ mod tests { #[test] fn can_be_created() { // TODO better test - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let _ = BlockQueue::new(Config::default(), engine, IoChannel::disconnected(), true); } @@ -848,7 +848,7 @@ mod tests { #[test] fn test_mem_limit() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let mut config = Config::default(); config.max_mem_use = super::MIN_MEM_LIMIT; // empty queue uses about 15000 @@ -899,7 +899,7 @@ mod tests { #[test] fn worker_threads_honor_specified_number_without_scaling() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let config = get_test_config(1, false); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); @@ -909,7 +909,7 @@ mod tests { #[test] fn worker_threads_specified_to_zero_should_set_to_one() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let config = get_test_config(0, false); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); @@ -919,7 +919,7 @@ mod tests { #[test] fn worker_threads_should_only_accept_max_number_cpus() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let config = get_test_config(10_000, false); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); @@ -933,7 +933,7 @@ mod tests { let num_cpus = ::num_cpus::get(); // only run the test with at least 2 CPUs if num_cpus > 1 { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = spec.engine; let config = get_test_config(num_cpus - 1, true); let queue = BlockQueue::new(config, engine, IoChannel::disconnected(), true); diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 89930cd7530..949326a2de7 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -372,7 +372,7 @@ mod tests { use hash::keccak; use engines::Engine; use ethkey::{Random, Generator}; - use spec::bundle; + use crate::spec; use test_helpers::{create_test_block_with_data, create_test_block}; use types::{ encoded, @@ -546,7 +546,7 @@ mod tests { #[test] fn test_verify_block_basic_with_invalid_transactions() { - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = &*spec.engine; let block = { @@ -571,7 +571,7 @@ mod tests { // Test against morden let mut good = Header::new(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let engine = &*spec.engine; let min_gas_limit = engine.params().min_gas_limit; diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index 556ff35f8a9..e0004fb5753 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -636,7 +636,7 @@ fn all_expected(values: &[A], expected_values: &[B], is_expected: F) -> mod tests { use super::*; use ethcore::client::TestBlockChainClient; - use ethcore::spec::bundle; + use ethcore::spec; use ethkey::{Generator,Random}; use hash::keccak; use parking_lot::RwLock; @@ -681,7 +681,7 @@ mod tests { fn import_headers_in_chain_head_state() { ::env_logger::try_init().ok(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_hash = spec.genesis_header().hash(); let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0); @@ -930,7 +930,7 @@ mod tests { fn reset_after_multiple_sets_of_useless_headers() { ::env_logger::try_init().ok(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_hash = spec.genesis_header().hash(); let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0); @@ -970,7 +970,7 @@ mod tests { fn dont_reset_after_multiple_sets_of_useless_headers_for_chain_head() { ::env_logger::try_init().ok(); - let spec = bundle::new_test(); + let spec = spec::new_test(); let genesis_hash = spec.genesis_header().hash(); let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0); diff --git a/ethcore/sync/src/light_sync/tests/test_net.rs b/ethcore/sync/src/light_sync/tests/test_net.rs index da8d26a96a5..f33ad212375 100644 --- a/ethcore/sync/src/light_sync/tests/test_net.rs +++ b/ethcore/sync/src/light_sync/tests/test_net.rs @@ -23,7 +23,7 @@ use light_sync::*; use tests::helpers::{TestNet, Peer as PeerLike, TestPacket}; use ethcore::client::TestBlockChainClient; -use ethcore::spec::bundle; +use ethcore::spec; use io::IoChannel; use kvdb_memorydb; use light::client::fetch::{self, Unavailable}; @@ -229,7 +229,7 @@ impl TestNet { config, Arc::new(db), None, - &bundle::new_test(), + &spec::new_test(), fetch::unavailable(), // TODO: allow fetch from full nodes. IoChannel::disconnected(), cache diff --git a/ethcore/sync/src/tests/chain.rs b/ethcore/sync/src/tests/chain.rs index b0c994e8495..3c67f94463c 100644 --- a/ethcore/sync/src/tests/chain.rs +++ b/ethcore/sync/src/tests/chain.rs @@ -19,7 +19,7 @@ use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockId, EachBlock use chain::{SyncState}; use super::helpers::*; use {SyncConfig, WarpSync}; -use ethcore::spec::bundle; +use ethcore::spec; #[test] fn two_peers() { @@ -102,7 +102,7 @@ fn forked_with_misbehaving_peer() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); - let mut alt_spec = bundle::new_test(); + let mut alt_spec = spec::new_test(); alt_spec.extra_data = b"fork".to_vec(); // peer 0 is on a totally different chain with higher total difficulty net.peer_mut(0).chain = Arc::new(TestBlockChainClient::new_with_spec(alt_spec)); diff --git a/ethcore/sync/src/tests/consensus.rs b/ethcore/sync/src/tests/consensus.rs index 14b99d0ea61..8f17ecb156b 100644 --- a/ethcore/sync/src/tests/consensus.rs +++ b/ethcore/sync/src/tests/consensus.rs @@ -20,7 +20,7 @@ use ethereum_types::{U256, Address}; use io::{IoHandler, IoChannel}; use ethcore::client::{ChainInfo, ClientIoMessage}; use ethcore::engines; -use ethcore::spec::bundle; +use ethcore::spec; use ethcore::miner::{self, MinerService}; use ethkey::{KeyPair, Secret}; use types::transaction::{Action, PendingTransaction, Transaction}; @@ -44,8 +44,8 @@ fn authority_round() { let s0 = KeyPair::from_secret_slice(keccak("1").as_bytes()).unwrap(); let s1 = KeyPair::from_secret_slice(keccak("0").as_bytes()).unwrap(); - let chain_id = bundle::new_test_round().chain_id(); - let mut net = TestNet::with_spec(2, SyncConfig::default(), bundle::new_test_round); + let chain_id = spec::new_test_round().chain_id(); + let mut net = TestNet::with_spec(2, SyncConfig::default(), spec::new_test_round); let io_handler0: Arc> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone())); let io_handler1: Arc> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone())); // Push transaction to both clients. Only one of them gets lucky to produce a block. diff --git a/ethcore/sync/src/tests/helpers.rs b/ethcore/sync/src/tests/helpers.rs index 3f8f766b16c..135161a381a 100644 --- a/ethcore/sync/src/tests/helpers.rs +++ b/ethcore/sync/src/tests/helpers.rs @@ -25,7 +25,7 @@ use tests::snapshot::*; use ethcore::client::{TestBlockChainClient, BlockChainClient, Client as EthcoreClient, ClientConfig, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage}; use ethcore::snapshot::SnapshotService; -use ethcore::spec::{bundle, Spec}; +use ethcore::spec::{self, Spec}; use ethcore::miner::Miner; use ethcore::test_helpers; use sync_io::SyncIo; @@ -351,7 +351,7 @@ impl TestNet> { sync: RwLock::new(sync), snapshot_service: ss, chain: Arc::new(chain), - miner: Arc::new(Miner::new_for_tests(&bundle::new_test(), None)), + miner: Arc::new(Miner::new_for_tests(&spec::new_test(), None)), queue: RwLock::new(VecDeque::new()), private_tx_handler, io_queue: RwLock::new(VecDeque::new()), diff --git a/evmbin/src/info.rs b/evmbin/src/info.rs index c2557e22b08..605f54176e1 100644 --- a/evmbin/src/info.rs +++ b/evmbin/src/info.rs @@ -211,7 +211,7 @@ pub mod tests { use super::*; use tempdir::TempDir; use ethereum_types::Address; - use ethcore::spec::{bundle, Spec}; + use ethcore::spec::{self, Spec}; pub fn run_test( informant: I, @@ -229,7 +229,7 @@ pub mod tests { params.gas = gas.into(); let tempdir = TempDir::new("").unwrap(); - let spec = bundle::new_foundation(&tempdir.path()); + let spec = spec::new_foundation(&tempdir.path()); let result = run_action(&spec, params, informant, TrieSpec::Secure); match result { Ok(Success { traces, .. }) => { diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index 47b7153e7fe..c9be4d9a283 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -339,7 +339,7 @@ impl Args { spec::Spec::load(&::std::env::temp_dir(), file)? }, None => { - spec::bundle::new_foundation(&::std::env::temp_dir()) + spec::new_foundation(&::std::env::temp_dir()) }, }) } diff --git a/parity/params.rs b/parity/params.rs index 2b0cf58dce2..bee919290fe 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -19,7 +19,7 @@ use std::time::Duration; use std::{str, fs, fmt}; use ethcore::client::Mode; -use ethcore::spec::{Spec, SpecParams, bundle}; +use ethcore::spec::{Spec, SpecParams, self}; use ethereum_types::{U256, Address}; use parity_runtime::Executor; use hash_fetch::fetch::Client as FetchClient; @@ -114,23 +114,23 @@ impl SpecType { pub fn spec<'a, T: Into>>(&self, params: T) -> Result { let params = params.into(); match *self { - SpecType::Foundation => Ok(bundle::new_foundation(params)), - SpecType::Classic => Ok(bundle::new_classic(params)), - SpecType::Poanet => Ok(bundle::new_poanet(params)), - SpecType::Tobalaba => Ok(bundle::new_tobalaba(params)), - SpecType::Expanse => Ok(bundle::new_expanse(params)), - SpecType::Musicoin => Ok(bundle::new_musicoin(params)), - SpecType::Ellaism => Ok(bundle::new_ellaism(params)), - SpecType::Mix => Ok(bundle::new_mix(params)), - SpecType::Callisto => Ok(bundle::new_callisto(params)), - SpecType::Morden => Ok(bundle::new_morden(params)), - SpecType::Ropsten => Ok(bundle::new_ropsten(params)), - SpecType::Kovan => Ok(bundle::new_kovan(params)), - SpecType::Rinkeby => Ok(bundle::new_rinkeby(params)), - SpecType::Goerli => Ok(bundle::new_goerli(params)), - SpecType::Kotti => Ok(bundle::new_kotti(params)), - SpecType::Sokol => Ok(bundle::new_sokol(params)), - SpecType::Dev => Ok(bundle::new_instant()), + SpecType::Foundation => Ok(spec::new_foundation(params)), + SpecType::Classic => Ok(spec::new_classic(params)), + SpecType::Poanet => Ok(spec::new_poanet(params)), + SpecType::Tobalaba => Ok(spec::new_tobalaba(params)), + SpecType::Expanse => Ok(spec::new_expanse(params)), + SpecType::Musicoin => Ok(spec::new_musicoin(params)), + SpecType::Ellaism => Ok(spec::new_ellaism(params)), + SpecType::Mix => Ok(spec::new_mix(params)), + SpecType::Callisto => Ok(spec::new_callisto(params)), + SpecType::Morden => Ok(spec::new_morden(params)), + SpecType::Ropsten => Ok(spec::new_ropsten(params)), + SpecType::Kovan => Ok(spec::new_kovan(params)), + SpecType::Rinkeby => Ok(spec::new_rinkeby(params)), + SpecType::Goerli => Ok(spec::new_goerli(params)), + SpecType::Kotti => Ok(spec::new_kotti(params)), + SpecType::Sokol => Ok(spec::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) diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 7a8350ddf3e..c1981ce0101 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use accounts::AccountProvider; use ethcore::client::{BlockChainClient, Client, ClientConfig, ChainInfo, ImportBlock}; use ethcore::miner::Miner; -use ethcore::spec::{Genesis, Spec, bundle}; +use ethcore::spec::{Genesis, Spec, self}; use ethcore::test_helpers; use ethcore::verification::VerifierType; use ethcore::verification::queue::kind::blocks::Unverified; @@ -63,7 +63,7 @@ fn snapshot_service() -> Arc { fn make_spec(chain: &BlockChain) -> Spec { let genesis = Genesis::from(chain.genesis()); - let mut spec = bundle::new_frontier_test(); + let mut spec = spec::new_frontier_test(); let state = chain.pre_state.clone().into(); spec.set_genesis_state(state).expect("unable to set genesis state"); spec.overwrite_genesis_params(genesis); From f1898f09cc6211f31e9c21f552ecf6022011cd75 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 7 Aug 2019 13:53:53 +0200 Subject: [PATCH 4/5] removed unused derives --- ethcore/src/spec/spec.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 7040c6fb17d..78f049f561f 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -62,7 +62,6 @@ fn fmt_err(f: F) -> String { /// Runtime parameters for the spec that are related to how the software should run the chain, /// rather than integral properties of the chain itself. -#[derive(Debug, Clone, Copy)] pub struct SpecParams<'a> { /// The path to the folder used to cache nodes. This is typically /tmp/ on Unix-like systems pub cache_dir: &'a Path, @@ -186,7 +185,6 @@ fn run_constructors( /// Parameters for a block chain; includes both those intrinsic to the design of the /// chain and those to be interpreted by the active chain engine. -#[derive(Clone)] pub struct Spec { /// User friendly spec name. pub name: String, @@ -227,7 +225,6 @@ pub struct Spec { } /// Part of `Spec`. Describes the hardcoded synchronization parameters. -#[derive(Debug, Clone)] pub struct SpecHardcodedSync { /// Header of the block to jump to for hardcoded sync, and total difficulty. pub header: encoded::Header, From 693b0cbecdf04de52169a8cf4df6a1f0b7d8f8e1 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 7 Aug 2019 13:58:25 +0200 Subject: [PATCH 5/5] updated spec/chain.rs description --- ethcore/src/spec/chain.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethcore/src/spec/chain.rs b/ethcore/src/spec/chain.rs index 3207bc88b16..7d742d47354 100644 --- a/ethcore/src/spec/chain.rs +++ b/ethcore/src/spec/chain.rs @@ -16,8 +16,7 @@ //! Ethereum protocol module. //! -//! Contains all Ethereum network specific stuff, such as denominations and -//! consensus specifications. +//! Loads all protocols supported by parity-ethereum client. macro_rules! bundle_release_spec { ($($path: expr => $name: ident), *) => {