Function holochain::test_utils::network_simulation::data_zome
source · Expand description
The zome to use for this simulation. Currently this is a limitation of this prototype that you must use the data generation zome in the actual simulation so the Dna record matches. Hopefully this limitation can be overcome in the future.
Examples found in repository?
src/test_utils/network_simulation.rs (lines 189-192)
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
pub async fn generate_test_data(
num_agents: usize,
min_num_ops_held: usize,
in_memory: bool,
force_new_data: bool,
) -> (MockNetworkData, Connection) {
let cached = if !in_memory || !force_new_data {
get_cached().filter(|data| data.authored.len() == num_agents)
} else {
None
};
let is_cached = cached.is_some();
let (data, dna_hash) = match cached {
Some(cached) => {
let dna_file = data_zome(
cached.integrity_uuid.clone(),
cached.coordinator_uuid.clone(),
)
.await;
let dna_hash = dna_file.dna_hash().clone();
(cached, dna_hash)
}
None => {
let integrity_uuid = nanoid::nanoid!();
let coordinator_uuid = nanoid::nanoid!();
let dna_file = data_zome(integrity_uuid.clone(), coordinator_uuid.clone()).await;
let dna_hash = dna_file.dna_hash().clone();
let data = create_test_data(
num_agents,
min_num_ops_held,
dna_file,
integrity_uuid,
coordinator_uuid,
)
.await;
(data, dna_hash)
}
};
let generated_data = GeneratedData {
ops: data.ops,
peer_data: reset_peer_data(data.peer_data, &dna_hash).await,
integrity_uuid: data.integrity_uuid,
coordinator_uuid: data.coordinator_uuid,
authored: data.authored,
};
let data = MockNetworkData::new(generated_data);
let conn = cache_data(in_memory, &data, is_cached);
(data, conn)
}