Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
unify loading spec && further spec cleanups (#10948)
Browse files Browse the repository at this point in the history
* bundle_* macros for spec

* fixed failing tests

* renamed bundle.rs to chain.rs

* removed unused derives

* updated spec/chain.rs description
  • Loading branch information
debris authored and dvdplm committed Aug 7, 2019
1 parent c689495 commit 45978bc
Show file tree
Hide file tree
Showing 45 changed files with 378 additions and 591 deletions.
18 changes: 9 additions & 9 deletions ethcore/light/src/client/header_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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))));
Expand Down Expand Up @@ -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))));

Expand All @@ -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))));
Expand Down Expand Up @@ -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))));
Expand Down Expand Up @@ -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))));
Expand All @@ -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))));
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions ethcore/light/src/client/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions ethcore/private-tx/tests/private_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()]);
Expand All @@ -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();

Expand All @@ -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();

Expand Down
21 changes: 9 additions & 12 deletions ethcore/src/client/evm_test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Expand Down
32 changes: 16 additions & 16 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1673,21 +1673,21 @@ 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);
}

#[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())]);

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 _);
Expand Down Expand Up @@ -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 _);
Expand Down Expand Up @@ -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 _);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
Loading

0 comments on commit 45978bc

Please sign in to comment.