use crate::prelude::InitCallbackResult;
use crate::sweettest::{SweetConductor, SweetDnaFile};
use crate::test_utils::retry_fn_until_timeout;
use holochain_wasm_test_utils::TestWasm;
#[tokio::test(flavor = "multi_thread")]
async fn check_or_run_zome_init_triggers_zome_initialization() {
let zome = TestWasm::InitPass;
let (dna, _, _) = SweetDnaFile::unique_from_test_wasms(vec![zome]).await;
let mut conductor = SweetConductor::from_standard_config().await;
let app = conductor.setup_app("app", [&dna]).await.unwrap();
let cell_id = app.cells()[0].cell_id();
retry_fn_until_timeout(
|| async { conductor.all_ops_integrated(dna.dna_hash()).unwrap() },
None,
None,
)
.await
.unwrap();
let before_state_dump = conductor
.raw_handle()
.dump_full_cell_state(cell_id, None)
.await
.expect("Failed to get state dump");
let cell = conductor
.raw_handle()
.cell_by_id(cell_id)
.await
.expect("failed to get cell");
cell.check_or_run_zome_init()
.await
.expect("failed to init cell");
retry_fn_until_timeout(
|| async { conductor.all_ops_integrated(dna.dna_hash()).unwrap() },
None,
None,
)
.await
.unwrap();
let after_state_dump = conductor
.raw_handle()
.dump_full_cell_state(cell_id, None)
.await
.expect("Failed to get state dump");
assert_eq!(
after_state_dump.integration_dump.integrated.len()
- before_state_dump.integration_dump.integrated.len(),
2
);
assert_eq!(after_state_dump.integration_dump.integration_limbo.len(), 0);
}
#[tokio::test(flavor = "multi_thread")]
async fn check_or_run_zome_init_does_nothing_if_already_initialized() {
let zome = TestWasm::InitPass;
let (dna, _, _) = SweetDnaFile::unique_from_test_wasms(vec![zome]).await;
let mut conductor = SweetConductor::from_standard_config().await;
let app = conductor.setup_app("app", [&dna]).await.unwrap();
let cell_id = app.cells()[0].cell_id();
let sweet_zome = app.cells()[0].zome(TestWasm::InitPass);
let _: InitCallbackResult = conductor.call(&sweet_zome, "init", ()).await;
retry_fn_until_timeout(
|| async { conductor.all_ops_integrated(dna.dna_hash()).unwrap() },
None,
None,
)
.await
.unwrap();
let before_state_dump = conductor
.raw_handle()
.dump_full_cell_state(cell_id, None)
.await
.expect("Failed to get state dump");
let cell = conductor
.raw_handle()
.cell_by_id(cell_id)
.await
.expect("failed to get cell");
cell.check_or_run_zome_init()
.await
.expect("failed to init cell");
retry_fn_until_timeout(
|| async { conductor.all_ops_integrated(dna.dna_hash()).unwrap() },
None,
None,
)
.await
.unwrap();
let after_state_dump = conductor
.raw_handle()
.dump_full_cell_state(cell_id, None)
.await
.expect("Failed to get state dump");
assert_eq!(
after_state_dump.integration_dump.integrated.len()
- before_state_dump.integration_dump.integrated.len(),
0
);
}