Skip to content

Commit

Permalink
Merge pull request #360 from holochain/holochain-p2p-mock
Browse files Browse the repository at this point in the history
HolochainP2pCell mock
  • Loading branch information
maackle committed Sep 17, 2020
2 parents 25e4d85 + 4a31bad commit 490e6ba
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 290 deletions.
10 changes: 6 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/holochain/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ edition = "2018"

[dependencies]
anyhow = "1.0.26"
async-trait = "0.1.24"
async-trait = "0.1"
base64 = "0.10.1"
cfg-if = "0.1"
chrono = "0.4.6"
Expand All @@ -36,7 +36,7 @@ holochain_zome_types = { version = "0.0.1", path = "../zome_types" }
human-panic = "1.0.3"
lazy_static = "1.4.0"
legacy = { path = "../legacy", package = "holochain_legacy" }
mockall = "0.7.0"
mockall = "0.8"
must_future = "0.1.1"
nanoid = "0.3"
num_cpus = "1.8"
Expand Down
10 changes: 6 additions & 4 deletions crates/holochain/src/conductor/cell.rs
Expand Up @@ -36,6 +36,7 @@ use futures::future::FutureExt;
use hash_type::AnyDht;
use holo_hash::*;
use holochain_keystore::Signature;
use holochain_p2p::HolochainP2pCellT;
use holochain_serialized_bytes::SerializedBytes;
use holochain_state::{
db::GetDb,
Expand Down Expand Up @@ -94,14 +95,15 @@ impl PartialEq for Cell {
/// The [Conductor] manages a collection of Cells, and will call functions
/// on the Cell when a Conductor API method is called (either a
/// [CellConductorApi] or an [AppInterfaceApi])
pub struct Cell<CA = CellConductorApi>
pub struct Cell<Api = CellConductorApi, P2pCell = holochain_p2p::HolochainP2pCell>
where
CA: CellConductorApiT,
Api: CellConductorApiT,
P2pCell: holochain_p2p::HolochainP2pCellT,
{
id: CellId,
conductor_api: CA,
conductor_api: Api,
env: EnvironmentWrite,
holochain_p2p_cell: holochain_p2p::HolochainP2pCell,
holochain_p2p_cell: P2pCell,
queue_triggers: InitialQueueTriggers,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/holochain/src/conductor/cell/test.rs
Expand Up @@ -29,9 +29,9 @@ async fn test_cell_handle_publish() {

let holochain_p2p_cell = holochain_p2p.to_cell(dna.clone(), agent.clone());

let mut mock_handler = crate::conductor::handle::mock::MockConductorHandle::new();
let mut mock_handler = crate::conductor::handle::MockConductorHandleT::new();
mock_handler
.expect_sync_get_dna()
.expect_get_dna()
.returning(|_| Some(fixt!(DnaFile)));

let mock_handler: crate::conductor::handle::ConductorHandle = Arc::new(mock_handler);
Expand Down
20 changes: 9 additions & 11 deletions crates/holochain/src/conductor/compat.rs
Expand Up @@ -186,9 +186,7 @@ fn extract_app_interfaces(
pub mod tests {

use super::*;
use crate::conductor::{
handle::mock::MockConductorHandle, paths::EnvironmentRootPath, Conductor,
};
use crate::conductor::{handle::MockConductorHandleT, paths::EnvironmentRootPath, Conductor};
use holochain_types::{app::MembraneProof, test_utils::fake_dna_zomes};
use holochain_wasm_test_utils::TestWasm;
use matches::assert_matches;
Expand Down Expand Up @@ -347,24 +345,24 @@ pub mod tests {
.await
.unwrap();

let mut handle = MockConductorHandle::new();
let mut handle = MockConductorHandleT::new();
handle
.expect_sync_install_dna()
.expect_install_dna()
.with(predicate::eq(dna1.clone()))
.times(1)
.returning(|_| Ok(()));
handle
.expect_sync_install_dna()
.expect_install_dna()
.with(predicate::eq(dna1a.clone()))
.times(1)
.returning(|_| Ok(()));
handle
.expect_sync_install_dna()
.expect_install_dna()
.with(predicate::eq(dna2.clone()))
.times(1)
.returning(|_| Ok(()));
handle
.expect_sync_install_app()
.expect_install_app()
.with(
predicate::eq("LEGACY".to_string()),
predicate::function(move |data: &Vec<(InstalledCell, Option<MembraneProof>)>| {
Expand All @@ -377,16 +375,16 @@ pub mod tests {
.times(1)
.returning(|_, _| Ok(()));
handle
.expect_sync_activate_app()
.expect_activate_app()
.with(predicate::eq("LEGACY".to_string()))
.times(1)
.returning(|_| Ok(()));
handle
.expect_sync_setup_cells()
.expect_setup_cells()
.times(1)
.returning(|| Ok(vec![]));
handle
.expect_sync_add_app_interface()
.expect_add_app_interface()
.with(predicate::eq(1111))
.times(1)
.returning(|port| Ok(port));
Expand Down
6 changes: 3 additions & 3 deletions crates/holochain/src/conductor/conductor.rs
Expand Up @@ -65,7 +65,7 @@ use futures::future::{self, TryFutureExt};
use holo_hash::DnaHash;

#[cfg(test)]
use super::handle::mock::MockConductorHandle;
use super::handle::MockConductorHandleT;
use fallible_iterator::FallibleIterator;
use holochain_zome_types::entry_def::EntryDef;

Expand Down Expand Up @@ -734,7 +734,7 @@ mod builder {
#[cfg(test)]
state: Option<ConductorState>,
#[cfg(test)]
mock_handle: Option<MockConductorHandle>,
mock_handle: Option<MockConductorHandleT>,
}

impl ConductorBuilder {
Expand Down Expand Up @@ -886,7 +886,7 @@ mod builder {
/// Pass a mock handle in, which will be returned regardless of whatever
/// else happens to this builder
#[cfg(test)]
pub fn with_mock_handle(mut self, handle: MockConductorHandle) -> Self {
pub fn with_mock_handle(mut self, handle: MockConductorHandleT) -> Self {
self.mock_handle = Some(handle);
self
}
Expand Down

0 comments on commit 490e6ba

Please sign in to comment.