use crate::sweettest::{SweetConductor, SweetDnaFile};
use holochain_conductor_api::CellInfo;
use holochain_types::prelude::*;
use holochain_wasm_test_utils::TestWasm;
use matches::matches;
#[tokio::test(flavor = "multi_thread")]
async fn app_info_returns_all_cells_with_info() {
let (dna_1, _, _) = SweetDnaFile::unique_from_test_wasms(vec![TestWasm::Create]).await;
let (dna_2, _, _) = SweetDnaFile::unique_from_test_wasms(vec![TestWasm::Create]).await;
let mut conductor = SweetConductor::from_standard_config().await;
let app_id: InstalledAppId = "app".into();
let role_name_1: RoleName = "role_1".into();
let role_name_2: RoleName = "role_2".into();
let app = conductor
.setup_app(
&app_id,
[
&(role_name_1.clone(), dna_1.clone()),
&(role_name_2.clone(), dna_2.clone()),
],
)
.await
.unwrap();
let agent_pub_key = app.agent().clone();
let clone_cell_1 = conductor
.clone()
.create_clone_cell(
&app_id,
CreateCloneCellPayload {
role_name: role_name_1.clone(),
modifiers: DnaModifiersOpt::none().with_network_seed("seed numero uno".to_string()),
membrane_proof: None,
name: None,
},
)
.await
.unwrap();
assert_eq!(clone_cell_1.original_dna_hash, dna_1.dna_hash().clone());
let clone_cell_2 = conductor
.clone()
.create_clone_cell(
&app_id,
CreateCloneCellPayload {
role_name: role_name_2.clone(),
modifiers: DnaModifiersOpt::none().with_network_seed("seed numero dos".to_string()),
membrane_proof: None,
name: None,
},
)
.await
.unwrap();
assert_eq!(clone_cell_2.original_dna_hash, dna_2.dna_hash().clone());
conductor
.disable_clone_cell(
&app_id,
&DisableCloneCellPayload {
clone_cell_id: CloneCellId::DnaHash(clone_cell_2.cell_id.dna_hash().clone()),
},
)
.await
.unwrap();
let app_info = conductor.get_app_info(&app_id).await.unwrap().unwrap();
assert_eq!(app_info.agent_pub_key, agent_pub_key);
assert_eq!(app_info.cell_info.len(), 2);
let cell_info_for_role_1 = app_info.cell_info.get(&role_name_1).unwrap();
matches!(cell_info_for_role_1[0], CellInfo::Provisioned(_));
matches!(cell_info_for_role_1[1], CellInfo::Cloned(_));
let cell_info_for_role_2 = app_info.cell_info.get(&role_name_2).unwrap();
matches!(cell_info_for_role_2[0], CellInfo::Provisioned(_));
matches!(cell_info_for_role_2[1], CellInfo::Cloned(_));
assert!(if let CellInfo::Cloned(cell) = &cell_info_for_role_1[1] {
cell.cell_id == clone_cell_1.cell_id.clone()
} else {
false
});
assert!(if let CellInfo::Cloned(cell) = &cell_info_for_role_2[1] {
cell.cell_id == clone_cell_2.cell_id.clone()
} else {
false
});
conductor.shutdown().await;
conductor.startup(false).await;
let app_info_after_restart = conductor
.clone()
.get_app_info(&app_id)
.await
.unwrap()
.unwrap();
assert_eq!(app_info, app_info_after_restart);
let reenabled_clone_cell = conductor
.clone()
.enable_clone_cell(
&app_id,
&EnableCloneCellPayload {
clone_cell_id: CloneCellId::DnaHash(clone_cell_2.cell_id.dna_hash().clone()),
},
)
.await
.unwrap();
assert_eq!(
reenabled_clone_cell.original_dna_hash,
dna_2.dna_hash().clone()
);
}