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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2022 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.
use ;
use Keypair;
use future;
use crate;
use HashSet;
use time;
use *;
use XOR_NAME_LEN;
use crateelder_count;
/*
#[tokio::test(flavor = "multi_thread")]
async fn test_genesis_node() -> Result<()> {
let keypair = Keypair::generate(&mut rand::thread_rng());
let (node, mut event_stream) = create_node(Config {
first: true,
keypair: Some(keypair),
..Default::default()
})
.await?;
assert_next_event!(event_stream, Event::EldersChanged { .. });
assert!(node.is_elder().await);
assert_eq!(node.name().await[XOR_NAME_LEN - 1], 255);
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn test_node_bootstrapping() -> Result<()> {
let (genesis_node, mut event_stream) = create_node(Config {
first: true,
..Default::default()
})
.await?;
// spawn genesis node events listener
let genesis_handler = tokio::spawn(async move {
assert_next_event!(event_stream, Event::EldersChanged { .. });
assert_next_event!(event_stream, Event::MemberJoined { .. });
});
// bootstrap a second node with genesis
let genesis_contact = genesis_node.our_connection_info();
let (node1, _event_stream) = create_node(config_with_contact(genesis_contact)).await?;
// just await for genesis node to finish receiving all events
genesis_handler.await?;
let elder_size = 2;
verify_invariants_for_node(&genesis_node, elder_size).await?;
verify_invariants_for_node(&node1, elder_size).await?;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn test_startup_section_bootstrapping() -> Result<()> {
// Create the genesis node.
let (genesis_node, mut event_stream) = create_node(Config {
first: true,
..Default::default()
})
.await?;
let other_node_count =elder_count() - 1;
// Then add more nodes to form a section. Because there is only `elder_count()` nodes in total,
// we expect every one to be promoted to elder.
let genesis_contact = genesis_node.our_connection_info();
let nodes_joining_tasks = (0..other_node_count).map(|_| async {
let (node, mut event_stream) = create_node(config_with_contact(genesis_contact)).await?;
assert_event!(
event_stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);
Ok::<_, Error>(node)
});
let other_nodes = future::try_join_all(nodes_joining_tasks).await?;
// Keep track of the joined nodes the genesis node knows about.
let mut joined_names = HashSet::new();
// Keep listening to the events from the genesis node until it becomes aware of all the other
// nodes in the section.
while let Some(event) = time::timeout(TIMEOUT, event_stream.next()).await? {
let _ = match event {
Event::MemberJoined { name, .. } => joined_names.insert(name),
Event::MemberLeft { name, .. } => joined_names.remove(&name),
_ => false,
};
let actual_names: HashSet<_> = future::join_all(other_nodes.iter().map(|node| node.name()))
.await
.into_iter()
.collect();
if joined_names == actual_names {
return Ok(());
}
}
panic!("event stream unexpectedly closed")
}
// Test that the first `elder_count()` nodes in the network are promoted to elders.
#[tokio::test(flavor = "multi_thread")]
async fn test_startup_elders() -> Result<()> {
let mut nodes = create_connected_nodes(elder_count()).await?;
future::join_all(nodes.iter_mut().map(|(node, stream)| async move {
if node.is_elder().await {
return;
}
assert_event!(
stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
)
}))
.await;
Ok(())
}
*/