Private transactions integration pr (#6422)
* Private transaction message added * Empty line removed * Private transactions logic removed from client into the separate module * Fixed compilation after merge with head * Signed private transaction message added as well * Comments after the review fixed * Private tx execution * Test update * Renamed some methods * Fixed some tests * Reverted submodules * Fixed build * Private transaction message added * Empty line removed * Private transactions logic removed from client into the separate module * Fixed compilation after merge with head * Signed private transaction message added as well * Comments after the review fixed * Encrypted private transaction message and signed reply added * Private tx execution * Test update * Main scenario completed * Merged with the latest head * Private transactions API * Comments after review fixed * Parameters for private transactions added to parity arguments * New files added * New API methods added * Do not process packets from unconfirmed peers * Merge with ptm_ss branch * Encryption and permissioning with key server added * Fixed compilation after merge * Version of Parity protocol incremented in order to support private transactions * Doc strings for constants added * Proper format for doc string added * fixed some encryptor.rs grumbles * Private transactions functionality moved to the separate crate * Refactoring in order to remove late initialisation * Tests fixed after moving to the separate crate * Fetch method removed * Sync test helpers refactored * Interaction with encryptor refactored * Contract address retrieving via substate removed * Sensible gas limit for private transactions implemented * New private contract with nonces added * Parsing of the response from key server fixed * Build fixed after the merge, native contracts removed * Crate renamed * Tests moved to the separate directory * Handling of errors reworked in order to use error chain * Encodable macro added, new constructor replaced with default * Native ethabi usage removed * Couple conversions optimized * Interactions with client reworked * Errors omitting removed * Fix after merge * Fix after the merge * private transactions improvements in progress * private_transactions -> ethcore/private-tx * making private transactions more idiomatic * private-tx encryptor uses shared FetchClient and is more idiomatic * removed redundant tests, moved integration tests to tests/ dir * fixed failing service test * reenable add_notify on private tx provider * removed private_tx tests from sync module * removed commented out code * Use plain password instead of unlocking account manager * remove dead code * Link to the contract changed * Transaction signature chain replay protection module created * Redundant type conversion removed * Contract address returned by private provider * Test fixed * Addressing grumbles in PrivateTransactions (#8249) * Tiny fixes part 1. * A bunch of additional comments and todos. * Fix ethsync tests. * resolved merge conflicts * final private tx pr (#8318) * added cli option that enables private transactions * fixed failing test * fixed failing test * fixed failing test * fixed failing test
This commit is contained in:
committed by
Marek Kotewicz
parent
c039ab79b5
commit
e6f75bccfe
@@ -645,7 +645,7 @@ pub fn enact_verified(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use super::*;
|
||||
use engines::EthEngine;
|
||||
use vm::LastHashes;
|
||||
|
||||
@@ -1421,7 +1421,7 @@ mod tests {
|
||||
use ethereum_types::*;
|
||||
use receipt::{Receipt, TransactionOutcome};
|
||||
use blockchain::{BlockProvider, BlockChain, Config, ImportRoute};
|
||||
use tests::helpers::{
|
||||
use test_helpers::{
|
||||
generate_dummy_blockchain, generate_dummy_blockchain_with_extra,
|
||||
generate_dummy_empty_blockchain
|
||||
};
|
||||
|
||||
@@ -17,6 +17,16 @@
|
||||
use ethereum_types::H256;
|
||||
use bytes::Bytes;
|
||||
|
||||
/// Messages to broadcast via chain
|
||||
pub enum ChainMessageType {
|
||||
/// Consensus message
|
||||
Consensus(Vec<u8>),
|
||||
/// Message with private transaction
|
||||
PrivateTransaction(Vec<u8>),
|
||||
/// Message with signed private transaction
|
||||
SignedPrivateTransaction(Vec<u8>),
|
||||
}
|
||||
|
||||
/// Represents what has to be handled by actor listening to chain events
|
||||
pub trait ChainNotify : Send + Sync {
|
||||
/// fires when chain has new blocks.
|
||||
@@ -45,7 +55,7 @@ pub trait ChainNotify : Send + Sync {
|
||||
}
|
||||
|
||||
/// fires when chain broadcasts a message
|
||||
fn broadcast(&self, _data: Vec<u8>) {}
|
||||
fn broadcast(&self, _message_type: ChainMessageType) {}
|
||||
|
||||
/// fires when new transactions are received from a peer
|
||||
fn transactions_received(&self,
|
||||
|
||||
@@ -45,7 +45,7 @@ use client::{
|
||||
use client::{
|
||||
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
|
||||
MiningBlockChainClient, TraceFilter, CallAnalytics, BlockImportError, Mode,
|
||||
ChainNotify, PruningInfo, ProvingBlockChainClient, EngineInfo
|
||||
ChainNotify, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType
|
||||
};
|
||||
use encoded;
|
||||
use engines::{EthEngine, EpochTransition};
|
||||
@@ -2126,7 +2126,7 @@ impl super::traits::EngineClient for Client {
|
||||
}
|
||||
|
||||
fn broadcast_consensus_message(&self, message: Bytes) {
|
||||
self.notify(|notify| notify.broadcast(message.clone()));
|
||||
self.notify(|notify| notify.broadcast(ChainMessageType::Consensus(message.clone())));
|
||||
}
|
||||
|
||||
fn epoch_transition_for(&self, parent_hash: H256) -> Option<::engines::EpochTransition> {
|
||||
@@ -2237,7 +2237,7 @@ mod tests {
|
||||
#[test]
|
||||
fn should_not_cache_details_before_commit() {
|
||||
use client::{BlockChainClient, ChainInfo};
|
||||
use tests::helpers::{generate_dummy_client, get_good_dummy_block_hash};
|
||||
use test_helpers::{generate_dummy_client, get_good_dummy_block_hash};
|
||||
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -36,6 +36,8 @@ pub enum ClientIoMessage {
|
||||
/// Take a snapshot for the block with given number.
|
||||
TakeSnapshot(u64),
|
||||
/// New consensus message received.
|
||||
NewMessage(Bytes)
|
||||
NewMessage(Bytes),
|
||||
/// New private transaction arrived
|
||||
NewPrivateTransaction,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,12 @@ pub use self::error::Error;
|
||||
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult};
|
||||
pub use self::io_message::ClientIoMessage;
|
||||
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
|
||||
pub use self::chain_notify::ChainNotify;
|
||||
pub use self::chain_notify::{ChainNotify, ChainMessageType};
|
||||
pub use self::traits::{
|
||||
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, CallContract, TransactionInfo, RegistryInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
|
||||
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter
|
||||
};
|
||||
//pub use self::private_notify::PrivateNotify;
|
||||
pub use state::StateInfo;
|
||||
pub use self::traits::{BlockChainClient, MiningBlockChainClient, EngineClient, ProvingBlockChainClient};
|
||||
|
||||
@@ -53,3 +54,4 @@ pub use verification::VerifierType;
|
||||
mod traits;
|
||||
|
||||
mod chain_notify;
|
||||
mod private_notify;
|
||||
|
||||
23
ethcore/src/client/private_notify.rs
Normal file
23
ethcore/src/client/private_notify.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||
// 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/>.
|
||||
|
||||
use error::TransactionImportError;
|
||||
|
||||
/// Represent private transactions handler inside the client
|
||||
pub trait PrivateNotify : Send + Sync {
|
||||
/// fires when private transaction message queued via client io queue
|
||||
fn private_transaction_queued(&self) -> Result<(), TransactionImportError>;
|
||||
}
|
||||
@@ -1326,7 +1326,7 @@ mod tests {
|
||||
use header::Header;
|
||||
use rlp::encode;
|
||||
use block::*;
|
||||
use tests::helpers::{
|
||||
use test_helpers::{
|
||||
generate_dummy_client_with_spec_and_accounts, get_temp_state_db, generate_dummy_client,
|
||||
TestNotify
|
||||
};
|
||||
|
||||
@@ -199,7 +199,7 @@ mod tests {
|
||||
use hash::keccak;
|
||||
use ethereum_types::H520;
|
||||
use block::*;
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use account_provider::AccountProvider;
|
||||
use header::Header;
|
||||
use spec::Spec;
|
||||
|
||||
@@ -67,7 +67,7 @@ impl<M: Machine> Engine<M> for InstantSeal<M>
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use ethereum_types::{H520, Address};
|
||||
use tests::helpers::{get_temp_state_db};
|
||||
use test_helpers::get_temp_state_db;
|
||||
use spec::Spec;
|
||||
use header::Header;
|
||||
use block::*;
|
||||
|
||||
@@ -514,7 +514,6 @@ impl Engine<EthereumMachine> for Tendermint {
|
||||
fn fmt_err<T: ::std::fmt::Debug>(x: T) -> EngineError {
|
||||
EngineError::MalformedMessage(format!("{:?}", x))
|
||||
}
|
||||
|
||||
let rlp = UntrustedRlp::new(rlp);
|
||||
let message: ConsensusMessage = rlp.as_val().map_err(fmt_err)?;
|
||||
if !self.votes.is_old_or_known(&message) {
|
||||
@@ -783,7 +782,7 @@ mod tests {
|
||||
use header::Header;
|
||||
use client::ChainInfo;
|
||||
use miner::MinerService;
|
||||
use tests::helpers::{
|
||||
use test_helpers::{
|
||||
TestNotify, get_temp_state_db, generate_dummy_client,
|
||||
generate_dummy_client_with_spec_and_accounts
|
||||
};
|
||||
|
||||
@@ -145,8 +145,8 @@ mod tests {
|
||||
use account_provider::AccountProvider;
|
||||
use miner::MinerService;
|
||||
use types::ids::BlockId;
|
||||
use test_helpers::generate_dummy_client_with_spec_and_accounts;
|
||||
use client::{BlockChainClient, ChainInfo, BlockInfo, CallContract};
|
||||
use tests::helpers::generate_dummy_client_with_spec_and_accounts;
|
||||
use super::super::ValidatorSet;
|
||||
use super::ValidatorContract;
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ mod tests {
|
||||
use header::Header;
|
||||
use miner::MinerService;
|
||||
use spec::Spec;
|
||||
use tests::helpers::{generate_dummy_client_with_spec_and_accounts, generate_dummy_client_with_spec_and_data};
|
||||
use test_helpers::{generate_dummy_client_with_spec_and_accounts, generate_dummy_client_with_spec_and_data};
|
||||
use types::ids::BlockId;
|
||||
use ethereum_types::Address;
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ mod tests {
|
||||
use client::{ChainInfo, BlockInfo, ImportBlock};
|
||||
use ethkey::Secret;
|
||||
use miner::MinerService;
|
||||
use tests::helpers::{generate_dummy_client_with_spec_and_accounts, generate_dummy_client_with_spec_and_data};
|
||||
use test_helpers::{generate_dummy_client_with_spec_and_accounts, generate_dummy_client_with_spec_and_data};
|
||||
use super::super::ValidatorSet;
|
||||
use super::{ValidatorSafeContract, EVENT_NAME_HASH};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! General error types for use in ethcore.
|
||||
|
||||
use std::fmt;
|
||||
use std::{fmt, error};
|
||||
use kvdb;
|
||||
use ethereum_types::{H256, U256, Address, Bloom};
|
||||
use util_error::UtilError;
|
||||
@@ -268,6 +268,13 @@ impl fmt::Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
// improve description
|
||||
"ethcore error"
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of import block operation.
|
||||
pub type ImportResult = Result<H256, Error>;
|
||||
|
||||
|
||||
@@ -487,7 +487,7 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
use ethereum_types::{H64, H256, U256, Address};
|
||||
use block::*;
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use error::{BlockError, Error};
|
||||
use header::Header;
|
||||
use spec::Spec;
|
||||
|
||||
@@ -145,7 +145,7 @@ mod tests {
|
||||
use ethereum_types::U256;
|
||||
use state::*;
|
||||
use super::*;
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use views::BlockView;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -701,7 +701,7 @@ mod tests {
|
||||
use error::ExecutionError;
|
||||
use machine::EthereumMachine;
|
||||
use state::{Substate, CleanupMode};
|
||||
use tests::helpers::{get_temp_state_with_factory, get_temp_state};
|
||||
use test_helpers::{get_temp_state_with_factory, get_temp_state};
|
||||
use trace::trace;
|
||||
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer};
|
||||
use trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, VMTracer, NoopVMTracer, ExecutiveVMTracer};
|
||||
@@ -746,7 +746,6 @@ mod tests {
|
||||
assert_eq!(state.storage_at(&address, &H256::new()).unwrap(), H256::from(&U256::from(0xf9u64)));
|
||||
assert_eq!(state.balance(&sender).unwrap(), U256::from(0xf9));
|
||||
assert_eq!(state.balance(&address).unwrap(), U256::from(0x7));
|
||||
// 0 cause contract hasn't returned
|
||||
assert_eq!(substate.contracts_created.len(), 0);
|
||||
|
||||
// TODO: just test state root.
|
||||
|
||||
@@ -414,7 +414,7 @@ mod tests {
|
||||
use ethereum_types::{U256, Address};
|
||||
use evm::{EnvInfo, Ext, CallType};
|
||||
use state::{State, Substate};
|
||||
use tests::helpers::get_temp_state;
|
||||
use test_helpers::get_temp_state;
|
||||
use super::*;
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ use vm::{
|
||||
CreateContractAddress, ReturnData,
|
||||
};
|
||||
use externalities::*;
|
||||
use tests::helpers::get_temp_state;
|
||||
use test_helpers::get_temp_state;
|
||||
use ethjson;
|
||||
use trace::{Tracer, NoopTracer};
|
||||
use trace::{VMTracer, NoopVMTracer};
|
||||
|
||||
@@ -94,6 +94,7 @@ extern crate ansi_term;
|
||||
extern crate unexpected;
|
||||
extern crate kvdb;
|
||||
extern crate kvdb_memorydb;
|
||||
extern crate kvdb_rocksdb;
|
||||
extern crate util_error;
|
||||
extern crate snappy;
|
||||
|
||||
@@ -128,9 +129,6 @@ extern crate trace_time;
|
||||
#[cfg_attr(test, macro_use)]
|
||||
extern crate evm;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate kvdb_rocksdb;
|
||||
|
||||
pub extern crate ethstore;
|
||||
|
||||
pub mod account_provider;
|
||||
@@ -142,6 +140,7 @@ pub mod engines;
|
||||
pub mod error;
|
||||
pub mod ethereum;
|
||||
pub mod executed;
|
||||
pub mod executive;
|
||||
pub mod header;
|
||||
pub mod machine;
|
||||
pub mod miner;
|
||||
@@ -150,6 +149,8 @@ pub mod snapshot;
|
||||
pub mod spec;
|
||||
pub mod state;
|
||||
pub mod state_db;
|
||||
// Test helpers made public for usage outside ethcore
|
||||
pub mod test_helpers;
|
||||
pub mod trace;
|
||||
pub mod verification;
|
||||
pub mod views;
|
||||
@@ -159,7 +160,6 @@ mod blooms;
|
||||
mod pod_account;
|
||||
mod account_db;
|
||||
mod builtin;
|
||||
mod executive;
|
||||
mod externalities;
|
||||
mod blockchain;
|
||||
mod factory;
|
||||
|
||||
@@ -24,7 +24,7 @@ use ethereum_types::{H256, U256, Address};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use bytes::Bytes;
|
||||
use engines::{EthEngine, Seal};
|
||||
use error::*;
|
||||
use error::{ExecutionError, Error};
|
||||
use ethcore_miner::banning_queue::{BanningTransactionQueue, Threshold};
|
||||
use ethcore_miner::local_transactions::{Status as LocalTransactionStatus};
|
||||
use ethcore_miner::transaction_queue::{
|
||||
@@ -1327,8 +1327,7 @@ mod tests {
|
||||
use spec::Spec;
|
||||
use transaction::{SignedTransaction, Transaction, PendingTransaction, Action};
|
||||
use miner::MinerService;
|
||||
|
||||
use tests::helpers::{generate_dummy_client, generate_dummy_client_with_spec_and_accounts};
|
||||
use test_helpers::{generate_dummy_client, generate_dummy_client_with_spec_and_accounts};
|
||||
|
||||
#[test]
|
||||
fn should_prepare_block_to_seal() {
|
||||
|
||||
@@ -210,7 +210,7 @@ pub fn from_fat_rlp(
|
||||
mod tests {
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use basic_account::BasicAccount;
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use snapshot::tests::helpers::fill_storage;
|
||||
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||
|
||||
@@ -635,7 +635,7 @@ mod tests {
|
||||
use snapshot::{ManifestData, RestorationStatus, SnapshotService};
|
||||
use super::*;
|
||||
use tempdir::TempDir;
|
||||
use tests::helpers::restoration_db_handler;
|
||||
use test_helpers::restoration_db_handler;
|
||||
|
||||
struct NoopDBRestore;
|
||||
impl DatabaseRestore for NoopDBRestore {
|
||||
|
||||
@@ -25,7 +25,7 @@ use client::{Client, BlockChainClient, ChainInfo};
|
||||
use ethkey::Secret;
|
||||
use snapshot::tests::helpers as snapshot_helpers;
|
||||
use spec::Spec;
|
||||
use tests::helpers;
|
||||
use test_helpers::generate_dummy_client_with_spec_and_accounts;
|
||||
use transaction::{Transaction, Action, SignedTransaction};
|
||||
use tempdir::TempDir;
|
||||
|
||||
@@ -89,7 +89,7 @@ enum Transition {
|
||||
|
||||
// create a chain with the given transitions and some blocks beyond that transition.
|
||||
fn make_chain(accounts: Arc<AccountProvider>, blocks_beyond: usize, transitions: Vec<Transition>) -> Arc<Client> {
|
||||
let client = helpers::generate_dummy_client_with_spec_and_accounts(
|
||||
let client = generate_dummy_client_with_spec_and_accounts(
|
||||
spec_fixed_to_contract, Some(accounts.clone()));
|
||||
|
||||
let mut cur_signers = vec![*RICH_ADDR];
|
||||
|
||||
@@ -24,7 +24,7 @@ use ids::BlockId;
|
||||
use snapshot::service::{Service, ServiceParams};
|
||||
use snapshot::{self, ManifestData, SnapshotService};
|
||||
use spec::Spec;
|
||||
use tests::helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler};
|
||||
use test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler};
|
||||
|
||||
use io::IoChannel;
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
|
||||
@@ -892,7 +892,7 @@ impl Spec {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use state::State;
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use views::BlockView;
|
||||
use tempdir::TempDir;
|
||||
|
||||
|
||||
@@ -180,6 +180,16 @@ impl Account {
|
||||
self.init_code(code);
|
||||
}
|
||||
|
||||
/// Reset this account's code and storage to given values.
|
||||
pub fn reset_code_and_storage(&mut self, code: Arc<Bytes>, storage: HashMap<H256, H256>) {
|
||||
self.code_hash = keccak(&*code);
|
||||
self.code_cache = code;
|
||||
self.code_size = Some(self.code_cache.len());
|
||||
self.code_filth = Filth::Dirty;
|
||||
self.storage_cache = Self::empty_storage_cache();
|
||||
self.storage_changes = storage;
|
||||
}
|
||||
|
||||
/// Set (and cache) the contents of the trie's storage at `key` to `value`.
|
||||
pub fn set_storage(&mut self, key: H256, value: H256) {
|
||||
self.storage_changes.insert(key, value);
|
||||
|
||||
@@ -494,6 +494,13 @@ impl<B: Backend> State<B> {
|
||||
(self.root, self.db)
|
||||
}
|
||||
|
||||
/// Destroy the current object and return single account data.
|
||||
pub fn into_account(self, account: &Address) -> trie::Result<(Option<Arc<Bytes>>, HashMap<H256, H256>)> {
|
||||
// TODO: deconstruct without cloning.
|
||||
let account = self.require(account, true)?;
|
||||
Ok((account.code().clone(), account.storage_changes().clone()))
|
||||
}
|
||||
|
||||
/// Return reference to root
|
||||
pub fn root(&self) -> &H256 {
|
||||
&self.root
|
||||
@@ -1014,6 +1021,11 @@ impl<B: Backend> State<B> {
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/// Replace account code and storage. Creates account if it does not exist.
|
||||
pub fn patch_account(&self, a: &Address, code: Arc<Bytes>, storage: HashMap<H256, H256>) -> trie::Result<()> {
|
||||
Ok(self.require(a, false)?.reset_code_and_storage(code, storage))
|
||||
}
|
||||
}
|
||||
|
||||
// State proof implementations; useful for light client protocols.
|
||||
@@ -1099,7 +1111,7 @@ mod tests {
|
||||
use super::*;
|
||||
use ethkey::Secret;
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use tests::helpers::{get_temp_state, get_temp_state_db};
|
||||
use test_helpers::{get_temp_state, get_temp_state_db};
|
||||
use machine::EthereumMachine;
|
||||
use vm::EnvInfo;
|
||||
use spec::*;
|
||||
|
||||
@@ -480,7 +480,7 @@ unsafe impl Sync for SyncAccount {}
|
||||
mod tests {
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use kvdb::DBTransaction;
|
||||
use tests::helpers::{get_temp_state_db};
|
||||
use test_helpers::get_temp_state_db;
|
||||
use state::{Account, Backend};
|
||||
use ethcore_logger::init_log;
|
||||
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Set of different helpers for client tests
|
||||
|
||||
use account_provider::AccountProvider;
|
||||
use ethereum_types::{H256, U256};
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use block::{OpenBlock, Drain};
|
||||
use blockchain::{BlockChain, Config as BlockChainConfig};
|
||||
use bytes::Bytes;
|
||||
use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify};
|
||||
use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock};
|
||||
use ethkey::KeyPair;
|
||||
use evm::Factory as EvmFactory;
|
||||
use factory::Factories;
|
||||
@@ -39,6 +41,7 @@ use views::BlockView;
|
||||
use kvdb::{KeyValueDB, KeyValueDBHandler};
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
|
||||
/// Creates test block with corresponding header
|
||||
pub fn create_test_block(header: &Header) -> Bytes {
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
rlp.append(header);
|
||||
@@ -76,6 +79,7 @@ fn create_unverifiable_block(order: u32, parent_hash: H256) -> Bytes {
|
||||
create_test_block(&create_unverifiable_block_header(order, parent_hash))
|
||||
}
|
||||
|
||||
/// Creates test block with corresponding header and data
|
||||
pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransaction], uncles: &[Header]) -> Bytes {
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
rlp.append(header);
|
||||
@@ -87,23 +91,27 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa
|
||||
rlp.out()
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding amount of blocks
|
||||
pub fn generate_dummy_client(block_number: u32) -> Arc<Client> {
|
||||
generate_dummy_client_with_spec_and_data(Spec::new_test, block_number, 0, &[])
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding amount of blocks and txs per every block
|
||||
pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> {
|
||||
generate_dummy_client_with_spec_and_data(Spec::new_null, block_number, txs_per_block, tx_gas_prices)
|
||||
}
|
||||
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding amount of blocks, txs per block and spec
|
||||
pub fn generate_dummy_client_with_spec_and_data<F>(test_spec: F, block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> where F: Fn()->Spec {
|
||||
generate_dummy_client_with_spec_accounts_and_data(test_spec, None, block_number, txs_per_block, tx_gas_prices)
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding spec and accounts
|
||||
pub fn generate_dummy_client_with_spec_and_accounts<F>(test_spec: F, accounts: Option<Arc<AccountProvider>>) -> Arc<Client> where F: Fn()->Spec {
|
||||
generate_dummy_client_with_spec_accounts_and_data(test_spec, accounts, 0, 0, &[])
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding blocks, accounts and spec
|
||||
pub fn generate_dummy_client_with_spec_accounts_and_data<F>(test_spec: F, accounts: Option<Arc<AccountProvider>>, block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> where F: Fn()->Spec {
|
||||
let test_spec = test_spec();
|
||||
let client_db = new_db();
|
||||
@@ -174,6 +182,7 @@ pub fn generate_dummy_client_with_spec_accounts_and_data<F>(test_spec: F, accoun
|
||||
client
|
||||
}
|
||||
|
||||
/// Adds blocks to the client
|
||||
pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting_number: usize, block_number: usize) {
|
||||
let test_spec = Spec::new_test();
|
||||
let state_root = test_spec.genesis_header().state_root().clone();
|
||||
@@ -203,6 +212,29 @@ pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds one block with transactions
|
||||
pub fn push_block_with_transactions(client: &Arc<Client>, transactions: &[SignedTransaction]) {
|
||||
let test_spec = Spec::new_test();
|
||||
let test_engine = &*test_spec.engine;
|
||||
let block_number = client.chain_info().best_block_number as u64 + 1;
|
||||
|
||||
let mut b = client.prepare_open_block(Address::default(), (0.into(), 5000000.into()), Bytes::new());
|
||||
b.set_timestamp(block_number * 10);
|
||||
|
||||
for t in transactions {
|
||||
b.push_transaction(t.clone(), None).unwrap();
|
||||
}
|
||||
let b = b.close_and_lock().seal(test_engine, vec![]).unwrap();
|
||||
|
||||
if let Err(e) = client.import_block(b.rlp_bytes()) {
|
||||
panic!("error importing block which is valid by definition: {:?}", e);
|
||||
}
|
||||
|
||||
client.flush_queue();
|
||||
client.import_verified_blocks();
|
||||
}
|
||||
|
||||
/// Creates dummy client (not test client) with corresponding blocks
|
||||
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> Arc<Client> {
|
||||
let test_spec = Spec::new_test();
|
||||
let client_db = new_db();
|
||||
@@ -229,6 +261,7 @@ fn new_db() -> Arc<::kvdb::KeyValueDB> {
|
||||
Arc::new(::kvdb_memorydb::create(::db::NUM_COLUMNS.unwrap_or(0)))
|
||||
}
|
||||
|
||||
/// Generates dummy blockchain with corresponding amount of blocks
|
||||
pub fn generate_dummy_blockchain(block_number: u32) -> BlockChain {
|
||||
let db = new_db();
|
||||
let bc = BlockChain::new(BlockChainConfig::default(), &create_unverifiable_block(0, H256::zero()), db.clone());
|
||||
@@ -242,6 +275,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> BlockChain {
|
||||
bc
|
||||
}
|
||||
|
||||
/// Generates dummy blockchain with corresponding amount of blocks (using creation with extra method for blocks creation)
|
||||
pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> BlockChain {
|
||||
let db = new_db();
|
||||
let bc = BlockChain::new(BlockChainConfig::default(), &create_unverifiable_block(0, H256::zero()), db.clone());
|
||||
@@ -256,17 +290,20 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> BlockChain {
|
||||
bc
|
||||
}
|
||||
|
||||
/// Returns empty dummy blockchain
|
||||
pub fn generate_dummy_empty_blockchain() -> BlockChain {
|
||||
let db = new_db();
|
||||
let bc = BlockChain::new(BlockChainConfig::default(), &create_unverifiable_block(0, H256::zero()), db.clone());
|
||||
bc
|
||||
}
|
||||
|
||||
/// Returns temp state
|
||||
pub fn get_temp_state() -> State<::state_db::StateDB> {
|
||||
let journal_db = get_temp_state_db();
|
||||
State::new(journal_db, U256::from(0), Default::default())
|
||||
}
|
||||
|
||||
/// Returns temp state using coresponding factory
|
||||
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();
|
||||
@@ -274,17 +311,20 @@ pub fn get_temp_state_with_factory(factory: EvmFactory) -> State<::state_db::Sta
|
||||
State::new(journal_db, U256::from(0), factories)
|
||||
}
|
||||
|
||||
/// Returns temp state db
|
||||
pub fn get_temp_state_db() -> StateDB {
|
||||
let db = new_db();
|
||||
let journal_db = ::journaldb::new(db, ::journaldb::Algorithm::EarlyMerge, ::db::COL_STATE);
|
||||
StateDB::new(journal_db, 5 * 1024 * 1024)
|
||||
}
|
||||
|
||||
/// Returns sequence of hashes of the dummy blocks
|
||||
pub fn get_good_dummy_block_seq(count: usize) -> Vec<Bytes> {
|
||||
let test_spec = Spec::new_test();
|
||||
get_good_dummy_block_fork_seq(1, count, &test_spec.genesis_header().hash())
|
||||
}
|
||||
|
||||
/// Returns sequence of hashes of the dummy blocks beginning from corresponding parent
|
||||
pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_hash: &H256) -> Vec<Bytes> {
|
||||
let test_spec = Spec::new_test();
|
||||
let genesis_gas = test_spec.genesis_header().gas_limit().clone();
|
||||
@@ -308,6 +348,7 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h
|
||||
r
|
||||
}
|
||||
|
||||
/// Returns hash and header of the correct dummy block
|
||||
pub fn get_good_dummy_block_hash() -> (H256, Bytes) {
|
||||
let mut block_header = Header::new();
|
||||
let test_spec = Spec::new_test();
|
||||
@@ -322,11 +363,13 @@ pub fn get_good_dummy_block_hash() -> (H256, Bytes) {
|
||||
(block_header.hash(), create_test_block(&block_header))
|
||||
}
|
||||
|
||||
/// Returns hash of the correct dummy block
|
||||
pub fn get_good_dummy_block() -> Bytes {
|
||||
let (_, bytes) = get_good_dummy_block_hash();
|
||||
bytes
|
||||
}
|
||||
|
||||
/// Returns hash of the dummy block with incorrect state root
|
||||
pub fn get_bad_state_dummy_block() -> Bytes {
|
||||
let mut block_header = Header::new();
|
||||
let test_spec = Spec::new_test();
|
||||
@@ -342,17 +385,25 @@ pub fn get_bad_state_dummy_block() -> Bytes {
|
||||
create_test_block(&block_header)
|
||||
}
|
||||
|
||||
/// Test actor for chain events
|
||||
#[derive(Default)]
|
||||
pub struct TestNotify {
|
||||
/// Messages store
|
||||
pub messages: RwLock<Vec<Bytes>>,
|
||||
}
|
||||
|
||||
impl ChainNotify for TestNotify {
|
||||
fn broadcast(&self, data: Vec<u8>) {
|
||||
fn broadcast(&self, message: ChainMessageType) {
|
||||
let data = match message {
|
||||
ChainMessageType::Consensus(data) => data,
|
||||
ChainMessageType::SignedPrivateTransaction(data) => data,
|
||||
ChainMessageType::PrivateTransaction(data) => data,
|
||||
};
|
||||
self.messages.write().push(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates new instance of KeyValueDBHandler
|
||||
pub fn restoration_db_handler(config: DatabaseConfig) -> Box<KeyValueDBHandler> {
|
||||
use kvdb::Error;
|
||||
|
||||
@@ -23,7 +23,7 @@ use state::{self, State, CleanupMode};
|
||||
use executive::{Executive, TransactOptions};
|
||||
use ethereum;
|
||||
use block::IsBlock;
|
||||
use tests::helpers::{
|
||||
use test_helpers::{
|
||||
generate_dummy_client, push_blocks_to_client, get_test_client_with_blocks, get_good_dummy_block_seq,
|
||||
generate_dummy_client_with_data, get_good_dummy_block, get_bad_state_dummy_block
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType};
|
||||
use evm::{Factory, VMType};
|
||||
use executive::Executive;
|
||||
use state::Substate;
|
||||
use tests::helpers::get_temp_state_with_factory;
|
||||
use test_helpers::get_temp_state_with_factory;
|
||||
use trace::{NoopVMTracer, NoopTracer};
|
||||
use transaction::SYSTEM_ADDRESS;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
pub mod helpers;
|
||||
mod client;
|
||||
mod evm;
|
||||
mod trace;
|
||||
|
||||
@@ -24,7 +24,7 @@ use ethereum_types::{U256, Address};
|
||||
use io::*;
|
||||
use spec::*;
|
||||
use client::*;
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use client::{BlockChainClient, Client, ClientConfig};
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -731,7 +731,7 @@ mod tests {
|
||||
use spec::Spec;
|
||||
use super::{BlockQueue, Config, State};
|
||||
use super::kind::blocks::Unverified;
|
||||
use tests::helpers::{get_good_dummy_block_seq, get_good_dummy_block};
|
||||
use test_helpers::{get_good_dummy_block_seq, get_good_dummy_block};
|
||||
use error::*;
|
||||
use views::*;
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ mod tests {
|
||||
use error::BlockError::*;
|
||||
use ethkey::{Random, Generator};
|
||||
use spec::{CommonParams, Spec};
|
||||
use tests::helpers::{create_test_block_with_data, create_test_block};
|
||||
use test_helpers::{create_test_block_with_data, create_test_block};
|
||||
use transaction::{SignedTransaction, Transaction, UnverifiedTransaction, Action};
|
||||
use types::log_entry::{LogEntry, LocalizedLogEntry};
|
||||
use rlp;
|
||||
|
||||
Reference in New Issue
Block a user