diff --git a/gateway/src/client.rs b/gateway/src/client.rs index 9f6f9cd79..d98e1aed4 100644 --- a/gateway/src/client.rs +++ b/gateway/src/client.rs @@ -85,11 +85,11 @@ pub trait ChainNotify: Send + Sync { pub struct Client { client: runtime_ethereum::Client, engine: Arc, - #[allow(dead_code)] + #[cfg(not(test))] snapshot_manager: Option, eip86_transition: u64, environment: Arc, - #[allow(dead_code)] + #[cfg(not(test))] storage_backend: Arc, /// The most recent block for which we have sent notifications. notified_block_number: Mutex, @@ -119,9 +119,11 @@ impl Client { Self { client: client, engine: spec.engine.clone(), + #[cfg(not(test))] snapshot_manager: snapshot_manager, eip86_transition: spec.params().eip86_transition, environment, + #[cfg(not(test))] storage_backend: backend, // start at current block notified_block_number: Mutex::new(current_block_number), @@ -141,10 +143,8 @@ impl Client { Self { client: test_helpers::get_test_runtime_client(), engine: spec.engine.clone(), - snapshot_manager: None, eip86_transition: spec.params().eip86_transition, environment: environment, - storage_backend: Arc::new(DummyStorageBackend::new()), notified_block_number: Mutex::new(0), listeners: RwLock::new(vec![]), gas_price: U256::from(1_000_000_000), diff --git a/gateway/src/informant.rs b/gateway/src/informant.rs index f31a69b86..da4913edb 100644 --- a/gateway/src/informant.rs +++ b/gateway/src/informant.rs @@ -110,15 +110,13 @@ impl RpcStats { .unwrap_or(0) } - // used for tests - #[allow(dead_code)] + #[cfg(test)] /// Returns number of open sessions pub fn sessions(&self) -> usize { self.sessions.read().len() } - // used for tests - #[allow(dead_code)] + #[cfg(test)] /// Returns requests rate pub fn requests_rate(&self, id: &H256) -> usize { self.sessions diff --git a/gateway/src/middleware.rs b/gateway/src/middleware.rs index 457780fd3..78bddc741 100644 --- a/gateway/src/middleware.rs +++ b/gateway/src/middleware.rs @@ -252,7 +252,7 @@ mod tests { let request_1 = make_request(1); let response = dispatcher - .on_request(request_1, metadata.clone(), |request, meta| { + .on_request(request_1, metadata.clone(), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() @@ -284,15 +284,15 @@ mod tests { let request_1 = make_request(1); let request_2 = make_request(2); - let response = dispatcher - .on_request(request_1, metadata.clone(), |request, meta| { + let _response = dispatcher + .on_request(request_1, metadata.clone(), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() .unwrap(); let response = dispatcher - .on_request(request_2, metadata.clone(), |request, meta| { + .on_request(request_2, metadata.clone(), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() @@ -348,7 +348,7 @@ mod tests { // batch size: 1 (should pass) let response_1 = middleware - .on_request(batch_1, (), |request, meta| { + .on_request(batch_1, (), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() @@ -359,7 +359,7 @@ mod tests { // batch size: 2 (should fail) let response_2 = middleware - .on_request(batch_2, (), |request, meta| { + .on_request(batch_2, (), |_request, _meta| { Box::new(rpc::futures::finished(None)) }) .wait() diff --git a/gateway/src/rpc_apis.rs b/gateway/src/rpc_apis.rs index c790fcb3f..19f73b108 100644 --- a/gateway/src/rpc_apis.rs +++ b/gateway/src/rpc_apis.rs @@ -64,7 +64,7 @@ impl FromStr for Api { #[derive(Debug, Clone)] pub enum ApiSet { // Used in tests. - #[allow(dead_code)] + #[cfg(test)] // Safe context (like token-protected WS interface) SafeContext, // Unsafe context (like jsonrpc over http) @@ -241,6 +241,7 @@ impl ApiSet { match *self { ApiSet::List(ref apis) => apis.clone(), ApiSet::UnsafeContext => public_list, + #[cfg(test)] ApiSet::SafeContext => public_list, ApiSet::All => public_list, } diff --git a/gateway/src/test_helpers.rs b/gateway/src/test_helpers.rs index 53b278879..dffe3fbb5 100644 --- a/gateway/src/test_helpers.rs +++ b/gateway/src/test_helpers.rs @@ -342,7 +342,7 @@ impl Database for MockDb { unimplemented!(); } - fn with_encryption_key(&mut self, key: StateKeyType, _f: F) -> R + fn with_encryption_key(&mut self, _key: StateKeyType, _f: F) -> R where F: FnOnce(&mut DatabaseHandle) -> R, { diff --git a/src/lib.rs b/src/lib.rs index 84f89d0c7..fa6067e1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ use std::sync::Arc; use ekiden_core::error::{Error, Result}; use ekiden_storage_base::StorageBackend; #[cfg(not(target_env = "sgx"))] -#[allow(dead_code)] +#[cfg(test)] use ekiden_storage_dummy::DummyStorageBackend; #[cfg(target_env = "sgx")] use ekiden_trusted::db::untrusted::UntrustedStorageBackend; @@ -155,7 +155,8 @@ pub fn get_block_height(_request: &bool, ctx: &mut RuntimeCallContext) -> Result Ok(ectx.cache.get_latest_block_number().into()) } -#[allow(dead_code)] +#[cfg(not(feature = "test"))] +#[cfg(not(test))] fn get_block_hash(id: &BlockId, ctx: &mut RuntimeCallContext) -> Result> { let ectx = ctx.runtime.downcast_mut::().unwrap(); @@ -168,7 +169,8 @@ fn get_block_hash(id: &BlockId, ctx: &mut RuntimeCallContext) -> Result Result>> { let ectx = ctx.runtime.downcast_mut::().unwrap(); @@ -189,7 +191,8 @@ fn get_block(id: &BlockId, ctx: &mut RuntimeCallContext) -> Result Result> { let ectx = ctx.runtime.downcast_mut::().unwrap(); diff --git a/src/state.rs b/src/state.rs index 33de0abcb..176af54bf 100644 --- a/src/state.rs +++ b/src/state.rs @@ -400,9 +400,6 @@ mod tests { use self::ekiden_storage_dummy::DummyStorageBackend; - #[allow(dead_code)] - use lazy_static; - use super::*; #[test]