make test helpers not test, add some docs

This commit is contained in:
keorn 2016-09-13 14:21:12 +02:00
parent 8b9e7c0ba5
commit 67601327af
3 changed files with 24 additions and 3 deletions

View File

@ -152,8 +152,9 @@ mod blockchain;
mod types;
mod factory;
#[cfg(test)]
mod tests;
//#[cfg(test)]
#[allow(missing_docs)]
pub mod tests;
#[cfg(test)]
#[cfg(feature="json-tests")]
mod json_tests;

View File

@ -36,6 +36,7 @@ pub enum ChainEra {
DaoHardfork,
}
/// Engine for testing nested calls.
pub struct TestEngine {
engine: Arc<Engine>,
max_depth: usize
@ -124,7 +125,12 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa
}
pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>> {
generate_dummy_client_with_spec_and_data(Spec::new_test, block_number, 0, &[])
generate_dummy_client_with_spec(Spec::new_test, block_number)
}
pub fn generate_dummy_client_with_spec<F>(get_spec: F, block_number: u32) -> GuardedTempResult<Arc<Client>> where
F: Fn()->Spec {
generate_dummy_client_with_spec_and_data(get_spec, block_number, 0, &[])
}
pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> GuardedTempResult<Arc<Client>> {
@ -266,6 +272,7 @@ pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<
}
}
/// New db at path.
fn new_db(path: &str) -> Arc<Database> {
Arc::new(
Database::open(&DatabaseConfig::with_columns(::db::NUM_COLUMNS), path)
@ -273,6 +280,7 @@ fn new_db(path: &str) -> Arc<Database> {
)
}
/// Make blockchain.
pub fn generate_dummy_blockchain(block_number: u32) -> GuardedTempResult<BlockChain> {
let temp = RandomTempPath::new();
let db = new_db(temp.as_str());
@ -291,6 +299,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> GuardedTempResult<BlockCh
}
}
/// Blockchain with extra data.
pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> GuardedTempResult<BlockChain> {
let temp = RandomTempPath::new();
let db = new_db(temp.as_str());
@ -310,6 +319,7 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> GuardedTempRes
}
}
/// Make blochchain.
pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
let temp = RandomTempPath::new();
let db = new_db(temp.as_str());
@ -321,6 +331,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
}
}
/// Temporary journal db at random path.
pub fn get_temp_journal_db() -> GuardedTempResult<Box<JournalDB>> {
let temp = RandomTempPath::new();
let journal_db = get_temp_journal_db_in(temp.as_path());
@ -331,6 +342,7 @@ pub fn get_temp_journal_db() -> GuardedTempResult<Box<JournalDB>> {
}
}
/// Temporary state.
pub fn get_temp_state() -> GuardedTempResult<State> {
let temp = RandomTempPath::new();
let journal_db = get_temp_journal_db_in(temp.as_path());
@ -341,21 +353,25 @@ pub fn get_temp_state() -> GuardedTempResult<State> {
}
}
/// Temporary journal db.
pub fn get_temp_journal_db_in(path: &Path) -> Box<JournalDB> {
let db = new_db(path.to_str().expect("Only valid utf8 paths for tests."));
journaldb::new(db.clone(), journaldb::Algorithm::EarlyMerge, None)
}
/// Temporary state db.
pub fn get_temp_state_in(path: &Path) -> State {
let journal_db = get_temp_journal_db_in(path);
State::new(journal_db, U256::from(0), Default::default())
}
/// Sequence of good blocks.
pub fn get_good_dummy_block_seq(count: usize) -> Vec<Bytes> {
let test_spec = get_test_spec();
get_good_dummy_block_fork_seq(1, count, &test_spec.genesis_header().hash())
}
/// Forked sequence of good blocks.
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.engine;
@ -380,6 +396,7 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h
r
}
/// Good block.
pub fn get_good_dummy_block() -> Bytes {
let mut block_header = Header::new();
let test_spec = get_test_spec();
@ -394,6 +411,7 @@ pub fn get_good_dummy_block() -> Bytes {
create_test_block(&block_header)
}
/// Block with bad state.
pub fn get_bad_state_dummy_block() -> Bytes {
let mut block_header = Header::new();
let test_spec = get_test_spec();

View File

@ -15,5 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
pub mod helpers;
#[cfg(test)]
mod client;
#[cfg(test)]
mod rpc;