forked from iotaledger/streams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
118 lines (97 loc) · 3.64 KB
/
main.rs
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
109
110
111
112
113
114
115
116
117
118
#![allow(non_snake_case)]
#![allow(dead_code)]
//#![no_std]
use dotenv;
use std::env;
use anyhow::Result;
use rand::Rng;
use iota_streams::{
app::transport::{
TransportOptions,
tangle::client::{SendTrytesOptions, Client, },
},
app_channels::api::tangle::Transport,
core::prelude::{ String, Rc, },
};
use core::cell::RefCell;
mod branching;
fn run_single_branch_test<T: Transport>(
transport: Rc<RefCell<T>>,
seed: &str,
){
println!("\tRunning Single Branch Test, seed: {}", seed);
match branching::single_branch::example(transport, false, seed) {
Err(err) => println!("Error in Single Branch test: {:?}", err),
Ok(_) => println!("\tSingle Branch Test completed!!"),
}
println!("#######################################");
}
fn run_multi_branch_test<T: Transport>(
transport: Rc<RefCell<T>>,
seed: &str,
){
println!("\tRunning Multi Branch Test, seed: {}", seed);
match branching::multi_branch::example(transport, true, seed) {
Err(err) => println!("Error in Multi Branch test: {:?}", err),
Ok(_) => println!("\tMulti Branch Test completed!!"),
}
println!("#######################################");
}
fn run_main<T: Transport>(transport: T) -> Result<()>
{
let seed1: &str = "SEEDSINGLE";
let seed2: &str = "SEEDMULTI9";
let transport = Rc::new(RefCell::new(transport));
run_single_branch_test(transport.clone(), seed1);
run_multi_branch_test(transport.clone(), seed2);
Ok(())
}
#[allow(dead_code)]
fn main_pure() {
let transport = iota_streams::app_channels::api::tangle::BucketTransport::new();
println!("#######################################");
println!("Running pure tests without accessing Tangle");
println!("#######################################");
println!("\n");
let transport = Rc::new(RefCell::new(transport));
run_single_branch_test(transport.clone(), "PURESEEDA");
run_multi_branch_test(transport.clone(), "PURESEEDB");
println!("Done running pure tests without accessing Tangle");
println!("#######################################");
}
#[allow(dead_code)]
fn main_client() {
// Load or .env file, log message if we failed
if dotenv::dotenv().is_err() {
println!(".env file not found; copy and rename example.env to \".env\"");
};
// Parse env vars with a fallback
let node_url = env::var("URL").unwrap_or("http://localhost:14265".to_string());
let node_mwm: u8 = env::var("MWM").map(|s| s.parse().unwrap_or(14)).unwrap_or(14);
// Fails at unwrap when the url isnt working
// TODO: Fail gracefully
let client = Client::new_from_url(&node_url);
let mut transport = Rc::new(RefCell::new(client));
let mut send_opt = SendTrytesOptions::default();
send_opt.min_weight_magnitude = node_mwm;
transport.set_send_options(send_opt);
let alph9 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9";
let seed1: &str = &(0..10)
.map(|_| alph9.chars().nth(rand::thread_rng().gen_range(0, 27)).unwrap())
.collect::<String>();
let seed2: &str = &(0..10)
.map(|_| alph9.chars().nth(rand::thread_rng().gen_range(0, 27)).unwrap())
.collect::<String>();
println!("#######################################");
println!("Running tests accessing Tangle via node {}", &node_url);
println!("#######################################");
println!("\n");
run_single_branch_test(transport.clone(), seed1);
run_multi_branch_test(transport.clone(), seed2);
println!("Done running tests accessing Tangle via node {}", &node_url);
println!("#######################################");
}
fn main() {
//main_pure();
main_client();
}