unify loading spec && further spec cleanups (#10948)

* bundle_* macros for spec

* fixed failing tests

* renamed bundle.rs to chain.rs

* removed unused derives

* updated spec/chain.rs description
This commit is contained in:
Marek Kotewicz 2019-08-07 16:52:48 +02:00 committed by David
parent c689495826
commit 45978bc2bd
45 changed files with 378 additions and 591 deletions

View File

@ -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;
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 = spec::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 = 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 = Spec::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 = Spec::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 = Spec::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 = Spec::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 = Spec::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 = Spec::new_test();
let spec = spec::new_test();
let genesis_header = spec.genesis_header();
let db = make_db();

View File

@ -113,7 +113,7 @@ impl<T: ChainDataFetcher> IoHandler<ClientIoMessage> for ImportBlocks<T> {
#[cfg(test)]
mod tests {
use super::Service;
use ethcore::spec::Spec;
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 = Spec::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();

View File

@ -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;
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(&spec::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(&spec::new_test(), None));
let private_keys = Arc::new(StoringKeyProvider::default());
let pm = Arc::new(Provider::new(
client.clone(),

View File

@ -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;
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 = spec::new_test();
let service = ClientService::start(
ClientConfig::default(),
&spec,

View File

@ -563,6 +563,7 @@ mod tests {
errors::EthcoreError as Error,
};
use hash_db::EMPTY_PREFIX;
use crate::spec;
/// 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 = 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,8 +645,7 @@ mod tests {
#[test]
fn enact_block() {
use spec::*;
let spec = Spec::new_test();
let spec = spec::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 = spec::new_test();
let engine = &*spec.engine;
let genesis_header = spec.genesis_header();

View File

@ -29,13 +29,13 @@ 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 executive_state::ExecutiveState;
/// EVM test Error.
@ -70,9 +70,6 @@ impl fmt::Display for EvmTestError {
}
}
use ethereum;
use ethjson::spec::ForkSpec;
/// Simplified, single-block EVM test client.
pub struct EvmTestClient<'a> {
state: State<state_db::StateDB>,
@ -101,14 +98,14 @@ impl<'a> EvmTestClient<'a> {
/// Converts a json spec definition into spec.
pub fn fork_spec_from_json(spec: &ForkSpec) -> Option<spec::Spec> {
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(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,
}
}

View File

@ -66,7 +66,7 @@ use engines::Engine;
use executive::Executed;
use journaldb;
use miner::{self, Miner, MinerService};
use spec::Spec;
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 = Spec::new_test();
let spec = spec::new_test();
TestBlockChainClient::new_with_spec_and_extra(spec, extra_data)
}

View File

@ -1636,7 +1636,7 @@ mod tests {
generate_dummy_client_with_spec, get_temp_state_db,
TestNotify
};
use spec::Spec;
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 = Spec::new_test_round().engine;
let engine = spec::new_test_round().engine;
assert!(!engine.name().is_empty());
}
#[test]
fn can_return_schedule() {
let engine = Spec::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 = Spec::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 = Spec::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 = Spec::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::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::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::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::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::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::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<AccountProvider>, Vec<Address>) {
let spec = Spec::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(Spec::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(Spec::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(Spec::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(Spec::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 = Spec::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(Spec::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

View File

@ -164,7 +164,7 @@ mod test {
use std::str::FromStr;
use client::PrepareOpenBlock;
use ethereum_types::{U256, Address};
use spec::Spec;
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(Spec::new_test_round_block_reward_contract);
let client = generate_dummy_client_with_spec(spec::new_test_round_block_reward_contract);
let machine = Spec::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(

View File

@ -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;
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: spec::new_test_machine(),
}
}

View File

@ -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::{new_morden, new_mcip3_test, new_homestead_test_machine};
use super::{Ethash, EthashParams, ecip1017_eras_block_reward};
use rlp;
use tempdir::TempDir;

View File

@ -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 crate::spec;
use types::header::Header;
use block::*;
use engines::Seal;
#[test]
fn instant_can_seal() {
let spec = Spec::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 = Spec::new_instant().engine;
let engine = spec::new_instant().engine;
let mut header: Header = Header::default();
assert!(engine.verify_block_basic(&header).is_ok());

View File

@ -144,7 +144,7 @@ mod tests {
use ethereum_types::{H520, Address};
use bytes::ToPretty;
use rlp::encode;
use spec::Spec;
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(Spec::new_validator_contract);
let client = generate_dummy_client_with_spec(spec::new_validator_contract);
let vc = Arc::new(ValidatorContract::new("0000000000000000000000000000000000000005".parse::<Address>().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(spec::new_validator_contract);
client.engine().register_client(Arc::downgrade(&client) as _);
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();

View File

@ -162,7 +162,7 @@ mod tests {
use ethkey::Secret;
use types::header::Header;
use miner::{self, MinerService};
use spec::Spec;
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(Spec::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(Spec::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();

View File

@ -454,7 +454,7 @@ mod tests {
use hash::keccak;
use ethereum_types::Address;
use types::ids::BlockId;
use spec::Spec;
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(Spec::new_validator_safe_contract);
let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract);
let vc = Arc::new(ValidatorSafeContract::new("0000000000000000000000000000000000000005".parse::<Address>().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 = 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::<Address>().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(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(Spec::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::<Address>().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(spec::new_validator_safe_contract);
let engine = client.engine().clone();
let mut new_header = Header::default();

View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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<Option<SpecParams<'a>>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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<SpecParams<'a>>>(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());
}
}

View File

@ -1228,15 +1228,16 @@ mod tests {
errors::ExecutionError,
transaction::{Action, Transaction},
};
use crate::spec;
fn make_frontier_machine(max_depth: usize) -> Machine {
let mut machine = ::ethereum::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 = ::ethereum::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
}
@ -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 = spec::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 = spec::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 = 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)));
@ -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 = spec::new_kovan_wasm_test_machine();
let mut output = [0u8; 20];
let FinalizationResult { gas_left: result, return_data, .. } = {

View File

@ -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;
fn secret() -> Secret {
keccak("").into()
}
fn make_frontier_machine(max_depth: usize) -> Machine {
let mut machine = ::ethereum::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 = Spec::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 = Spec::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 = Spec::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 = Spec::new_test_machine();
let machine = spec::new_test_machine();
let t = Transaction {
nonce: 0.into(),

View File

@ -442,6 +442,7 @@ mod tests {
use super::*;
use trace::{NoopTracer, NoopVMTracer};
use std::str::FromStr;
use crate::spec;
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 = spec::new_test_machine();
let env_info = get_test_env_info();
let schedule = machine.schedule(env_info.number);
TestSetup {

View File

@ -61,7 +61,7 @@ macro_rules! difficulty_json_test {
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
let tempdir = TempDir::new("").unwrap();
json_difficulty_test(json_data, ::ethereum::$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<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
json_difficulty_test(json_data, ::ethereum::$spec(), h)
json_difficulty_test(json_data, crate::spec::$spec(), h)
}
}

View File

@ -37,6 +37,7 @@ use rlp::RlpStream;
use hash::keccak;
use machine::Machine;
use ethereum_types::BigEndianHash;
use crate::spec;
use super::HookType;
@ -271,7 +272,7 @@ fn do_json_test_for<H: FnMut(&str, HookType)>(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 = spec::new_frontier_test_machine();
machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = 1));
machine
};

View File

@ -152,7 +152,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;

View File

@ -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;
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 = spec::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 = spec::new_homestead_test();
let ethparams = get_default_ethash_extensions();
let machine = Machine::with_ethash_extensions(

View File

@ -1488,12 +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;
#[test]
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(&spec::new_test(), None);
// when
let sealing_work = miner.work_package(&client);
@ -1504,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(&Spec::new_test(), None);
let miner = Miner::new_for_tests(&spec::new_test(), None);
let res = miner.work_package(&client);
let hash = res.unwrap().0;
@ -1548,7 +1549,7 @@ mod tests {
},
},
GasPricer::new_fixed(0u64.into()),
&Spec::new_test(),
&spec::new_test(),
::std::collections::HashSet::new(), // local accounts
)
}
@ -1671,7 +1672,7 @@ mod tests {
..miner().options
},
GasPricer::new_fixed(0u64.into()),
&Spec::new_test(),
&spec::new_test(),
local_accounts,
);
let transaction = transaction();
@ -1714,7 +1715,7 @@ mod tests {
..miner().options
},
GasPricer::new_fixed(0u64.into()),
&Spec::new_test(),
&spec::new_test(),
HashSet::from_iter(vec![transaction.sender()].into_iter()),
);
let best_block = 0;
@ -1746,7 +1747,7 @@ mod tests {
#[test]
fn internal_seals_without_work() {
let _ = env_logger::try_init();
let spec = Spec::new_instant();
let spec = spec::new_instant();
let miner = Miner::new_for_tests(&spec, None);
let client = generate_dummy_client(2);
@ -1775,7 +1776,7 @@ mod tests {
#[test]
fn should_not_fail_setting_engine_signer_without_account_provider() {
let spec = Spec::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);
@ -1791,7 +1792,7 @@ mod tests {
#[test]
fn should_mine_if_internal_sealing_is_enabled() {
let spec = Spec::new_instant();
let spec = spec::new_instant();
let miner = Miner::new_for_tests(&spec, None);
let client = generate_dummy_client(2);
@ -1802,7 +1803,7 @@ mod tests {
#[test]
fn should_not_mine_if_internal_sealing_is_disabled() {
let spec = Spec::new_test_round();
let spec = spec::new_test_round();
let miner = Miner::new_for_tests(&spec, None);
let client = generate_dummy_client(2);
@ -1813,7 +1814,7 @@ mod tests {
#[test]
fn should_not_mine_if_no_fetch_work_request() {
let spec = Spec::new_test();
let spec = spec::new_test();
let miner = Miner::new_for_tests(&spec, None);
let client = generate_dummy_client(2);
@ -1831,7 +1832,7 @@ mod tests {
fn notify(&self, _pow_hash: H256, _difficulty: U256, _number: u64) { }
}
let spec = Spec::new_test();
let spec = spec::new_test();
let miner = Miner::new_for_tests(&spec, None);
miner.add_work_listener(Box::new(DummyNotifyWork));
@ -1844,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(&Spec::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();
@ -1882,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(&Spec::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;

View File

@ -899,7 +899,7 @@ impl Drop for Service {
mod tests {
use client::ClientIoMessage;
use io::{IoService};
use spec::Spec;
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(Spec::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::<ClientIoMessage>::start().unwrap();
let spec = Spec::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 = Spec::new_test();
let spec = spec::new_test();
let tempdir = TempDir::new("").unwrap();
let state_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect();

View File

@ -29,6 +29,7 @@ use parking_lot::Mutex;
use snappy;
use kvdb::DBTransaction;
use test_helpers;
use crate::spec;
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 = spec::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 = spec::new_test().engine;
let chain = BlockChain::new(Default::default(), genesis.last().encoded().raw(), db.clone());
let manifest = ::snapshot::ManifestData {

View File

@ -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 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(Spec::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 = Spec::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(Spec::new_null, 400, 5, &gas_prices);
let client = generate_dummy_client_with_spec_and_data(spec::new_null, 400, 5, &gas_prices);
let spec = Spec::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 = Spec::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(Spec::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 = Spec::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();

165
ethcore/src/spec/chain.rs Normal file
View File

@ -0,0 +1,165 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Ethereum protocol module.
//!
//! Loads all protocols supported by parity-ethereum client.
macro_rules! bundle_release_spec {
($($path: expr => $name: ident), *) => {
$(
/// Bundled release spec
pub fn $name<'a, T: Into<crate::spec::SpecParams<'a>>>(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_multi" => new_validator_multi,
"validator_safe_contract" => new_validator_safe_contract
}
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());
}
}

View File

@ -16,9 +16,11 @@
//! Blockchain params.
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};

View File

@ -62,7 +62,6 @@ fn fmt_err<F: ::std::fmt::Display>(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,
@ -187,16 +186,14 @@ fn run_constructors<T: Backend>(
/// 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.
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<dyn Engine>,
/// 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<String>,
/// The genesis block's parent hash field.
pub parent_hash: H256,
/// The genesis block's author field.
@ -217,48 +214,17 @@ 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<SpecHardcodedSync>,
/// 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.
#[derive(Debug, Clone)]
pub struct SpecHardcodedSync {
/// Header of the block to jump to for hardcoded sync, and total difficulty.
pub header: encoded::Header,
@ -289,13 +255,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<Spec, Error> {
let builtins = s.accounts
@ -355,24 +314,6 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
Ok(s)
}
macro_rules! load_bundled {
($e:expr) => {
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 +361,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 +449,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<T: Backend>(&self, db: T, factories: &Factories) -> Result<T, Error> {
if db.as_hash_db().contains(&self.state_root(), hash_db::EMPTY_PREFIX) {
@ -545,20 +476,19 @@ impl Spec {
pub fn load_machine<R: Read>(reader: R) -> Result<Machine, String> {
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<SpecParams<'a>>, R>(params: T, reader: R) -> Result<Self, String>
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<SpecParams<'a>>, R: Read>(params: T, reader: R) -> Result<Self, String> {
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 +546,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 +557,7 @@ mod tests {
use types::view;
use types::views::BlockView;
use std::str::FromStr;
use crate::spec;
#[test]
fn test_load_empty() {
@ -724,7 +567,7 @@ mod tests {
#[test]
fn test_chain() {
let test_spec = Spec::new_test();
let test_spec = spec::new_test();
assert_eq!(
test_spec.state_root(),
@ -740,7 +583,7 @@ mod tests {
#[test]
fn genesis_constructor() {
let _ = ::env_logger::try_init();
let spec = Spec::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(

View File

@ -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::{Spec, self};
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<Client> {
generate_dummy_client_with_spec_and_data(Spec::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<Client> {
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(spec::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<F>(test_spec: F) -> Arc<Client> where F: Fn()->Spec {
pub fn generate_dummy_client_with_spec<F>(test_spec: F) -> Arc<Client> 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<F>(test_spec: F, block_number: u
/// Adds blocks to the client
pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting_number: usize, block_number: usize) {
let test_spec = Spec::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<Client>, timestamp_salt: u64, starting
/// Adds one block with transactions
pub fn push_block_with_transactions(client: &Arc<Client>, transactions: &[SignedTransaction]) {
let test_spec = Spec::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<Client>, transactions: &[Signed
/// Creates dummy client (not test client) with corresponding blocks
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> Arc<Client> {
let test_spec = Spec::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<Bytes> {
let test_spec = Spec::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<Bytes> {
let test_spec = Spec::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 = Spec::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 = Spec::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);

View File

@ -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;
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 = spec::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 = spec::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 = spec::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 = spec::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 = spec::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 = spec::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 = 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();

View File

@ -29,6 +29,7 @@ use types::transaction::SYSTEM_ADDRESS;
use rustc_hex::FromHex;
use ethereum_types::{H256, Address};
use crate::spec;
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 = spec::new_eip210_test_machine();
let mut env_info = EnvInfo::default();
// populate state with 256 last hashes

View File

@ -21,7 +21,7 @@ use hash::keccak;
use block::*;
use ethereum_types::{U256, Address};
use io::*;
use spec::*;
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 = Spec::new_test_with_reward();
let spec = spec::new_test_with_reward();
let engine = &*spec.engine;
// Create client

View File

@ -734,7 +734,6 @@ impl<K: Kind> Drop for VerificationQueue<K> {
#[cfg(test)]
mod tests {
use io::*;
use spec::Spec;
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 = Spec::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 = Spec::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 = Spec::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 = Spec::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 = Spec::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 = Spec::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 = Spec::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);

View File

@ -372,7 +372,7 @@ mod tests {
use hash::keccak;
use engines::Engine;
use ethkey::{Random, Generator};
use spec::Spec;
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 = Spec::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 = Spec::new_test();
let spec = spec::new_test();
let engine = &*spec.engine;
let min_gas_limit = engine.params().min_gas_limit;

View File

@ -636,7 +636,7 @@ fn all_expected<A, B, F>(values: &[A], expected_values: &[B], is_expected: F) ->
mod tests {
use super::*;
use ethcore::client::TestBlockChainClient;
use ethcore::spec::Spec;
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 = Spec::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 = Spec::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 = Spec::new_test();
let spec = spec::new_test();
let genesis_hash = spec.genesis_header().hash();
let mut downloader = BlockDownloader::new(BlockSet::NewBlocks, &genesis_hash, 0);

View File

@ -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;
use io::IoChannel;
use kvdb_memorydb;
use light::client::fetch::{self, Unavailable};
@ -229,7 +229,7 @@ impl TestNet<Peer> {
config,
Arc::new(db),
None,
&Spec::new_test(),
&spec::new_test(),
fetch::unavailable(), // TODO: allow fetch from full nodes.
IoChannel::disconnected(),
cache

View File

@ -19,6 +19,7 @@ use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockId, EachBlock
use chain::{SyncState};
use super::helpers::*;
use {SyncConfig, WarpSync};
use ethcore::spec;
#[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 = 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));

View File

@ -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;
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 = spec::new_test_round().chain_id();
let mut net = TestNet::with_spec(2, SyncConfig::default(), spec::new_test_round);
let io_handler0: Arc<dyn IoHandler<ClientIoMessage>> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone()));
let io_handler1: Arc<dyn IoHandler<ClientIoMessage>> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone()));
// Push transaction to both clients. Only one of them gets lucky to produce a block.

View File

@ -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::{self, Spec};
use ethcore::miner::Miner;
use ethcore::test_helpers;
use sync_io::SyncIo;
@ -351,7 +351,7 @@ impl TestNet<EthPeer<TestBlockChainClient>> {
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(&spec::new_test(), None)),
queue: RwLock::new(VecDeque::new()),
private_tx_handler,
io_queue: RwLock::new(VecDeque::new()),

View File

@ -88,12 +88,12 @@ pub fn run_action<T: Informant>(
// 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(&params.code_address) {
if let Some(acc) = spec.genesis_state.get().get(&params.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),
@ -240,6 +240,7 @@ pub mod tests {
use super::*;
use tempdir::TempDir;
use ethereum_types::Address;
use ethcore::spec::{self, Spec};
pub fn run_test<T, I, F>(
informant: I,
@ -257,7 +258,7 @@ pub mod tests {
params.gas = gas.into();
let tempdir = TempDir::new("").unwrap();
let spec = ::ethcore::ethereum::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, .. }) => {
@ -278,7 +279,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!(

View File

@ -443,7 +443,7 @@ impl Args {
spec::Spec::load(&::std::env::temp_dir(), file)?
},
None => {
ethcore::ethereum::new_foundation(&::std::env::temp_dir())
spec::new_foundation(&::std::env::temp_dir())
},
})
}

View File

@ -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, self};
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<SpecParams<'a>>>(&self, params: T) -> Result<Spec, String> {
let params = params.into();
match *self {
SpecType::Foundation => Ok(ethereum::new_foundation(params)),
SpecType::Classic => Ok(ethereum::new_classic(params)),
SpecType::Poanet => Ok(ethereum::new_poanet(params)),
SpecType::Tobalaba => Ok(ethereum::new_tobalaba(params)),
SpecType::Expanse => Ok(ethereum::new_expanse(params)),
SpecType::Musicoin => Ok(ethereum::new_musicoin(params)),
SpecType::Ellaism => Ok(ethereum::new_ellaism(params)),
SpecType::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(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)

View File

@ -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, self};
use ethcore::test_helpers;
use ethcore::verification::VerifierType;
use ethcore::verification::queue::kind::blocks::Unverified;
@ -64,7 +63,7 @@ fn snapshot_service() -> Arc<TestSnapshotService> {
fn make_spec(chain: &BlockChain) -> Spec {
let genesis = Genesis::from(chain.genesis());
let mut spec = ethereum::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);