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
extern crate holochain_agent;
extern crate holochain_cas_implementations;
extern crate holochain_core;
extern crate holochain_core_api;
extern crate holochain_dna;
extern crate tempfile;

use holochain_agent::Agent;
use holochain_cas_implementations::{cas::file::FilesystemStorage, eav::file::EavFileStorage};
use holochain_core::{context::Context, logger::SimpleLogger, persister::SimplePersister};
use holochain_core_api::*;
use holochain_dna::Dna;
use std::{
    env,
    sync::{Arc, Mutex},
};

use tempfile::tempdir;

// this is all debug code, no need to track code test coverage
#[cfg_attr(tarpaulin, skip)]
fn usage() {
    println!("Usage: holochain_test_bin <identity>");
    std::process::exit(1);
}

// this is all debug code, no need to track code test coverage
#[cfg_attr(tarpaulin, skip)]
fn main() {
    let tempdir = tempdir().unwrap();
    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {
        usage();
    }

    let identity = &args[1];

    if identity == "" {
        usage();
    }

    //let dna = holochain_dna::from_package_file("mydna.hcpkg");
    let dna = Dna::new();
    let agent = Agent::from(identity.to_string());
    let context = Context::new(
        agent,
        Arc::new(Mutex::new(SimpleLogger {})),
        Arc::new(Mutex::new(SimplePersister::new("foo".to_string()))),
        FilesystemStorage::new(tempdir.path().to_str().unwrap()).unwrap(),
        EavFileStorage::new(tempdir.path().to_str().unwrap().to_string()).unwrap(),
    ).expect("context is supposed to be created");
    let mut hc = Holochain::new(dna, Arc::new(context)).unwrap();
    println!("Created a new instance with identity: {}", identity);

    // start up the holochain instance
    hc.start().expect("couldn't start the holochain instance");
    println!("Started the holochain instance..");

    // call a function in the zome code
    //hc.call("some_fn");

    // get the state
    {
        let state = hc.state().unwrap();
        println!("Agent State: {:?}", state.agent());

        // do some other stuff with the state here
        // ...
    }

    // stop the holochain instance
    hc.stop().expect("couldn't stop the holochain instance");
    println!("Stopped the holochain instance..");
}