1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
pub mod build_validation_package;
pub mod get_entry;
pub mod initialize;
pub mod validate;
#[cfg(test)]
pub mod tests {
use agent::actions::commit::commit_entry;
use context::Context;
use futures::executor::block_on;
use holochain_core_types::{
cas::content::AddressableContent, chain_header::ChainHeader, entry::Entry,
entry_type::EntryType,
};
use holochain_dna::zome::{capabilities::Capability, entry_types::EntryTypeDef};
use instance::{
tests::{test_context, test_instance},
Instance,
};
use std::sync::Arc;
use test_utils::*;
#[cfg_attr(tarpaulin, skip)]
pub fn instance() -> (Instance, Arc<Context>) {
let wasm =
create_wasm_from_file("src/nucleus/actions/wasm-test/target/wasm32-unknown-unknown/release/nucleus_actions_tests.wasm");
let mut dna = create_test_dna_with_cap("test_zome", "test_cap", &Capability::new(), &wasm);
dna.zomes
.get_mut("test_zome")
.unwrap()
.entry_types
.insert(String::from("package_entry"), EntryTypeDef::new());
dna.zomes
.get_mut("test_zome")
.unwrap()
.entry_types
.insert(String::from("package_chain_entries"), EntryTypeDef::new());
dna.zomes
.get_mut("test_zome")
.unwrap()
.entry_types
.insert(String::from("package_chain_headers"), EntryTypeDef::new());
dna.zomes
.get_mut("test_zome")
.unwrap()
.entry_types
.insert(String::from("package_chain_full"), EntryTypeDef::new());
let instance = test_instance(dna).expect("Could not create test instance");
let context = test_context("joan");
let initialized_context = instance.initialize_context(context);
(instance, initialized_context)
}
#[cfg_attr(tarpaulin, skip)]
pub fn test_entry_package_entry() -> Entry {
Entry::new(
&EntryType::App(String::from("package_entry")),
&String::from("test value"),
)
}
#[cfg_attr(tarpaulin, skip)]
pub fn test_entry_package_chain_entries() -> Entry {
Entry::new(
&EntryType::App(String::from("package_chain_entries")),
&String::from("test value"),
)
}
#[cfg_attr(tarpaulin, skip)]
pub fn test_entry_package_chain_headers() -> Entry {
Entry::new(
&EntryType::App(String::from("package_chain_headers")),
&String::from("test value"),
)
}
#[cfg_attr(tarpaulin, skip)]
pub fn test_entry_package_chain_full() -> Entry {
Entry::new(
&EntryType::App(String::from("package_chain_full")),
&String::from("test value"),
)
}
#[cfg_attr(tarpaulin, skip)]
pub fn commit(entry: Entry, context: &Arc<Context>) -> ChainHeader {
let chain = context.state().unwrap().agent().chain();
let commit_result = block_on(commit_entry(
entry.clone(),
&context.clone().action_channel,
&context.clone(),
));
assert!(commit_result.is_ok());
let top_header = context.state().unwrap().agent().top_chain_header();
chain
.iter(&top_header)
.find(|ref header| *header.entry_address() == entry.address())
.expect("Couldn't find header in chain for given entry")
}
}