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/>.
|
|
|
|
|
2016-08-05 10:32:04 +02:00
|
|
|
use io::IoChannel;
|
2016-12-09 23:01:43 +01:00
|
|
|
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId};
|
2017-03-08 14:39:44 +01:00
|
|
|
use state::{self, State, CleanupMode};
|
|
|
|
use executive::Executive;
|
2016-08-17 19:25:02 +02:00
|
|
|
use ethereum;
|
2016-03-02 00:34:38 +01:00
|
|
|
use block::IsBlock;
|
2016-02-02 22:50:41 +01:00
|
|
|
use tests::helpers::*;
|
2016-09-14 12:02:30 +02:00
|
|
|
use types::filter::Filter;
|
2016-10-24 18:35:25 +02:00
|
|
|
use util::*;
|
2016-02-19 15:18:20 +01:00
|
|
|
use devtools::*;
|
2016-05-31 22:24:32 +02:00
|
|
|
use miner::Miner;
|
2016-12-28 13:44:51 +01:00
|
|
|
use rlp::View;
|
2016-10-14 14:44:56 +02:00
|
|
|
use spec::Spec;
|
2016-10-24 18:35:25 +02:00
|
|
|
use views::BlockView;
|
2017-01-11 12:16:47 +01:00
|
|
|
use ethkey::{KeyPair, Secret};
|
2017-02-03 19:32:10 +01:00
|
|
|
use transaction::{PendingTransaction, Transaction, Action, Condition};
|
2016-12-16 13:27:14 +01:00
|
|
|
use miner::MinerService;
|
2016-01-26 11:39:49 +01:00
|
|
|
|
2016-01-26 14:33:22 +01:00
|
|
|
#[test]
|
|
|
|
fn imports_from_empty() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
2016-08-05 23:33:55 +02:00
|
|
|
let spec = get_test_spec();
|
2016-09-07 15:27:28 +02:00
|
|
|
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
2017-02-20 17:21:55 +01:00
|
|
|
let client_db = Arc::new(Database::open(&db_config, dir.as_path().to_str().unwrap()).unwrap());
|
2016-09-07 15:27:28 +02:00
|
|
|
|
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
client_db,
|
2016-09-07 15:27:28 +02:00
|
|
|
Arc::new(Miner::with_spec(&spec)),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
2016-01-26 14:33:22 +01:00
|
|
|
client.flush_queue();
|
|
|
|
}
|
|
|
|
|
2016-08-17 19:25:02 +02:00
|
|
|
#[test]
|
|
|
|
fn should_return_registrar() {
|
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let spec = ethereum::new_morden();
|
2016-09-07 15:27:28 +02:00
|
|
|
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
2017-02-20 17:21:55 +01:00
|
|
|
let client_db = Arc::new(Database::open(&db_config, dir.as_path().to_str().unwrap()).unwrap());
|
2016-09-07 15:27:28 +02:00
|
|
|
|
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
client_db,
|
2016-09-07 15:27:28 +02:00
|
|
|
Arc::new(Miner::with_spec(&spec)),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
2016-10-05 19:44:09 +02:00
|
|
|
let params = client.additional_params();
|
2016-11-28 13:20:49 +01:00
|
|
|
let address = ¶ms["registrar"];
|
2016-10-05 19:44:09 +02:00
|
|
|
|
|
|
|
assert_eq!(address.len(), 40);
|
|
|
|
assert!(U256::from_str(address).is_ok());
|
2016-08-17 19:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-03-11 20:24:44 +01:00
|
|
|
#[test]
|
|
|
|
fn returns_state_root_basic() {
|
|
|
|
let client_result = generate_dummy_client(6);
|
|
|
|
let client = client_result.reference();
|
|
|
|
let test_spec = get_test_spec();
|
2016-08-29 11:35:24 +02:00
|
|
|
let genesis_header = test_spec.genesis_header();
|
2016-03-11 20:24:44 +01:00
|
|
|
|
2016-08-29 11:35:24 +02:00
|
|
|
assert!(client.state_data(genesis_header.state_root()).is_some());
|
2016-03-11 20:24:44 +01:00
|
|
|
}
|
|
|
|
|
2016-01-26 14:33:22 +01:00
|
|
|
#[test]
|
|
|
|
fn imports_good_block() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
2016-08-05 23:33:55 +02:00
|
|
|
let spec = get_test_spec();
|
2016-09-07 15:27:28 +02:00
|
|
|
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
2017-02-20 17:21:55 +01:00
|
|
|
let client_db = Arc::new(Database::open(&db_config, dir.as_path().to_str().unwrap()).unwrap());
|
2016-09-07 15:27:28 +02:00
|
|
|
|
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
client_db,
|
2016-09-07 15:27:28 +02:00
|
|
|
Arc::new(Miner::with_spec(&spec)),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
2016-01-26 14:33:22 +01:00
|
|
|
let good_block = get_good_dummy_block();
|
2016-11-28 13:20:49 +01:00
|
|
|
if client.import_block(good_block).is_err() {
|
2016-01-26 14:33:22 +01:00
|
|
|
panic!("error importing block being good by definition");
|
|
|
|
}
|
|
|
|
client.flush_queue();
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
2016-01-26 14:33:22 +01:00
|
|
|
|
2016-12-09 23:01:43 +01:00
|
|
|
let block = client.block_header(BlockId::Number(1)).unwrap();
|
2016-12-28 13:44:51 +01:00
|
|
|
assert!(!block.into_inner().is_empty());
|
2016-01-26 14:33:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn query_none_block() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
2016-08-05 23:33:55 +02:00
|
|
|
let spec = get_test_spec();
|
2016-09-07 15:27:28 +02:00
|
|
|
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
2017-02-20 17:21:55 +01:00
|
|
|
let client_db = Arc::new(Database::open(&db_config, dir.as_path().to_str().unwrap()).unwrap());
|
2016-01-26 14:33:22 +01:00
|
|
|
|
2016-09-07 15:27:28 +02:00
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
client_db,
|
2016-09-07 15:27:28 +02:00
|
|
|
Arc::new(Miner::with_spec(&spec)),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
2016-12-09 23:01:43 +01:00
|
|
|
let non_existant = client.block_header(BlockId::Number(188));
|
2016-01-26 14:55:08 +01:00
|
|
|
assert!(non_existant.is_none());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn query_bad_block() {
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = get_test_client_with_blocks(vec![get_bad_state_dummy_block()]);
|
|
|
|
let client = client_result.reference();
|
2016-12-28 13:44:51 +01:00
|
|
|
let bad_block: Option<_> = client.block_header(BlockId::Number(1));
|
2016-01-26 14:55:08 +01:00
|
|
|
|
|
|
|
assert!(bad_block.is_none());
|
2016-01-26 18:05:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn returns_chain_info() {
|
|
|
|
let dummy_block = get_good_dummy_block();
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
|
|
|
let client = client_result.reference();
|
2016-01-26 18:05:25 +01:00
|
|
|
let block = BlockView::new(&dummy_block);
|
|
|
|
let info = client.chain_info();
|
|
|
|
assert_eq!(info.best_block_hash, block.header().hash());
|
2016-01-27 13:23:24 +01:00
|
|
|
}
|
|
|
|
|
2016-09-14 12:02:30 +02:00
|
|
|
#[test]
|
|
|
|
fn returns_logs() {
|
|
|
|
let dummy_block = get_good_dummy_block();
|
|
|
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
|
|
|
let client = client_result.reference();
|
|
|
|
let logs = client.logs(Filter {
|
2016-12-09 23:01:43 +01:00
|
|
|
from_block: BlockId::Earliest,
|
|
|
|
to_block: BlockId::Latest,
|
2016-09-14 12:02:30 +02:00
|
|
|
address: None,
|
|
|
|
topics: vec![],
|
2016-09-21 12:51:10 +02:00
|
|
|
limit: None,
|
|
|
|
});
|
2016-09-14 12:02:30 +02:00
|
|
|
assert_eq!(logs.len(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn returns_logs_with_limit() {
|
|
|
|
let dummy_block = get_good_dummy_block();
|
|
|
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
|
|
|
let client = client_result.reference();
|
|
|
|
let logs = client.logs(Filter {
|
2016-12-09 23:01:43 +01:00
|
|
|
from_block: BlockId::Earliest,
|
|
|
|
to_block: BlockId::Latest,
|
2016-09-14 12:02:30 +02:00
|
|
|
address: None,
|
|
|
|
topics: vec![],
|
2016-09-21 12:51:10 +02:00
|
|
|
limit: Some(2),
|
|
|
|
});
|
2016-09-14 12:02:30 +02:00
|
|
|
assert_eq!(logs.len(), 0);
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:07:46 +01:00
|
|
|
#[test]
|
|
|
|
fn returns_block_body() {
|
|
|
|
let dummy_block = get_good_dummy_block();
|
|
|
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
|
|
|
let client = client_result.reference();
|
|
|
|
let block = BlockView::new(&dummy_block);
|
2016-12-09 23:01:43 +01:00
|
|
|
let body = client.block_body(BlockId::Hash(block.header().hash())).unwrap();
|
2016-12-28 13:44:51 +01:00
|
|
|
let body = body.rlp();
|
2016-02-11 02:07:46 +01:00
|
|
|
assert_eq!(body.item_count(), 2);
|
|
|
|
assert_eq!(body.at(0).as_raw()[..], block.rlp().at(1).as_raw()[..]);
|
|
|
|
assert_eq!(body.at(1).as_raw()[..], block.rlp().at(2).as_raw()[..]);
|
|
|
|
}
|
|
|
|
|
2016-01-27 13:23:24 +01:00
|
|
|
#[test]
|
|
|
|
fn imports_block_sequence() {
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = generate_dummy_client(6);
|
|
|
|
let client = client_result.reference();
|
2016-12-09 23:01:43 +01:00
|
|
|
let block = client.block_header(BlockId::Number(5)).unwrap();
|
2016-01-27 13:23:24 +01:00
|
|
|
|
2016-12-28 13:44:51 +01:00
|
|
|
assert!(!block.into_inner().is_empty());
|
2016-01-27 13:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_collect_garbage() {
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = generate_dummy_client(100);
|
|
|
|
let client = client_result.reference();
|
2016-01-27 13:23:24 +01:00
|
|
|
client.tick();
|
2016-02-25 14:09:39 +01:00
|
|
|
assert!(client.blockchain_cache_info().blocks < 100 * 1024);
|
2016-02-02 22:50:41 +01:00
|
|
|
}
|
2016-03-02 15:06:53 +01:00
|
|
|
|
2016-10-31 12:57:48 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_generate_gas_price_median() {
|
2016-11-28 13:20:49 +01:00
|
|
|
let client_result = generate_dummy_client_with_data(3, 1, slice_into![1, 2, 3]);
|
2016-10-31 12:57:48 +01:00
|
|
|
let client = client_result.reference();
|
2017-02-17 16:18:31 +01:00
|
|
|
assert_eq!(Some(&U256::from(2)), client.gas_price_corpus(3).median());
|
2016-10-31 12:57:48 +01:00
|
|
|
|
2016-11-28 13:20:49 +01:00
|
|
|
let client_result = generate_dummy_client_with_data(4, 1, slice_into![1, 4, 3, 2]);
|
2016-10-31 12:57:48 +01:00
|
|
|
let client = client_result.reference();
|
2017-02-17 16:18:31 +01:00
|
|
|
assert_eq!(Some(&U256::from(3)), client.gas_price_corpus(3).median());
|
2016-10-31 12:57:48 +01:00
|
|
|
}
|
|
|
|
|
2016-06-16 12:44:08 +02:00
|
|
|
#[test]
|
2016-10-31 12:57:48 +01:00
|
|
|
fn can_generate_gas_price_histogram() {
|
2016-11-28 13:20:49 +01:00
|
|
|
let client_result = generate_dummy_client_with_data(20, 1, slice_into![6354,8593,6065,4842,7845,7002,689,4958,4250,6098,5804,4320,643,8895,2296,8589,7145,2000,2512,1408]);
|
2016-06-16 12:44:08 +02:00
|
|
|
let client = client_result.reference();
|
2016-10-31 12:57:48 +01:00
|
|
|
|
2017-02-17 16:18:31 +01:00
|
|
|
let hist = client.gas_price_corpus(20).histogram(5).unwrap();
|
|
|
|
let correct_hist = ::stats::Histogram { bucket_bounds: vec_into![643, 2294, 3945, 5596, 7247, 8898], counts: vec![4,2,4,6,4] };
|
2016-10-31 12:57:48 +01:00
|
|
|
assert_eq!(hist, correct_hist);
|
2016-06-16 12:44:08 +02:00
|
|
|
}
|
|
|
|
|
2016-10-31 12:57:48 +01:00
|
|
|
#[test]
|
|
|
|
fn empty_gas_price_histogram() {
|
2016-11-28 13:20:49 +01:00
|
|
|
let client_result = generate_dummy_client_with_data(20, 0, slice_into![]);
|
2016-10-31 12:57:48 +01:00
|
|
|
let client = client_result.reference();
|
|
|
|
|
2017-02-17 16:18:31 +01:00
|
|
|
assert!(client.gas_price_corpus(20).histogram(5).is_none());
|
2016-10-31 12:57:48 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 08:55:56 +01:00
|
|
|
#[test]
|
|
|
|
fn corpus_is_sorted() {
|
|
|
|
let client_result = generate_dummy_client_with_data(2, 1, slice_into![U256::from_str("11426908979").unwrap(), U256::from_str("50426908979").unwrap()]);
|
|
|
|
let client = client_result.reference();
|
|
|
|
let corpus = client.gas_price_corpus(20);
|
|
|
|
assert!(corpus[0] < corpus[1]);
|
|
|
|
}
|
2016-10-31 12:57:48 +01:00
|
|
|
|
2016-03-02 15:06:53 +01:00
|
|
|
#[test]
|
|
|
|
fn can_handle_long_fork() {
|
|
|
|
let client_result = generate_dummy_client(1200);
|
|
|
|
let client = client_result.reference();
|
2016-05-27 18:57:12 +02:00
|
|
|
for _ in 0..20 {
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
2016-03-02 15:06:53 +01:00
|
|
|
}
|
|
|
|
assert_eq!(1200, client.chain_info().best_block_number);
|
|
|
|
|
|
|
|
push_blocks_to_client(client, 45, 1201, 800);
|
|
|
|
push_blocks_to_client(client, 49, 1201, 800);
|
|
|
|
push_blocks_to_client(client, 53, 1201, 600);
|
|
|
|
|
2016-10-20 14:49:12 +02:00
|
|
|
for _ in 0..400 {
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
2016-03-02 15:06:53 +01:00
|
|
|
}
|
|
|
|
assert_eq!(2000, client.chain_info().best_block_number);
|
|
|
|
}
|
2016-03-02 15:15:09 +01:00
|
|
|
|
2016-03-02 00:34:38 +01:00
|
|
|
#[test]
|
|
|
|
fn can_mine() {
|
|
|
|
let dummy_blocks = get_good_dummy_block_seq(2);
|
|
|
|
let client_result = get_test_client_with_blocks(vec![dummy_blocks[0].clone()]);
|
|
|
|
let client = client_result.reference();
|
2016-03-08 16:23:32 +01:00
|
|
|
|
2016-06-23 14:43:20 +02:00
|
|
|
let b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).close();
|
2016-03-08 16:23:32 +01:00
|
|
|
|
|
|
|
assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().sha3());
|
2016-03-02 15:15:09 +01:00
|
|
|
}
|
2016-10-14 14:44:56 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn change_history_size() {
|
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let test_spec = Spec::new_null();
|
|
|
|
let mut config = ClientConfig::default();
|
|
|
|
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
2017-02-20 17:21:55 +01:00
|
|
|
let client_db = Arc::new(Database::open(&db_config, dir.as_path().to_str().unwrap()).unwrap());
|
|
|
|
|
2016-10-14 14:44:56 +02:00
|
|
|
config.history = 2;
|
|
|
|
let address = Address::random();
|
|
|
|
{
|
2017-02-20 17:21:55 +01:00
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&test_spec,
|
|
|
|
client_db.clone(),
|
|
|
|
Arc::new(Miner::with_spec(&test_spec)),
|
|
|
|
IoChannel::disconnected()
|
|
|
|
).unwrap();
|
|
|
|
|
2016-10-14 14:44:56 +02:00
|
|
|
for _ in 0..20 {
|
|
|
|
let mut b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]);
|
2017-02-26 13:10:50 +01:00
|
|
|
b.block_mut().fields_mut().state.add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap();
|
2016-10-14 14:44:56 +02:00
|
|
|
b.block_mut().fields_mut().state.commit().unwrap();
|
|
|
|
let b = b.close_and_lock().seal(&*test_spec.engine, vec![]).unwrap();
|
|
|
|
client.import_sealed_block(b).unwrap(); // account change is in the journal overlay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut config = ClientConfig::default();
|
|
|
|
config.history = 10;
|
2017-02-20 17:21:55 +01:00
|
|
|
let client = Client::new(
|
|
|
|
config,
|
|
|
|
&test_spec,
|
|
|
|
client_db,
|
|
|
|
Arc::new(Miner::with_spec(&test_spec)),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
).unwrap();
|
2017-02-26 13:10:50 +01:00
|
|
|
assert_eq!(client.state().balance(&address).unwrap(), 100.into());
|
2016-10-14 14:44:56 +02:00
|
|
|
}
|
2016-12-16 13:27:14 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_propagate_delayed_transactions() {
|
2017-01-11 12:16:47 +01:00
|
|
|
let key = KeyPair::from_secret(Secret::from_slice(&"test".sha3()).unwrap()).unwrap();
|
2016-12-16 13:27:14 +01:00
|
|
|
let secret = key.secret();
|
|
|
|
let tx0 = PendingTransaction::new(Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 21000.into(),
|
|
|
|
action: Action::Call(Address::default()),
|
|
|
|
value: 0.into(),
|
|
|
|
data: Vec::new(),
|
2017-02-03 19:32:10 +01:00
|
|
|
}.sign(secret, None), Some(Condition::Number(2)));
|
2016-12-16 13:27:14 +01:00
|
|
|
let tx1 = PendingTransaction::new(Transaction {
|
|
|
|
nonce: 1.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 21000.into(),
|
|
|
|
action: Action::Call(Address::default()),
|
|
|
|
value: 0.into(),
|
|
|
|
data: Vec::new(),
|
|
|
|
}.sign(secret, None), None);
|
|
|
|
let client_result = generate_dummy_client(1);
|
|
|
|
let client = client_result.reference();
|
|
|
|
|
|
|
|
client.miner().import_own_transaction(&**client, tx0).unwrap();
|
|
|
|
client.miner().import_own_transaction(&**client, tx1).unwrap();
|
2016-12-16 14:54:26 +01:00
|
|
|
assert_eq!(0, client.ready_transactions().len());
|
|
|
|
assert_eq!(2, client.miner().pending_transactions().len());
|
|
|
|
push_blocks_to_client(client, 53, 2, 2);
|
2016-12-17 12:28:31 +01:00
|
|
|
client.flush_queue();
|
2016-12-16 14:54:26 +01:00
|
|
|
assert_eq!(2, client.ready_transactions().len());
|
|
|
|
assert_eq!(2, client.miner().pending_transactions().len());
|
2016-12-16 13:27:14 +01:00
|
|
|
}
|
2017-03-08 14:39:44 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn transaction_proof() {
|
|
|
|
use ::client::ProvingBlockChainClient;
|
|
|
|
|
|
|
|
let client_result = generate_dummy_client(0);
|
|
|
|
let client = client_result.reference();
|
|
|
|
let address = Address::random();
|
|
|
|
let test_spec = Spec::new_test();
|
|
|
|
for _ in 0..20 {
|
|
|
|
let mut b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]);
|
|
|
|
b.block_mut().fields_mut().state.add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap();
|
|
|
|
b.block_mut().fields_mut().state.commit().unwrap();
|
|
|
|
let b = b.close_and_lock().seal(&*test_spec.engine, vec![]).unwrap();
|
|
|
|
client.import_sealed_block(b).unwrap(); // account change is in the journal overlay
|
|
|
|
}
|
|
|
|
|
|
|
|
let transaction = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 21000.into(),
|
|
|
|
action: Action::Call(Address::default()),
|
|
|
|
value: 5.into(),
|
|
|
|
data: Vec::new(),
|
|
|
|
}.fake_sign(address);
|
|
|
|
|
|
|
|
let proof = client.prove_transaction(transaction.clone(), BlockId::Latest).unwrap();
|
|
|
|
let backend = state::backend::ProofCheck::new(&proof);
|
|
|
|
|
|
|
|
let mut factories = ::factory::Factories::default();
|
|
|
|
factories.accountdb = ::account_db::Factory::Plain; // raw state values, no mangled keys.
|
|
|
|
let root = client.best_block_header().state_root();
|
|
|
|
|
|
|
|
let mut state = State::from_existing(backend, root, 0.into(), factories.clone()).unwrap();
|
|
|
|
Executive::new(&mut state, &client.latest_env_info(), &*test_spec.engine, &factories.vm)
|
|
|
|
.transact(&transaction, Default::default()).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(state.balance(&Address::default()).unwrap(), 5.into());
|
|
|
|
assert_eq!(state.balance(&address).unwrap(), 95.into());
|
|
|
|
}
|