fixed tests

This commit is contained in:
Svyatoslav Nikolsky 2017-07-24 12:36:31 +03:00
parent 5fb9652af5
commit b31b067743
4 changed files with 41 additions and 6 deletions

View File

@ -192,10 +192,13 @@ impl Drop for KeyServerCore {
pub mod tests { pub mod tests {
use std::time; use std::time;
use std::sync::Arc; use std::sync::Arc;
use std::net::SocketAddr;
use std::collections::BTreeMap;
use ethcrypto; use ethcrypto;
use ethkey::{self, Secret, Random, Generator}; use ethkey::{self, Secret, Random, Generator};
use acl_storage::tests::DummyAclStorage; use acl_storage::tests::DummyAclStorage;
use key_storage::tests::DummyKeyStorage; use key_storage::tests::DummyKeyStorage;
use key_server_set::tests::MapKeyServerSet;
use key_server_cluster::math; use key_server_cluster::math;
use util::H256; use util::H256;
use types::all::{Error, Public, ClusterConfiguration, NodeAddress, RequestSignature, ServerKeyId, use types::all::{Error, Public, ClusterConfiguration, NodeAddress, RequestSignature, ServerKeyId,
@ -253,8 +256,11 @@ pub mod tests {
})).collect(), })).collect(),
allow_connecting_to_higher_nodes: false, allow_connecting_to_higher_nodes: false,
}).collect(); }).collect();
let key_servers_set: BTreeMap<Public, SocketAddr> = configs[0].nodes.iter()
.map(|(k, a)| (k.clone(), format!("{}:{}", a.address, a.port).parse().unwrap()))
.collect();
let key_servers: Vec<_> = configs.into_iter().map(|cfg| let key_servers: Vec<_> = configs.into_iter().map(|cfg|
KeyServerImpl::new(&cfg, Arc::new(DummyAclStorage::default()), Arc::new(DummyKeyStorage::default())).unwrap() KeyServerImpl::new(&cfg, Arc::new(MapKeyServerSet::new(key_servers_set.clone())), Arc::new(DummyAclStorage::default()), Arc::new(DummyKeyStorage::default())).unwrap()
).collect(); ).collect();
// wait until connections are established. It is fast => do not bother with events here // wait until connections are established. It is fast => do not bother with events here

View File

@ -989,7 +989,7 @@ pub mod tests {
use parking_lot::Mutex; use parking_lot::Mutex;
use tokio_core::reactor::Core; use tokio_core::reactor::Core;
use ethkey::{Random, Generator, Public}; use ethkey::{Random, Generator, Public};
use key_server_cluster::{NodeId, SessionId, Error, DummyAclStorage, DummyKeyStorage}; use key_server_cluster::{NodeId, SessionId, Error, DummyAclStorage, DummyKeyStorage, MapKeyServerSet};
use key_server_cluster::message::Message; use key_server_cluster::message::Message;
use key_server_cluster::cluster::{Cluster, ClusterCore, ClusterConfiguration}; use key_server_cluster::cluster::{Cluster, ClusterCore, ClusterConfiguration};
use key_server_cluster::generation_session::{Session as GenerationSession, SessionState as GenerationSessionState}; use key_server_cluster::generation_session::{Session as GenerationSession, SessionState as GenerationSessionState};
@ -1059,7 +1059,7 @@ pub mod tests {
} }
pub fn all_connections_established(cluster: &Arc<ClusterCore>) -> bool { pub fn all_connections_established(cluster: &Arc<ClusterCore>) -> bool {
cluster.config().nodes.keys() cluster.config().key_server_set.get().keys()
.filter(|p| *p != cluster.config().self_key_pair.public()) .filter(|p| *p != cluster.config().self_key_pair.public())
.all(|p| cluster.connection(p).is_some()) .all(|p| cluster.connection(p).is_some())
} }
@ -1070,9 +1070,9 @@ pub mod tests {
threads: 1, threads: 1,
self_key_pair: key_pairs[i].clone(), self_key_pair: key_pairs[i].clone(),
listen_address: ("127.0.0.1".to_owned(), ports_begin + i as u16), listen_address: ("127.0.0.1".to_owned(), ports_begin + i as u16),
nodes: key_pairs.iter().enumerate() key_server_set: Arc::new(MapKeyServerSet::new(key_pairs.iter().enumerate()
.map(|(j, kp)| (kp.public().clone(), ("127.0.0.1".into(), ports_begin + j as u16))) .map(|(j, kp)| (kp.public().clone(), format!("127.0.0.1:{}", ports_begin + j as u16).parse().unwrap()))
.collect(), .collect())),
allow_connecting_to_higher_nodes: false, allow_connecting_to_higher_nodes: false,
key_storage: Arc::new(DummyKeyStorage::default()), key_storage: Arc::new(DummyKeyStorage::default()),
acl_storage: Arc::new(DummyAclStorage::default()), acl_storage: Arc::new(DummyAclStorage::default()),

View File

@ -34,6 +34,8 @@ pub use self::decryption_session::Session as DecryptionSession;
pub use super::key_storage::tests::DummyKeyStorage; pub use super::key_storage::tests::DummyKeyStorage;
#[cfg(test)] #[cfg(test)]
pub use super::acl_storage::tests::DummyAclStorage; pub use super::acl_storage::tests::DummyAclStorage;
#[cfg(test)]
pub use super::key_server_set::tests::MapKeyServerSet;
pub type SessionId = ServerKeyId; pub type SessionId = ServerKeyId;

View File

@ -175,3 +175,30 @@ impl CachedContract {
self.contract_addr = new_contract_address; self.contract_addr = new_contract_address;
} }
} }
#[cfg(test)]
pub mod tests {
use std::collections::BTreeMap;
use std::net::SocketAddr;
use ethkey::Public;
use super::KeyServerSet;
#[derive(Default)]
pub struct MapKeyServerSet {
nodes: BTreeMap<Public, SocketAddr>,
}
impl MapKeyServerSet {
pub fn new(nodes: BTreeMap<Public, SocketAddr>) -> Self {
MapKeyServerSet {
nodes: nodes,
}
}
}
impl KeyServerSet for MapKeyServerSet {
fn get(&self) -> BTreeMap<Public, SocketAddr> {
self.nodes.clone()
}
}
}