move spec constructors to spec
This commit is contained in:
parent
529633e9b2
commit
a719b91b63
@ -423,13 +423,13 @@ mod tests {
|
||||
use env_info::EnvInfo;
|
||||
use error::{BlockError, Error};
|
||||
use header::Header;
|
||||
use super::super::{new_morden, new_homestead_test};
|
||||
use spec::Spec;
|
||||
use super::{Ethash, EthashParams};
|
||||
use rlp;
|
||||
|
||||
#[test]
|
||||
fn on_close_block() {
|
||||
let spec = new_morden();
|
||||
let spec = Spec::new_ethereum_morden();
|
||||
let engine = &*spec.engine;
|
||||
let genesis_header = spec.genesis_header();
|
||||
let mut db_result = get_temp_state_db();
|
||||
@ -443,7 +443,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn on_close_block_with_uncle() {
|
||||
let spec = new_morden();
|
||||
let spec = Spec::new_ethereum_morden();
|
||||
let engine = &*spec.engine;
|
||||
let genesis_header = spec.genesis_header();
|
||||
let mut db_result = get_temp_state_db();
|
||||
@ -463,14 +463,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn has_valid_metadata() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
assert!(!engine.name().is_empty());
|
||||
assert!(engine.version().major >= 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_return_schedule() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let schedule = engine.schedule(&EnvInfo {
|
||||
number: 10000000,
|
||||
author: 0.into(),
|
||||
@ -498,8 +498,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_do_seal_verification_fail() {
|
||||
let engine = new_morden().engine;
|
||||
//let engine = Ethash::new_test(new_morden());
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
//let engine = Ethash::new_test(Spec::new_ethereum_morden());
|
||||
let header: Header = Header::default();
|
||||
|
||||
let verify_result = engine.verify_block_basic(&header, None);
|
||||
@ -513,7 +513,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_do_difficulty_verification_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let mut header: Header = Header::default();
|
||||
header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||
|
||||
@ -528,7 +528,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_do_proof_of_work_verification_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let mut header: Header = Header::default();
|
||||
header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||
header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap());
|
||||
@ -544,7 +544,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_do_seal_unordered_verification_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let header: Header = Header::default();
|
||||
|
||||
let verify_result = engine.verify_block_unordered(&header, None);
|
||||
@ -558,7 +558,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_do_seal256_verification_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let mut header: Header = Header::default();
|
||||
header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||
let verify_result = engine.verify_block_unordered(&header, None);
|
||||
@ -572,7 +572,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_do_proof_of_work_unordered_verification_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let mut header: Header = Header::default();
|
||||
header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||
header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap());
|
||||
@ -588,7 +588,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_verify_block_family_genesis_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let header: Header = Header::default();
|
||||
let parent_header: Header = Header::default();
|
||||
|
||||
@ -603,7 +603,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_verify_block_family_difficulty_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let mut header: Header = Header::default();
|
||||
header.set_number(2);
|
||||
let mut parent_header: Header = Header::default();
|
||||
@ -620,7 +620,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_verify_block_family_gas_fail() {
|
||||
let engine = new_morden().engine;
|
||||
let engine = Spec::new_ethereum_morden().engine;
|
||||
let mut header: Header = Header::default();
|
||||
header.set_number(2);
|
||||
header.set_difficulty(U256::from_str("0000000000000000000000000000000000000000000000000000000000020000").unwrap());
|
||||
@ -648,7 +648,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn difficulty_frontier() {
|
||||
let spec = new_homestead_test();
|
||||
let spec = Spec::new_ethereum_homestead_test();
|
||||
let ethparams = get_default_ethash_params();
|
||||
let ethash = Ethash::new(spec.params, ethparams, BTreeMap::new());
|
||||
|
||||
@ -666,7 +666,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn difficulty_homestead() {
|
||||
let spec = new_homestead_test();
|
||||
let spec = Spec::new_ethereum_homestead_test();
|
||||
let ethparams = get_default_ethash_params();
|
||||
let ethash = Ethash::new(spec.params, ethparams, BTreeMap::new());
|
||||
|
||||
@ -684,7 +684,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn difficulty_classic_bomb_delay() {
|
||||
let spec = new_homestead_test();
|
||||
let spec = Spec::new_ethereum_homestead_test();
|
||||
let ethparams = EthashParams {
|
||||
ecip1010_pause_transition: 3000000,
|
||||
..get_default_ethash_params()
|
||||
@ -717,7 +717,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_difficulty_bomb_continue() {
|
||||
let spec = new_homestead_test();
|
||||
let spec = Spec::new_ethereum_homestead_test();
|
||||
let ethparams = EthashParams {
|
||||
ecip1010_pause_transition: 3000000,
|
||||
ecip1010_continue_transition: 5000000,
|
||||
|
@ -27,56 +27,17 @@ pub mod denominations;
|
||||
pub use self::ethash::{Ethash};
|
||||
pub use self::denominations::*;
|
||||
|
||||
use super::spec::*;
|
||||
|
||||
fn load(b: &[u8]) -> Spec {
|
||||
Spec::load(b).expect("chain spec is invalid")
|
||||
}
|
||||
|
||||
/// Create a new Olympic chain spec.
|
||||
pub fn new_olympic() -> Spec { load(include_bytes!("../../res/ethereum/olympic.json")) }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec.
|
||||
pub fn new_frontier() -> Spec { load(include_bytes!("../../res/ethereum/frontier.json")) }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec without the DAO hardfork.
|
||||
pub fn new_classic() -> Spec { load(include_bytes!("../../res/ethereum/classic.json")) }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec without the DAO hardfork.
|
||||
pub fn new_expanse() -> Spec { load(include_bytes!("../../res/ethereum/expanse.json")) }
|
||||
|
||||
/// Create a new Frontier chain spec as though it never changes to Homestead.
|
||||
pub fn new_frontier_test() -> Spec { load(include_bytes!("../../res/ethereum/frontier_test.json")) }
|
||||
|
||||
/// Create a new Homestead chain spec as though it never changed from Frontier.
|
||||
pub fn new_homestead_test() -> Spec { load(include_bytes!("../../res/ethereum/homestead_test.json")) }
|
||||
|
||||
/// Create a new Homestead-EIP150 chain spec as though it never changed from Homestead/Frontier.
|
||||
pub fn new_eip150_test() -> Spec { load(include_bytes!("../../res/ethereum/eip150_test.json")) }
|
||||
|
||||
/// Create a new Homestead-EIP150 chain spec as though it never changed from Homestead/Frontier.
|
||||
pub fn new_eip161_test() -> Spec { load(include_bytes!("../../res/ethereum/eip161_test.json")) }
|
||||
|
||||
/// Create a new Frontier/Homestead/DAO chain spec with transition points at #5 and #8.
|
||||
pub fn new_transition_test() -> Spec { load(include_bytes!("../../res/ethereum/transition_test.json")) }
|
||||
|
||||
/// Create a new Frontier main net chain spec without genesis accounts.
|
||||
pub fn new_mainnet_like() -> Spec { load(include_bytes!("../../res/ethereum/frontier_like_test.json")) }
|
||||
|
||||
/// Create a new Morden chain spec.
|
||||
pub fn new_morden() -> Spec { load(include_bytes!("../../res/ethereum/morden.json")) }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use util::*;
|
||||
use state::*;
|
||||
use super::*;
|
||||
use tests::helpers::*;
|
||||
use spec::Spec;
|
||||
use views::BlockView;
|
||||
|
||||
#[test]
|
||||
fn ensure_db_good() {
|
||||
let spec = new_morden();
|
||||
let spec = Spec::new_ethereum_morden();
|
||||
let engine = &spec.engine;
|
||||
let genesis_header = spec.genesis_header();
|
||||
let mut db_result = get_temp_state_db();
|
||||
@ -93,7 +54,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn morden() {
|
||||
let morden = new_morden();
|
||||
let morden = Spec::new_ethereum_morden();
|
||||
|
||||
assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".into());
|
||||
let genesis = morden.genesis_block();
|
||||
@ -104,7 +65,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn frontier() {
|
||||
let frontier = new_frontier();
|
||||
let frontier = Spec::new_ethereum_frontier();
|
||||
|
||||
assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".into());
|
||||
let genesis = frontier.genesis_block();
|
||||
|
@ -27,12 +27,12 @@
|
||||
//! extern crate ethcore_util as util;
|
||||
//! extern crate ethcore;
|
||||
//! use std::env;
|
||||
//! use ethcore::ethereum;
|
||||
//! use spec::Spec;
|
||||
//! use ethcore::client::{Client, ClientConfig};
|
||||
//! use ethcore::miner::{Miner, MinerService};
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let miner: Miner = Miner::with_spec(ðereum::new_frontier());
|
||||
//! let miner: Miner = Miner::with_spec(&Spec::new_ethereum_frontier());
|
||||
//! // get status
|
||||
//! assert_eq!(miner.status().transactions_in_pending_queue, 0);
|
||||
//!
|
||||
|
@ -135,6 +135,12 @@ impl From<ethjson::spec::Spec> for Spec {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! load_bundled {
|
||||
($e:expr) => {
|
||||
Spec::load(include_bytes!(concat!("../../res/", $e, ".json")) as &[u8]).expect("Chain spec is invalid")
|
||||
};
|
||||
}
|
||||
|
||||
impl Spec {
|
||||
/// Convert engine spec into a arc'd Engine of the right underlying type.
|
||||
/// TODO avoid this hard-coded nastiness - use dynamic-linked plugin framework instead.
|
||||
@ -267,19 +273,46 @@ impl Spec {
|
||||
}
|
||||
|
||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus.
|
||||
pub fn new_test() -> Self {
|
||||
Spec::load(include_bytes!("../../res/null_morden.json") as &[u8]).expect("null_morden.json is invalid")
|
||||
}
|
||||
pub fn new_test() -> Spec { load_bundled!("null_morden") }
|
||||
|
||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is sha3('').
|
||||
pub fn new_null() -> Self {
|
||||
Spec::load(include_bytes!("../../res/null.json") as &[u8]).expect("null.json is invalid")
|
||||
}
|
||||
pub fn new_null() -> Spec { load_bundled!("null") }
|
||||
|
||||
/// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring work).
|
||||
pub fn new_test_instant() -> Self {
|
||||
Spec::load(include_bytes!("../../res/instant_seal.json") as &[u8]).expect("instant_seal.json is invalid")
|
||||
}
|
||||
pub fn new_test_instant() -> Spec { load_bundled!("instant_seal") }
|
||||
|
||||
/// Create a new Olympic chain spec.
|
||||
pub fn new_ethereum_olympic() -> Spec { load_bundled!("ethereum/olympic") }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec.
|
||||
pub fn new_ethereum_frontier() -> Spec { load_bundled!("ethereum/frontier") }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec without the DAO hardfork.
|
||||
pub fn new_ethereum_classic() -> Spec { load_bundled!("ethereum/classic") }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec without the DAO hardfork.
|
||||
pub fn new_expanse() -> Spec { load_bundled!("expanse") }
|
||||
|
||||
/// Create a new Frontier chain spec as though it never changes to Homestead.
|
||||
pub fn new_ethereum_frontier_test() -> Spec { load_bundled!("ethereum/frontier_test") }
|
||||
|
||||
/// Create a new Homestead chain spec as though it never changed from Frontier.
|
||||
pub fn new_ethereum_homestead_test() -> Spec { load_bundled!("ethereum/homestead_test") }
|
||||
|
||||
/// Create a new Homestead-EIP150 chain spec as though it never changed from Homestead/Frontier.
|
||||
pub fn new_ethereum_eip150_test() -> Spec { load_bundled!("ethereum/eip150_test") }
|
||||
|
||||
/// Create a new Homestead-EIP150 chain spec as though it never changed from Homestead/Frontier.
|
||||
pub fn new_ethereum_eip161_test() -> Spec { load_bundled!("ethereum/eip161_test") }
|
||||
|
||||
/// Create a new Frontier/Homestead/DAO chain spec with transition points at #5 and #8.
|
||||
pub fn new_ethereum_transition_test() -> Spec { load_bundled!("ethereum/transition_test") }
|
||||
|
||||
/// Create a new Frontier main net chain spec without genesis accounts.
|
||||
pub fn new_ethereum_mainnet_like() -> Spec { load_bundled!("ethereum/frontier_like_test") }
|
||||
|
||||
/// Create a new Morden chain spec.
|
||||
pub fn new_ethereum_morden() -> Spec { load_bundled!("ethereum/morden") }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -17,7 +17,6 @@
|
||||
use io::IoChannel;
|
||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID};
|
||||
use state::CleanupMode;
|
||||
use ethereum;
|
||||
use block::IsBlock;
|
||||
use tests::helpers::*;
|
||||
use types::filter::Filter;
|
||||
@ -50,7 +49,7 @@ fn imports_from_empty() {
|
||||
#[test]
|
||||
fn should_return_registrar() {
|
||||
let dir = RandomTempPath::new();
|
||||
let spec = ethereum::new_morden();
|
||||
let spec = Spec::new_ethereum_morden();
|
||||
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||
|
||||
let client = Client::new(
|
||||
|
@ -27,7 +27,6 @@ use state::*;
|
||||
use evm::Schedule;
|
||||
use engines::Engine;
|
||||
use env_info::EnvInfo;
|
||||
use ethereum;
|
||||
use ethereum::ethash::EthashParams;
|
||||
use devtools::*;
|
||||
use miner::Miner;
|
||||
@ -53,7 +52,7 @@ pub struct TestEngine {
|
||||
impl TestEngine {
|
||||
pub fn new(max_depth: usize) -> TestEngine {
|
||||
TestEngine {
|
||||
engine: ethereum::new_frontier_test().engine,
|
||||
engine: Spec::new_ethereum_frontier_test().engine,
|
||||
max_depth: max_depth,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user