Conditionally compile ethcore public test helpers (#8743)
* Mark test helpers and test-only specs as cfg(test) * Use test-probe to conditionally compile test helpers * Remove test probe and directly use features tag
This commit is contained in:
parent
8057e8df43
commit
e2a90ce159
@ -89,3 +89,5 @@ json-tests = ["ethcore-transaction/json-tests"]
|
|||||||
test-heavy = []
|
test-heavy = []
|
||||||
# Compile benches
|
# Compile benches
|
||||||
benches = []
|
benches = []
|
||||||
|
# Compile test helpers
|
||||||
|
test-helpers = []
|
||||||
|
@ -35,3 +35,6 @@ serde_derive = "1.0"
|
|||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tiny-keccak = "1.4"
|
tiny-keccak = "1.4"
|
||||||
url = "1"
|
url = "1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
ethcore = { path = "..", features = ["test-helpers"] }
|
||||||
|
@ -20,16 +20,20 @@ mod ancient_import;
|
|||||||
mod client;
|
mod client;
|
||||||
mod config;
|
mod config;
|
||||||
mod error;
|
mod error;
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
mod evm_test_client;
|
mod evm_test_client;
|
||||||
mod io_message;
|
mod io_message;
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
mod test_client;
|
mod test_client;
|
||||||
mod trace;
|
mod trace;
|
||||||
|
|
||||||
pub use self::client::*;
|
pub use self::client::*;
|
||||||
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType};
|
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType};
|
||||||
pub use self::error::Error;
|
pub use self::error::Error;
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult};
|
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult};
|
||||||
pub use self::io_message::ClientIoMessage;
|
pub use self::io_message::ClientIoMessage;
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
|
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
|
||||||
pub use self::chain_notify::{ChainNotify, ChainRoute, ChainRouteType, ChainMessageType};
|
pub use self::chain_notify::{ChainNotify, ChainRoute, ChainRouteType, ChainMessageType};
|
||||||
pub use self::traits::{
|
pub use self::traits::{
|
||||||
|
@ -157,8 +157,6 @@ pub mod snapshot;
|
|||||||
pub mod spec;
|
pub mod spec;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod state_db;
|
pub mod state_db;
|
||||||
// Test helpers made public for usage outside ethcore
|
|
||||||
pub mod test_helpers;
|
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
pub mod verification;
|
pub mod verification;
|
||||||
|
|
||||||
@ -177,6 +175,8 @@ mod tests;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature="json-tests")]
|
#[cfg(feature="json-tests")]
|
||||||
mod json_tests;
|
mod json_tests;
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
|
pub mod test_helpers;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_helpers_internal;
|
mod test_helpers_internal;
|
||||||
|
|
||||||
|
@ -515,6 +515,7 @@ macro_rules! load_bundled {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
macro_rules! load_machine_bundled {
|
macro_rules! load_machine_bundled {
|
||||||
($e:expr) => {
|
($e:expr) => {
|
||||||
Spec::load_machine(
|
Spec::load_machine(
|
||||||
@ -838,38 +839,44 @@ impl Spec {
|
|||||||
self.engine.genesis_epoch_data(&genesis, &call)
|
self.engine.genesis_epoch_data(&genesis, &call)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a
|
|
||||||
/// NullEngine consensus.
|
|
||||||
pub fn new_test() -> Spec {
|
|
||||||
load_bundled!("null_morden")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create the EthereumMachine corresponding to Spec::new_test.
|
|
||||||
pub fn new_test_machine() -> EthereumMachine { load_machine_bundled!("null_morden") }
|
|
||||||
|
|
||||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close.
|
|
||||||
pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") }
|
|
||||||
|
|
||||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose
|
|
||||||
/// secret is keccak('').
|
|
||||||
pub fn new_null() -> Spec {
|
|
||||||
load_bundled!("null")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new Spec which constructs a contract at address 5 with storage at 0 equal to 1.
|
|
||||||
pub fn new_test_constructor() -> Spec {
|
|
||||||
load_bundled!("constructor")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring
|
/// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring
|
||||||
/// work).
|
/// work).
|
||||||
pub fn new_instant() -> Spec {
|
pub fn new_instant() -> Spec {
|
||||||
load_bundled!("instant_seal")
|
load_bundled!("instant_seal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a
|
||||||
|
/// NullEngine consensus.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
|
pub fn new_test() -> Spec {
|
||||||
|
load_bundled!("null_morden")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create the EthereumMachine corresponding to Spec::new_test.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
|
pub fn new_test_machine() -> EthereumMachine { load_machine_bundled!("null_morden") }
|
||||||
|
|
||||||
|
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
|
pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") }
|
||||||
|
|
||||||
|
/// Create a new Spec which is a NullEngine consensus with a premine of address whose
|
||||||
|
/// secret is keccak('').
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
|
pub fn new_null() -> Spec {
|
||||||
|
load_bundled!("null")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new Spec which constructs a contract at address 5 with storage at 0 equal to 1.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
|
pub fn new_test_constructor() -> Spec {
|
||||||
|
load_bundled!("constructor")
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not
|
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not
|
||||||
/// requiring work).
|
/// requiring work).
|
||||||
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
|
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_test_round() -> Self {
|
pub fn new_test_round() -> Self {
|
||||||
load_bundled!("authority_round")
|
load_bundled!("authority_round")
|
||||||
}
|
}
|
||||||
@ -877,6 +884,7 @@ impl Spec {
|
|||||||
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not
|
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not
|
||||||
/// requiring work) with empty step messages enabled.
|
/// requiring work) with empty step messages enabled.
|
||||||
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
|
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_test_round_empty_steps() -> Self {
|
pub fn new_test_round_empty_steps() -> Self {
|
||||||
load_bundled!("authority_round_empty_steps")
|
load_bundled!("authority_round_empty_steps")
|
||||||
}
|
}
|
||||||
@ -884,6 +892,7 @@ impl Spec {
|
|||||||
/// Create a new Spec with AuthorityRound consensus (with empty steps) using a block reward
|
/// Create a new Spec with AuthorityRound consensus (with empty steps) using a block reward
|
||||||
/// contract. The contract source code can be found at:
|
/// contract. The contract source code can be found at:
|
||||||
/// https://github.com/parity-contracts/block-reward/blob/daf7d44383b6cdb11cb6b953b018648e2b027cfb/contracts/ExampleBlockReward.sol
|
/// https://github.com/parity-contracts/block-reward/blob/daf7d44383b6cdb11cb6b953b018648e2b027cfb/contracts/ExampleBlockReward.sol
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_test_round_block_reward_contract() -> Self {
|
pub fn new_test_round_block_reward_contract() -> Self {
|
||||||
load_bundled!("authority_round_block_reward_contract")
|
load_bundled!("authority_round_block_reward_contract")
|
||||||
}
|
}
|
||||||
@ -891,6 +900,7 @@ impl Spec {
|
|||||||
/// Create a new Spec with Tendermint consensus which does internal sealing (not requiring
|
/// Create a new Spec with Tendermint consensus which does internal sealing (not requiring
|
||||||
/// work).
|
/// work).
|
||||||
/// Account keccak("0") and keccak("1") are a authorities.
|
/// Account keccak("0") and keccak("1") are a authorities.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_test_tendermint() -> Self {
|
pub fn new_test_tendermint() -> Self {
|
||||||
load_bundled!("tendermint")
|
load_bundled!("tendermint")
|
||||||
}
|
}
|
||||||
@ -903,6 +913,7 @@ impl Spec {
|
|||||||
/// "0xbfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1" and added
|
/// "0xbfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1" and added
|
||||||
/// back in using
|
/// back in using
|
||||||
/// "0x4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".
|
/// "0x4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_validator_safe_contract() -> Self {
|
pub fn new_validator_safe_contract() -> Self {
|
||||||
load_bundled!("validator_safe_contract")
|
load_bundled!("validator_safe_contract")
|
||||||
}
|
}
|
||||||
@ -910,6 +921,7 @@ impl Spec {
|
|||||||
/// The same as the `safeContract`, but allows reporting and uses AuthorityRound.
|
/// The same as the `safeContract`, but allows reporting and uses AuthorityRound.
|
||||||
/// Account is marked with `reportBenign` it can be checked as disliked with "0xd8f2e0bf".
|
/// Account is marked with `reportBenign` it can be checked as disliked with "0xd8f2e0bf".
|
||||||
/// Validator can be removed with `reportMalicious`.
|
/// Validator can be removed with `reportMalicious`.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_validator_contract() -> Self {
|
pub fn new_validator_contract() -> Self {
|
||||||
load_bundled!("validator_contract")
|
load_bundled!("validator_contract")
|
||||||
}
|
}
|
||||||
@ -918,6 +930,7 @@ impl Spec {
|
|||||||
/// height.
|
/// height.
|
||||||
/// Account with secrets keccak("0") is the validator for block 1 and with keccak("1")
|
/// Account with secrets keccak("0") is the validator for block 1 and with keccak("1")
|
||||||
/// onwards.
|
/// onwards.
|
||||||
|
#[cfg(any(test, feature="test-helpers"))]
|
||||||
pub fn new_validator_multi() -> Self {
|
pub fn new_validator_multi() -> Self {
|
||||||
load_bundled!("validator_multi")
|
load_bundled!("validator_multi")
|
||||||
}
|
}
|
||||||
|
@ -38,3 +38,4 @@ ethcore-io = { path = "../../util/io", features = ["mio"] }
|
|||||||
ethkey = { path = "../../ethkey" }
|
ethkey = { path = "../../ethkey" }
|
||||||
kvdb-memorydb = { path = "../../util/kvdb-memorydb" }
|
kvdb-memorydb = { path = "../../util/kvdb-memorydb" }
|
||||||
ethcore-private-tx = { path = "../private-tx" }
|
ethcore-private-tx = { path = "../private-tx" }
|
||||||
|
ethcore = { path = "..", features = ["test-helpers"] }
|
||||||
|
Loading…
Reference in New Issue
Block a user