spec loading cleanup (#858)
* spec loading cleanup in progress * changed engine field in json spec * refactored engine params * polishing spec loading refactor * fixed compiling json tests * fixed compiling parity * removed warnings * removed commented out code * fixed failing test * bringing back removed TODO in spec.
This commit is contained in:
@@ -40,8 +40,7 @@ fn returns_state_root_basic() {
|
||||
let client_result = generate_dummy_client(6);
|
||||
let client = client_result.reference();
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
let state_root = test_engine.spec().genesis_header().state_root;
|
||||
let state_root = test_spec.genesis_header().state_root;
|
||||
|
||||
assert!(client.state_data(&state_root).is_some());
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ impl<T> GuardedTempResult<T> {
|
||||
|
||||
pub struct TestEngine {
|
||||
factory: Factory,
|
||||
spec: Spec,
|
||||
engine: Box<Engine>,
|
||||
max_depth: usize
|
||||
}
|
||||
|
||||
@@ -60,18 +60,29 @@ impl TestEngine {
|
||||
pub fn new(max_depth: usize, factory: Factory) -> TestEngine {
|
||||
TestEngine {
|
||||
factory: factory,
|
||||
spec: ethereum::new_frontier_test(),
|
||||
engine: ethereum::new_frontier_test().engine,
|
||||
max_depth: max_depth
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Engine for TestEngine {
|
||||
fn name(&self) -> &str { "TestEngine" }
|
||||
fn spec(&self) -> &Spec { &self.spec }
|
||||
fn name(&self) -> &str {
|
||||
"TestEngine"
|
||||
}
|
||||
|
||||
fn params(&self) -> &CommonParams {
|
||||
self.engine.params()
|
||||
}
|
||||
|
||||
fn builtins(&self) -> &BTreeMap<Address, Builtin> {
|
||||
self.engine.builtins()
|
||||
}
|
||||
|
||||
fn vm_factory(&self) -> &Factory {
|
||||
&self.factory
|
||||
}
|
||||
|
||||
fn schedule(&self, _env_info: &EnvInfo) -> Schedule {
|
||||
let mut schedule = Schedule::new_frontier();
|
||||
schedule.max_depth = self.max_depth;
|
||||
@@ -136,17 +147,17 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>
|
||||
|
||||
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
let state_root = test_engine.spec().genesis_header().state_root;
|
||||
let mut rolling_hash = test_engine.spec().genesis_header().hash();
|
||||
let test_engine = &test_spec.engine;
|
||||
let state_root = test_spec.genesis_header().state_root;
|
||||
let mut rolling_hash = test_spec.genesis_header().hash();
|
||||
let mut rolling_block_number = 1;
|
||||
let mut rolling_timestamp = 40;
|
||||
|
||||
for _ in 0..block_number {
|
||||
let mut header = Header::new();
|
||||
|
||||
header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap());
|
||||
header.difficulty = decode(test_engine.spec().engine_params.get("minimumDifficulty").unwrap());
|
||||
header.gas_limit = test_engine.params().min_gas_limit;
|
||||
header.difficulty = U256::from(0x20000);
|
||||
header.timestamp = rolling_timestamp;
|
||||
header.number = rolling_block_number;
|
||||
header.parent_hash = rolling_hash;
|
||||
@@ -171,8 +182,9 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>
|
||||
|
||||
pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting_number: usize, block_number: usize) {
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
let state_root = test_engine.spec().genesis_header().state_root;
|
||||
let test_engine = &test_spec.engine;
|
||||
//let test_engine = test_spec.to_engine().unwrap();
|
||||
let state_root = test_spec.genesis_header().state_root;
|
||||
let mut rolling_hash = client.chain_info().best_block_hash;
|
||||
let mut rolling_block_number = starting_number as u64;
|
||||
let mut rolling_timestamp = timestamp_salt + starting_number as u64 * 10;
|
||||
@@ -180,8 +192,8 @@ pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting
|
||||
for _ in 0..block_number {
|
||||
let mut header = Header::new();
|
||||
|
||||
header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap());
|
||||
header.difficulty = decode(test_engine.spec().engine_params.get("minimumDifficulty").unwrap());
|
||||
header.gas_limit = test_engine.params().min_gas_limit;
|
||||
header.difficulty = U256::from(0x20000);
|
||||
header.timestamp = rolling_timestamp;
|
||||
header.number = rolling_block_number;
|
||||
header.parent_hash = rolling_hash;
|
||||
@@ -279,24 +291,23 @@ pub fn get_temp_state_in(path: &Path) -> State {
|
||||
|
||||
pub fn get_good_dummy_block_seq(count: usize) -> Vec<Bytes> {
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
get_good_dummy_block_fork_seq(1, count, &test_engine.spec().genesis_header().hash())
|
||||
get_good_dummy_block_fork_seq(1, count, &test_spec.genesis_header().hash())
|
||||
}
|
||||
|
||||
pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_hash: &H256) -> Vec<Bytes> {
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
let test_engine = &test_spec.engine;
|
||||
let mut rolling_timestamp = start_number as u64 * 10;
|
||||
let mut parent = *parent_hash;
|
||||
let mut r = Vec::new();
|
||||
for i in start_number .. start_number + count + 1 {
|
||||
let mut block_header = Header::new();
|
||||
block_header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap());
|
||||
block_header.gas_limit = test_engine.params().min_gas_limit;
|
||||
block_header.difficulty = U256::from(i).mul(U256([0, 1, 0, 0]));
|
||||
block_header.timestamp = rolling_timestamp;
|
||||
block_header.number = i as u64;
|
||||
block_header.parent_hash = parent;
|
||||
block_header.state_root = test_engine.spec().genesis_header().state_root;
|
||||
block_header.state_root = test_spec.genesis_header().state_root;
|
||||
|
||||
parent = block_header.hash();
|
||||
rolling_timestamp = rolling_timestamp + 10;
|
||||
@@ -310,13 +321,13 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h
|
||||
pub fn get_good_dummy_block() -> Bytes {
|
||||
let mut block_header = Header::new();
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
block_header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap());
|
||||
block_header.difficulty = decode(test_engine.spec().engine_params.get("minimumDifficulty").unwrap());
|
||||
let test_engine = &test_spec.engine;
|
||||
block_header.gas_limit = test_engine.params().min_gas_limit;
|
||||
block_header.difficulty = U256::from(0x20000);
|
||||
block_header.timestamp = 40;
|
||||
block_header.number = 1;
|
||||
block_header.parent_hash = test_engine.spec().genesis_header().hash();
|
||||
block_header.state_root = test_engine.spec().genesis_header().state_root;
|
||||
block_header.parent_hash = test_spec.genesis_header().hash();
|
||||
block_header.state_root = test_spec.genesis_header().state_root;
|
||||
|
||||
create_test_block(&block_header)
|
||||
}
|
||||
@@ -324,12 +335,12 @@ pub fn get_good_dummy_block() -> Bytes {
|
||||
pub fn get_bad_state_dummy_block() -> Bytes {
|
||||
let mut block_header = Header::new();
|
||||
let test_spec = get_test_spec();
|
||||
let test_engine = test_spec.to_engine().unwrap();
|
||||
block_header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap());
|
||||
block_header.difficulty = decode(test_engine.spec().engine_params.get("minimumDifficulty").unwrap());
|
||||
let test_engine = &test_spec.engine;
|
||||
block_header.gas_limit = test_engine.params().min_gas_limit;
|
||||
block_header.difficulty = U256::from(0x20000);
|
||||
block_header.timestamp = 40;
|
||||
block_header.number = 1;
|
||||
block_header.parent_hash = test_engine.spec().genesis_header().hash();
|
||||
block_header.parent_hash = test_spec.genesis_header().hash();
|
||||
block_header.state_root = x!(0xbad);
|
||||
|
||||
create_test_block(&block_header)
|
||||
|
||||
Reference in New Issue
Block a user