Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit e2a90ce

Browse files
sorpaas5chdn
authored andcommitted
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
1 parent 8057e8d commit e2a90ce

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

ethcore/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ json-tests = ["ethcore-transaction/json-tests"]
8989
test-heavy = []
9090
# Compile benches
9191
benches = []
92+
# Compile test helpers
93+
test-helpers = []

ethcore/private-tx/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ serde_derive = "1.0"
3535
serde_json = "1.0"
3636
tiny-keccak = "1.4"
3737
url = "1"
38+
39+
[dev-dependencies]
40+
ethcore = { path = "..", features = ["test-helpers"] }

ethcore/src/client/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ mod ancient_import;
2020
mod client;
2121
mod config;
2222
mod error;
23+
#[cfg(any(test, feature="test-helpers"))]
2324
mod evm_test_client;
2425
mod io_message;
26+
#[cfg(any(test, feature="test-helpers"))]
2527
mod test_client;
2628
mod trace;
2729

2830
pub use self::client::*;
2931
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType};
3032
pub use self::error::Error;
33+
#[cfg(any(test, feature="test-helpers"))]
3134
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult};
3235
pub use self::io_message::ClientIoMessage;
36+
#[cfg(any(test, feature="test-helpers"))]
3337
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
3438
pub use self::chain_notify::{ChainNotify, ChainRoute, ChainRouteType, ChainMessageType};
3539
pub use self::traits::{

ethcore/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ pub mod snapshot;
157157
pub mod spec;
158158
pub mod state;
159159
pub mod state_db;
160-
// Test helpers made public for usage outside ethcore
161-
pub mod test_helpers;
162160
pub mod trace;
163161
pub mod verification;
164162

@@ -177,6 +175,8 @@ mod tests;
177175
#[cfg(test)]
178176
#[cfg(feature="json-tests")]
179177
mod json_tests;
178+
#[cfg(any(test, feature="test-helpers"))]
179+
pub mod test_helpers;
180180
#[cfg(test)]
181181
mod test_helpers_internal;
182182

ethcore/src/spec/spec.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ macro_rules! load_bundled {
515515
};
516516
}
517517

518+
#[cfg(any(test, feature="test-helpers"))]
518519
macro_rules! load_machine_bundled {
519520
($e:expr) => {
520521
Spec::load_machine(
@@ -838,59 +839,68 @@ impl Spec {
838839
self.engine.genesis_epoch_data(&genesis, &call)
839840
}
840841

842+
/// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring
843+
/// work).
844+
pub fn new_instant() -> Spec {
845+
load_bundled!("instant_seal")
846+
}
847+
841848
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a
842849
/// NullEngine consensus.
850+
#[cfg(any(test, feature="test-helpers"))]
843851
pub fn new_test() -> Spec {
844852
load_bundled!("null_morden")
845853
}
846854

847855
/// Create the EthereumMachine corresponding to Spec::new_test.
856+
#[cfg(any(test, feature="test-helpers"))]
848857
pub fn new_test_machine() -> EthereumMachine { load_machine_bundled!("null_morden") }
849858

850859
/// 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.
860+
#[cfg(any(test, feature="test-helpers"))]
851861
pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") }
852862

853863
/// Create a new Spec which is a NullEngine consensus with a premine of address whose
854864
/// secret is keccak('').
865+
#[cfg(any(test, feature="test-helpers"))]
855866
pub fn new_null() -> Spec {
856867
load_bundled!("null")
857868
}
858869

859870
/// Create a new Spec which constructs a contract at address 5 with storage at 0 equal to 1.
871+
#[cfg(any(test, feature="test-helpers"))]
860872
pub fn new_test_constructor() -> Spec {
861873
load_bundled!("constructor")
862874
}
863875

864-
/// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring
865-
/// work).
866-
pub fn new_instant() -> Spec {
867-
load_bundled!("instant_seal")
868-
}
869-
870876
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not
871877
/// requiring work).
872878
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
879+
#[cfg(any(test, feature="test-helpers"))]
873880
pub fn new_test_round() -> Self {
874881
load_bundled!("authority_round")
875882
}
876883

877884
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not
878885
/// requiring work) with empty step messages enabled.
879886
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
887+
#[cfg(any(test, feature="test-helpers"))]
880888
pub fn new_test_round_empty_steps() -> Self {
881889
load_bundled!("authority_round_empty_steps")
882890
}
883891

884892
/// Create a new Spec with AuthorityRound consensus (with empty steps) using a block reward
885893
/// contract. The contract source code can be found at:
886894
/// https://github.com/parity-contracts/block-reward/blob/daf7d44383b6cdb11cb6b953b018648e2b027cfb/contracts/ExampleBlockReward.sol
895+
#[cfg(any(test, feature="test-helpers"))]
887896
pub fn new_test_round_block_reward_contract() -> Self {
888897
load_bundled!("authority_round_block_reward_contract")
889898
}
890899

891900
/// Create a new Spec with Tendermint consensus which does internal sealing (not requiring
892901
/// work).
893902
/// Account keccak("0") and keccak("1") are a authorities.
903+
#[cfg(any(test, feature="test-helpers"))]
894904
pub fn new_test_tendermint() -> Self {
895905
load_bundled!("tendermint")
896906
}
@@ -903,13 +913,15 @@ impl Spec {
903913
/// "0xbfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1" and added
904914
/// back in using
905915
/// "0x4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".
916+
#[cfg(any(test, feature="test-helpers"))]
906917
pub fn new_validator_safe_contract() -> Self {
907918
load_bundled!("validator_safe_contract")
908919
}
909920

910921
/// The same as the `safeContract`, but allows reporting and uses AuthorityRound.
911922
/// Account is marked with `reportBenign` it can be checked as disliked with "0xd8f2e0bf".
912923
/// Validator can be removed with `reportMalicious`.
924+
#[cfg(any(test, feature="test-helpers"))]
913925
pub fn new_validator_contract() -> Self {
914926
load_bundled!("validator_contract")
915927
}
@@ -918,6 +930,7 @@ impl Spec {
918930
/// height.
919931
/// Account with secrets keccak("0") is the validator for block 1 and with keccak("1")
920932
/// onwards.
933+
#[cfg(any(test, feature="test-helpers"))]
921934
pub fn new_validator_multi() -> Self {
922935
load_bundled!("validator_multi")
923936
}

ethcore/sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ ethcore-io = { path = "../../util/io", features = ["mio"] }
3838
ethkey = { path = "../../ethkey" }
3939
kvdb-memorydb = { path = "../../util/kvdb-memorydb" }
4040
ethcore-private-tx = { path = "../private-tx" }
41+
ethcore = { path = "..", features = ["test-helpers"] }

0 commit comments

Comments
 (0)