2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity 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 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. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-07-29 17:12:07 +02:00
|
|
|
use std::collections::BTreeMap;
|
2017-07-29 21:56:42 +02:00
|
|
|
use std::sync::Arc;
|
2017-08-30 19:18:28 +02:00
|
|
|
use hash::keccak;
|
2016-08-24 18:35:21 +02:00
|
|
|
use ethkey::KeyPair;
|
2016-08-05 10:32:04 +02:00
|
|
|
use io::*;
|
2016-08-18 18:24:49 +02:00
|
|
|
use client::{BlockChainClient, Client, ClientConfig};
|
2017-09-04 16:36:49 +02:00
|
|
|
use bigint::prelude::U256;
|
|
|
|
use bigint::hash::H256;
|
2016-10-24 18:35:25 +02:00
|
|
|
use util::*;
|
2016-01-27 11:50:48 +01:00
|
|
|
use spec::*;
|
2017-01-18 18:49:50 +01:00
|
|
|
use account_provider::AccountProvider;
|
2016-09-27 18:02:11 +02:00
|
|
|
use state_db::StateDB;
|
2016-06-29 21:49:12 +02:00
|
|
|
use block::{OpenBlock, Drain};
|
2016-05-26 18:24:51 +02:00
|
|
|
use blockchain::{BlockChain, Config as BlockChainConfig};
|
2016-10-24 18:35:25 +02:00
|
|
|
use builtin::Builtin;
|
2016-01-31 10:52:07 +01:00
|
|
|
use state::*;
|
2017-05-30 11:52:33 +02:00
|
|
|
use evm::{Schedule, Factory as EvmFactory};
|
|
|
|
use factory::Factories;
|
2016-07-28 20:32:20 +02:00
|
|
|
use engines::Engine;
|
2016-02-09 16:31:57 +01:00
|
|
|
use ethereum;
|
2016-11-04 23:09:23 +01:00
|
|
|
use ethereum::ethash::EthashParams;
|
2016-05-31 22:24:32 +02:00
|
|
|
use miner::Miner;
|
2016-10-24 18:35:25 +02:00
|
|
|
use header::Header;
|
2017-01-13 09:51:36 +01:00
|
|
|
use transaction::{Action, Transaction, SignedTransaction};
|
2017-03-20 19:14:29 +01:00
|
|
|
use rlp::{self, RlpStream};
|
2016-10-24 18:35:25 +02:00
|
|
|
use views::BlockView;
|
2016-02-03 15:33:58 +01:00
|
|
|
|
|
|
|
#[cfg(feature = "json-tests")]
|
2016-01-29 17:49:58 +01:00
|
|
|
pub enum ChainEra {
|
|
|
|
Frontier,
|
|
|
|
Homestead,
|
2016-10-15 14:39:15 +02:00
|
|
|
Eip150,
|
2017-04-12 13:33:49 +02:00
|
|
|
_Eip161,
|
2016-10-15 14:39:15 +02:00
|
|
|
TransitionTest,
|
2016-01-29 17:49:58 +01:00
|
|
|
}
|
2016-01-27 13:41:41 +01:00
|
|
|
|
2016-02-09 16:31:57 +01:00
|
|
|
pub struct TestEngine {
|
2016-08-05 17:00:46 +02:00
|
|
|
engine: Arc<Engine>,
|
2016-10-15 14:39:15 +02:00
|
|
|
max_depth: usize,
|
2016-02-09 16:31:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TestEngine {
|
2016-05-19 00:44:49 +02:00
|
|
|
pub fn new(max_depth: usize) -> TestEngine {
|
2016-02-09 16:31:57 +01:00
|
|
|
TestEngine {
|
2016-04-09 19:20:35 +02:00
|
|
|
engine: ethereum::new_frontier_test().engine,
|
2016-10-15 14:39:15 +02:00
|
|
|
max_depth: max_depth,
|
2016-02-09 16:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
2017-05-23 15:49:17 +02:00
|
|
|
|
|
|
|
pub fn new_metropolis() -> TestEngine {
|
|
|
|
TestEngine {
|
|
|
|
engine: ethereum::new_metropolis_test().engine,
|
|
|
|
max_depth: 0,
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 16:31:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Engine for TestEngine {
|
2016-04-09 19:20:35 +02:00
|
|
|
fn name(&self) -> &str {
|
|
|
|
"TestEngine"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn params(&self) -> &CommonParams {
|
|
|
|
self.engine.params()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn builtins(&self) -> &BTreeMap<Address, Builtin> {
|
|
|
|
self.engine.builtins()
|
|
|
|
}
|
|
|
|
|
2017-04-19 14:30:00 +02:00
|
|
|
fn schedule(&self, _block_number: u64) -> Schedule {
|
2017-05-23 15:49:17 +02:00
|
|
|
let mut schedule = self.engine.schedule(0);
|
2016-02-09 16:31:57 +01:00
|
|
|
schedule.max_depth = self.max_depth;
|
|
|
|
schedule
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:44:08 +02:00
|
|
|
// TODO: move everything over to get_null_spec.
|
2016-01-27 11:50:48 +01:00
|
|
|
pub fn get_test_spec() -> Spec {
|
|
|
|
Spec::new_test()
|
|
|
|
}
|
|
|
|
|
2016-01-27 13:23:24 +01:00
|
|
|
pub fn create_test_block(header: &Header) -> Bytes {
|
|
|
|
let mut rlp = RlpStream::new_list(3);
|
|
|
|
rlp.append(header);
|
|
|
|
rlp.append_raw(&rlp::EMPTY_LIST_RLP, 1);
|
|
|
|
rlp.append_raw(&rlp::EMPTY_LIST_RLP, 1);
|
|
|
|
rlp.out()
|
|
|
|
}
|
|
|
|
|
2016-01-28 15:38:42 +01:00
|
|
|
fn create_unverifiable_block_header(order: u32, parent_hash: H256) -> Header {
|
2016-01-27 18:31:14 +01:00
|
|
|
let mut header = Header::new();
|
2016-08-29 11:35:24 +02:00
|
|
|
header.set_gas_limit(0.into());
|
|
|
|
header.set_difficulty((order * 100).into());
|
|
|
|
header.set_timestamp((order * 10) as u64);
|
|
|
|
header.set_number(order as u64);
|
|
|
|
header.set_parent_hash(parent_hash);
|
|
|
|
header.set_state_root(H256::zero());
|
2016-01-27 18:31:14 +01:00
|
|
|
|
2016-01-28 12:24:16 +01:00
|
|
|
header
|
|
|
|
}
|
|
|
|
|
2016-01-28 15:38:42 +01:00
|
|
|
fn create_unverifiable_block_with_extra(order: u32, parent_hash: H256, extra: Option<Bytes>) -> Bytes {
|
|
|
|
let mut header = create_unverifiable_block_header(order, parent_hash);
|
2016-08-29 11:35:24 +02:00
|
|
|
header.set_extra_data(match extra {
|
2016-01-28 12:24:16 +01:00
|
|
|
Some(extra_data) => extra_data,
|
|
|
|
None => {
|
2016-01-28 15:38:42 +01:00
|
|
|
let base = (order & 0x000000ff) as u8;
|
2016-01-28 16:59:31 +01:00
|
|
|
let generated: Vec<u8> = vec![base + 1, base + 2, base + 3];
|
|
|
|
generated
|
2016-01-28 12:24:16 +01:00
|
|
|
}
|
2016-08-29 11:35:24 +02:00
|
|
|
});
|
2016-01-27 18:31:14 +01:00
|
|
|
create_test_block(&header)
|
|
|
|
}
|
|
|
|
|
2016-01-28 17:15:45 +01:00
|
|
|
fn create_unverifiable_block(order: u32, parent_hash: H256) -> Bytes {
|
|
|
|
create_test_block(&create_unverifiable_block_header(order, parent_hash))
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:44:08 +02:00
|
|
|
pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransaction], uncles: &[Header]) -> Bytes {
|
2016-01-29 10:16:53 +01:00
|
|
|
let mut rlp = RlpStream::new_list(3);
|
|
|
|
rlp.append(header);
|
2016-01-29 17:07:23 +01:00
|
|
|
rlp.begin_list(transactions.len());
|
2016-01-29 10:16:53 +01:00
|
|
|
for t in transactions {
|
2017-06-28 14:16:53 +02:00
|
|
|
rlp.append_raw(&rlp::encode(t).into_vec(), 1);
|
2016-01-29 10:16:53 +01:00
|
|
|
}
|
2017-03-20 19:14:29 +01:00
|
|
|
rlp.append_list(&uncles);
|
2016-01-29 10:16:53 +01:00
|
|
|
rlp.out()
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_client(block_number: u32) -> Arc<Client> {
|
2016-06-18 15:11:10 +02:00
|
|
|
generate_dummy_client_with_spec_and_data(Spec::new_test, block_number, 0, &[])
|
2016-06-16 12:44:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> {
|
2016-06-16 12:44:08 +02:00
|
|
|
generate_dummy_client_with_spec_and_data(Spec::new_null, block_number, txs_per_block, tx_gas_prices)
|
|
|
|
}
|
|
|
|
|
2017-01-18 18:49:50 +01:00
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_client_with_spec_and_data<F>(get_test_spec: F, block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> where F: Fn()->Spec {
|
2017-01-18 18:49:50 +01:00
|
|
|
generate_dummy_client_with_spec_accounts_and_data(get_test_spec, None, block_number, txs_per_block, tx_gas_prices)
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_client_with_spec_and_accounts<F>(get_test_spec: F, accounts: Option<Arc<AccountProvider>>) -> Arc<Client> where F: Fn()->Spec {
|
2017-01-18 18:49:50 +01:00
|
|
|
generate_dummy_client_with_spec_accounts_and_data(get_test_spec, accounts, 0, 0, &[])
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_client_with_spec_accounts_and_data<F>(get_test_spec: F, accounts: Option<Arc<AccountProvider>>, block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> where F: Fn()->Spec {
|
2016-01-27 13:23:24 +01:00
|
|
|
let test_spec = get_test_spec();
|
2017-04-06 19:26:17 +02:00
|
|
|
let client_db = new_db();
|
2016-09-07 15:27:28 +02:00
|
|
|
|
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&test_spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
client_db,
|
2017-01-18 18:49:50 +01:00
|
|
|
Arc::new(Miner::with_spec_and_accounts(&test_spec, accounts)),
|
2016-09-07 15:27:28 +02:00
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
2016-08-10 16:29:40 +02:00
|
|
|
let test_engine = &*test_spec.engine;
|
2016-06-16 12:44:08 +02:00
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
let mut db = test_spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap();
|
2016-06-16 12:44:08 +02:00
|
|
|
let genesis_header = test_spec.genesis_header();
|
|
|
|
|
2016-01-27 13:23:24 +01:00
|
|
|
let mut rolling_timestamp = 40;
|
2016-06-16 12:44:08 +02:00
|
|
|
let mut last_hashes = vec![];
|
|
|
|
let mut last_header = genesis_header.clone();
|
2016-01-27 11:50:48 +01:00
|
|
|
|
2017-08-30 19:18:28 +02:00
|
|
|
let kp = KeyPair::from_secret_slice(&keccak("")).unwrap();
|
2016-06-16 12:44:08 +02:00
|
|
|
let author = kp.address();
|
2016-01-27 11:50:48 +01:00
|
|
|
|
2016-06-16 12:44:08 +02:00
|
|
|
let mut n = 0;
|
|
|
|
for _ in 0..block_number {
|
|
|
|
last_hashes.push(last_header.hash());
|
|
|
|
|
|
|
|
// forge block.
|
|
|
|
let mut b = OpenBlock::new(
|
2016-08-10 16:29:40 +02:00
|
|
|
test_engine,
|
2016-07-01 20:29:56 +02:00
|
|
|
Default::default(),
|
2016-06-16 12:44:08 +02:00
|
|
|
false,
|
|
|
|
db,
|
|
|
|
&last_header,
|
2016-08-03 22:03:40 +02:00
|
|
|
Arc::new(last_hashes.clone()),
|
2016-06-16 12:44:08 +02:00
|
|
|
author.clone(),
|
2016-06-23 14:43:20 +02:00
|
|
|
(3141562.into(), 31415620.into()),
|
2017-06-28 13:17:36 +02:00
|
|
|
vec![],
|
|
|
|
false,
|
2016-06-16 12:44:08 +02:00
|
|
|
).unwrap();
|
|
|
|
b.set_difficulty(U256::from(0x20000));
|
|
|
|
rolling_timestamp += 10;
|
|
|
|
b.set_timestamp(rolling_timestamp);
|
|
|
|
|
|
|
|
// first block we don't have any balance, so can't send any transactions.
|
|
|
|
for _ in 0..txs_per_block {
|
|
|
|
b.push_transaction(Transaction {
|
|
|
|
nonce: n.into(),
|
|
|
|
gas_price: tx_gas_prices[n % tx_gas_prices.len()],
|
|
|
|
gas: 100000.into(),
|
|
|
|
action: Action::Create,
|
|
|
|
data: vec![],
|
|
|
|
value: U256::zero(),
|
2017-08-21 13:46:58 +02:00
|
|
|
}.sign(kp.secret(), Some(test_spec.chain_id())), None).unwrap();
|
2016-06-16 12:44:08 +02:00
|
|
|
n += 1;
|
|
|
|
}
|
2016-01-27 13:23:24 +01:00
|
|
|
|
2016-08-10 16:29:40 +02:00
|
|
|
let b = b.close_and_lock().seal(test_engine, vec![]).unwrap();
|
2016-01-27 13:23:24 +01:00
|
|
|
|
2016-06-16 12:44:08 +02:00
|
|
|
if let Err(e) = client.import_block(b.rlp_bytes()) {
|
2016-03-02 15:06:53 +01:00
|
|
|
panic!("error importing block which is valid by definition: {:?}", e);
|
2016-01-27 13:23:24 +01:00
|
|
|
}
|
2016-06-18 15:11:10 +02:00
|
|
|
|
2016-06-16 12:44:08 +02:00
|
|
|
last_header = BlockView::new(&b.rlp_bytes()).header();
|
|
|
|
db = b.drain();
|
2016-01-27 11:50:48 +01:00
|
|
|
}
|
2016-01-27 13:23:24 +01:00
|
|
|
client.flush_queue();
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
2017-04-06 19:26:17 +02:00
|
|
|
client
|
2016-01-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2016-03-02 15:06:53 +01:00
|
|
|
pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting_number: usize, block_number: usize) {
|
|
|
|
let test_spec = get_test_spec();
|
2016-04-09 19:20:35 +02:00
|
|
|
let test_engine = &test_spec.engine;
|
|
|
|
//let test_engine = test_spec.to_engine().unwrap();
|
2016-08-29 11:35:24 +02:00
|
|
|
let state_root = test_spec.genesis_header().state_root().clone();
|
2016-03-02 15:06:53 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
for _ in 0..block_number {
|
|
|
|
let mut header = Header::new();
|
|
|
|
|
2016-08-29 11:35:24 +02:00
|
|
|
header.set_gas_limit(test_engine.params().min_gas_limit);
|
|
|
|
header.set_difficulty(U256::from(0x20000));
|
|
|
|
header.set_timestamp(rolling_timestamp);
|
|
|
|
header.set_number(rolling_block_number);
|
|
|
|
header.set_parent_hash(rolling_hash);
|
|
|
|
header.set_state_root(state_root);
|
2016-03-02 15:06:53 +01:00
|
|
|
|
|
|
|
rolling_hash = header.hash();
|
|
|
|
rolling_block_number = rolling_block_number + 1;
|
|
|
|
rolling_timestamp = rolling_timestamp + 10;
|
|
|
|
|
|
|
|
if let Err(e) = client.import_block(create_test_block(&header)) {
|
|
|
|
panic!("error importing block which is valid by definition: {:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> Arc<Client> {
|
2016-08-05 23:33:55 +02:00
|
|
|
let test_spec = get_test_spec();
|
2017-04-06 19:26:17 +02:00
|
|
|
let client_db = new_db();
|
2016-09-07 15:27:28 +02:00
|
|
|
|
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&test_spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
client_db,
|
2016-09-07 15:27:28 +02:00
|
|
|
Arc::new(Miner::with_spec(&test_spec)),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
|
|
|
|
2016-01-28 15:38:42 +01:00
|
|
|
for block in &blocks {
|
2016-11-28 13:20:49 +01:00
|
|
|
if client.import_block(block.clone()).is_err() {
|
2016-01-28 15:38:42 +01:00
|
|
|
panic!("panic importing block which is well-formed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.flush_queue();
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
2017-04-06 19:26:17 +02:00
|
|
|
client
|
2016-01-28 15:38:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
fn new_db() -> Arc<KeyValueDB> {
|
|
|
|
Arc::new(::util::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0)))
|
2016-07-28 23:46:24 +02:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_blockchain(block_number: u32) -> BlockChain {
|
|
|
|
let db = new_db();
|
2017-01-23 15:27:11 +01:00
|
|
|
let bc = BlockChain::new(BlockChainConfig::default(), &create_unverifiable_block(0, H256::zero()), db.clone());
|
2016-07-28 23:46:24 +02:00
|
|
|
|
2016-08-25 16:43:56 +02:00
|
|
|
let mut batch = db.transaction();
|
2016-01-27 18:31:14 +01:00
|
|
|
for block_order in 1..block_number {
|
2016-08-25 16:43:56 +02:00
|
|
|
bc.insert_block(&mut batch, &create_unverifiable_block(block_order, bc.best_block_hash()), vec![]);
|
2016-08-01 19:10:13 +02:00
|
|
|
bc.commit();
|
2016-01-27 18:31:14 +01:00
|
|
|
}
|
2016-07-28 23:46:24 +02:00
|
|
|
db.write(batch).unwrap();
|
2017-04-06 19:26:17 +02:00
|
|
|
bc
|
2016-01-28 12:24:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> BlockChain {
|
|
|
|
let db = new_db();
|
2017-01-23 15:27:11 +01:00
|
|
|
let bc = BlockChain::new(BlockChainConfig::default(), &create_unverifiable_block(0, H256::zero()), db.clone());
|
2016-07-28 23:46:24 +02:00
|
|
|
|
|
|
|
|
2016-08-25 16:43:56 +02:00
|
|
|
let mut batch = db.transaction();
|
2016-01-28 15:38:42 +01:00
|
|
|
for block_order in 1..block_number {
|
2016-08-25 16:43:56 +02:00
|
|
|
bc.insert_block(&mut batch, &create_unverifiable_block_with_extra(block_order, bc.best_block_hash(), None), vec![]);
|
2016-08-01 19:10:13 +02:00
|
|
|
bc.commit();
|
2016-01-28 15:38:42 +01:00
|
|
|
}
|
2016-07-28 23:46:24 +02:00
|
|
|
db.write(batch).unwrap();
|
2017-04-06 19:26:17 +02:00
|
|
|
bc
|
2016-01-28 15:38:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn generate_dummy_empty_blockchain() -> BlockChain {
|
|
|
|
let db = new_db();
|
2017-01-23 15:27:11 +01:00
|
|
|
let bc = BlockChain::new(BlockChainConfig::default(), &create_unverifiable_block(0, H256::zero()), db.clone());
|
2017-04-06 19:26:17 +02:00
|
|
|
bc
|
2016-01-28 19:14:07 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn get_temp_state() -> State<::state_db::StateDB> {
|
|
|
|
let journal_db = get_temp_state_db();
|
2017-04-12 13:33:49 +02:00
|
|
|
State::new(journal_db, U256::from(0), Default::default())
|
|
|
|
}
|
|
|
|
|
2017-05-30 11:52:33 +02:00
|
|
|
pub fn get_temp_state_with_factory(factory: EvmFactory) -> State<::state_db::StateDB> {
|
|
|
|
let journal_db = get_temp_state_db();
|
|
|
|
let mut factories = Factories::default();
|
|
|
|
factories.vm = factory;
|
|
|
|
State::new(journal_db, U256::from(0), factories)
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:26:17 +02:00
|
|
|
pub fn get_temp_state_db() -> StateDB {
|
|
|
|
let db = new_db();
|
2017-04-12 13:33:49 +02:00
|
|
|
let journal_db = journaldb::new(db, journaldb::Algorithm::EarlyMerge, ::db::COL_STATE);
|
|
|
|
StateDB::new(journal_db, 5 * 1024 * 1024)
|
|
|
|
}
|
|
|
|
|
2016-02-25 17:14:45 +01:00
|
|
|
pub fn get_good_dummy_block_seq(count: usize) -> Vec<Bytes> {
|
|
|
|
let test_spec = get_test_spec();
|
2017-04-06 19:26:17 +02:00
|
|
|
get_good_dummy_block_fork_seq(1, count, &test_spec.genesis_header().hash())
|
2016-03-02 15:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_hash: &H256) -> Vec<Bytes> {
|
|
|
|
let test_spec = get_test_spec();
|
2016-04-09 19:20:35 +02:00
|
|
|
let test_engine = &test_spec.engine;
|
2016-03-02 15:06:53 +01:00
|
|
|
let mut rolling_timestamp = start_number as u64 * 10;
|
|
|
|
let mut parent = *parent_hash;
|
2016-02-25 17:14:45 +01:00
|
|
|
let mut r = Vec::new();
|
2016-03-02 15:06:53 +01:00
|
|
|
for i in start_number .. start_number + count + 1 {
|
2016-02-25 17:14:45 +01:00
|
|
|
let mut block_header = Header::new();
|
2016-08-29 11:35:24 +02:00
|
|
|
block_header.set_gas_limit(test_engine.params().min_gas_limit);
|
2017-07-29 17:12:07 +02:00
|
|
|
block_header.set_difficulty(U256::from(i) * U256([0, 1, 0, 0]));
|
2016-08-29 11:35:24 +02:00
|
|
|
block_header.set_timestamp(rolling_timestamp);
|
|
|
|
block_header.set_number(i as u64);
|
|
|
|
block_header.set_parent_hash(parent);
|
|
|
|
block_header.set_state_root(test_spec.genesis_header().state_root().clone());
|
2016-03-02 15:06:53 +01:00
|
|
|
|
2016-02-25 17:14:45 +01:00
|
|
|
parent = block_header.hash();
|
2016-03-02 15:06:53 +01:00
|
|
|
rolling_timestamp = rolling_timestamp + 10;
|
|
|
|
|
2016-02-25 17:14:45 +01:00
|
|
|
r.push(create_test_block(&block_header));
|
|
|
|
}
|
|
|
|
r
|
|
|
|
}
|
|
|
|
|
2016-10-27 15:26:29 +02:00
|
|
|
pub fn get_good_dummy_block_hash() -> (H256, Bytes) {
|
2016-01-28 19:14:07 +01:00
|
|
|
let mut block_header = Header::new();
|
|
|
|
let test_spec = get_test_spec();
|
2016-04-09 19:20:35 +02:00
|
|
|
let test_engine = &test_spec.engine;
|
2016-08-29 11:35:24 +02:00
|
|
|
block_header.set_gas_limit(test_engine.params().min_gas_limit);
|
|
|
|
block_header.set_difficulty(U256::from(0x20000));
|
|
|
|
block_header.set_timestamp(40);
|
|
|
|
block_header.set_number(1);
|
|
|
|
block_header.set_parent_hash(test_spec.genesis_header().hash());
|
|
|
|
block_header.set_state_root(test_spec.genesis_header().state_root().clone());
|
2016-01-28 19:14:07 +01:00
|
|
|
|
2016-10-27 15:26:29 +02:00
|
|
|
(block_header.hash(), create_test_block(&block_header))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_good_dummy_block() -> Bytes {
|
|
|
|
let (_, bytes) = get_good_dummy_block_hash();
|
|
|
|
bytes
|
2016-01-28 19:14:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_bad_state_dummy_block() -> Bytes {
|
|
|
|
let mut block_header = Header::new();
|
|
|
|
let test_spec = get_test_spec();
|
2016-04-09 19:20:35 +02:00
|
|
|
let test_engine = &test_spec.engine;
|
2016-08-29 11:35:24 +02:00
|
|
|
block_header.set_gas_limit(test_engine.params().min_gas_limit);
|
|
|
|
block_header.set_difficulty(U256::from(0x20000));
|
|
|
|
block_header.set_timestamp(40);
|
|
|
|
block_header.set_number(1);
|
|
|
|
block_header.set_parent_hash(test_spec.genesis_header().hash());
|
|
|
|
block_header.set_state_root(0xbad.into());
|
2016-01-28 19:14:07 +01:00
|
|
|
|
|
|
|
create_test_block(&block_header)
|
|
|
|
}
|
2016-11-04 23:09:23 +01:00
|
|
|
|
2017-07-31 12:34:29 +02:00
|
|
|
pub fn get_default_ethash_params() -> EthashParams {
|
2016-11-04 23:09:23 +01:00
|
|
|
EthashParams {
|
|
|
|
minimum_difficulty: U256::from(131072),
|
|
|
|
difficulty_bound_divisor: U256::from(2048),
|
|
|
|
difficulty_increment_divisor: 10,
|
2017-03-27 11:42:40 +02:00
|
|
|
metropolis_difficulty_increment_divisor: 9,
|
2016-11-04 23:09:23 +01:00
|
|
|
duration_limit: 13,
|
|
|
|
homestead_transition: 1150000,
|
2016-11-11 13:01:47 +01:00
|
|
|
dao_hardfork_transition: u64::max_value(),
|
2016-11-04 23:09:23 +01:00
|
|
|
dao_hardfork_beneficiary: "0000000000000000000000000000000000000001".into(),
|
|
|
|
dao_hardfork_accounts: vec![],
|
2016-11-11 13:01:47 +01:00
|
|
|
difficulty_hardfork_transition: u64::max_value(),
|
2016-11-04 23:09:23 +01:00
|
|
|
difficulty_hardfork_bound_divisor: U256::from(0),
|
2016-11-11 13:01:47 +01:00
|
|
|
bomb_defuse_transition: u64::max_value(),
|
2017-03-27 11:42:40 +02:00
|
|
|
eip100b_transition: u64::max_value(),
|
2016-11-11 13:01:47 +01:00
|
|
|
eip150_transition: u64::max_value(),
|
|
|
|
eip160_transition: u64::max_value(),
|
|
|
|
eip161abc_transition: u64::max_value(),
|
|
|
|
eip161d_transition: u64::max_value(),
|
|
|
|
ecip1010_pause_transition: u64::max_value(),
|
|
|
|
ecip1010_continue_transition: u64::max_value(),
|
2017-06-19 18:56:37 +02:00
|
|
|
ecip1017_era_rounds: u64::max_value(),
|
2016-11-11 13:01:47 +01:00
|
|
|
max_code_size: u64::max_value(),
|
2017-02-24 17:34:32 +01:00
|
|
|
max_gas_limit_transition: u64::max_value(),
|
|
|
|
max_gas_limit: U256::max_value(),
|
|
|
|
min_gas_price_transition: u64::max_value(),
|
|
|
|
min_gas_price: U256::zero(),
|
2016-11-04 23:09:23 +01:00
|
|
|
}
|
|
|
|
}
|