Skip to content

Commit ef78887

Browse files
authored
[Jormungandr-scenario-test] fix failing tests from nighly run (#1168)
* clean imports & warnings * added more ? instead of unwrap. decreased iter limits
1 parent c57466d commit ef78887

File tree

8 files changed

+74
-214
lines changed

8 files changed

+74
-214
lines changed

jormungandr-scenario-tests/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[macro_use]
22
extern crate jormungandr_scenario_tests;
3-
4-
#[macro_use]
53
extern crate jormungandr_integration_tests;
64

75
use jormungandr_scenario_tests::{

jormungandr-scenario-tests/src/node.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use chain_impl_mockchain::{
77
};
88
use indicatif::ProgressBar;
99
use jormungandr_integration_tests::mock::{client::JormungandrClient, read_into};
10-
use jormungandr_lib::interfaces::{FragmentLog, FragmentStatus, Stats};
11-
#[macro_use]
1210
use jormungandr_integration_tests::response_to_vec;
11+
use jormungandr_lib::interfaces::{FragmentLog, FragmentStatus, Stats};
1312
use rand_core::RngCore;
1413
use std::{
1514
collections::HashMap,

jormungandr-scenario-tests/src/scenarios_repository.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub enum ScenarioResult {
121121
}
122122

123123
impl ScenarioResult {
124-
pub fn Failed<S: Into<String>>(reason: S) -> Self {
124+
pub fn failed<S: Into<String>>(reason: S) -> Self {
125125
ScenarioResult::Failed(reason.into())
126126
}
127127

@@ -160,16 +160,12 @@ fn scenarios_repository() -> HashMap<String, ScenarioMethod> {
160160
two_transaction_to_two_leaders,
161161
);
162162
map.insert("transaction_to_passive".to_string(), transaction_to_passive);
163-
map.insert("leader_is_offline".to_string(), leader_is_offline);
164-
map.insert(
165-
"leader_is_online_with_delay".to_string(),
166-
leader_is_online_with_delay,
167-
);
168163
map.insert("leader_restart".to_string(), leader_restart);
169164
map.insert(
170165
"passive_node_is_updated".to_string(),
171166
passive_node_is_updated,
172167
);
168+
map.insert("fully_connected".to_string(), fully_connected);
173169
map.insert("star".to_string(), star);
174170
map.insert("ring".to_string(), ring);
175171
map.insert("mesh".to_string(), mesh);

jormungandr-scenario-tests/src/test/comm/leader_leader.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,30 @@ pub fn two_transaction_to_two_leaders(mut context: Context<ChaChaRng>) -> Result
3030
}
3131
};
3232

33-
let mut controller = scenario_settings.build(context).unwrap();
33+
let mut controller = scenario_settings.build(context)?;
3434

35-
let leader_1 = controller
36-
.spawn_node(LEADER_1, LeadershipMode::Leader, PersistenceMode::InMemory)
37-
.unwrap();
38-
let leader_2 = controller
39-
.spawn_node(LEADER_2, LeadershipMode::Leader, PersistenceMode::InMemory)
40-
.unwrap();
35+
let leader_1 =
36+
controller.spawn_node(LEADER_1, LeadershipMode::Leader, PersistenceMode::InMemory)?;
37+
let leader_2 =
38+
controller.spawn_node(LEADER_2, LeadershipMode::Leader, PersistenceMode::InMemory)?;
4139

4240
leader_2.wait_for_bootstrap()?;
4341
leader_1.wait_for_bootstrap()?;
4442
controller.monitor_nodes();
4543

46-
let mut wallet1 = controller.wallet("delegated2").unwrap();
47-
let mut wallet2 = controller.wallet("delegated1").unwrap();
44+
let mut wallet1 = controller.wallet("delegated2")?;
45+
let mut wallet2 = controller.wallet("delegated1")?;
4846

49-
for _ in 0..40 {
50-
let check1 = controller
51-
.wallet_send_to(&mut wallet1, &wallet2, &leader_1, 1_000.into())
52-
.unwrap();
47+
for _ in 0..10 {
48+
let check1 = controller.wallet_send_to(&mut wallet1, &wallet2, &leader_1, 1_000.into())?;
5349

54-
let check2 = controller
55-
.wallet_send_to(&mut wallet2, &wallet1, &leader_2, 1_000.into())
56-
.unwrap();
50+
let check2 = controller.wallet_send_to(&mut wallet2, &wallet1, &leader_2, 1_000.into())?;
5751

58-
let status_1 = leader_1.wait_fragment(Duration::from_secs(2), check1);
59-
let status_2 = leader_2.wait_fragment(Duration::from_secs(2), check2);
52+
let status_1 = leader_1.wait_fragment(Duration::from_secs(2), check1)?;
53+
let status_2 = leader_2.wait_fragment(Duration::from_secs(2), check2)?;
6054

61-
if status_1.is_err() || status_2.is_err() {
62-
break;
63-
}
64-
65-
let status_1 = status_1.unwrap();
66-
let status_2 = status_2.unwrap();
67-
68-
if !status_1.is_in_a_block() || !status_2.is_in_a_block() {
69-
break;
70-
}
55+
utils::assert_is_in_block(status_1, &leader_1)?;
56+
utils::assert_is_in_block(status_2, &leader_2)?;
7157

7258
wallet1.confirm_transaction();
7359
wallet2.confirm_transaction();

jormungandr-scenario-tests/src/test/comm/passive_leader.rs

Lines changed: 8 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -40,125 +40,20 @@ pub fn transaction_to_passive(mut context: Context<ChaChaRng>) -> Result<Scenari
4040
passive.wait_for_bootstrap()?;
4141

4242
let mut wallet1 = controller.wallet("unassigned1")?;
43-
let wallet2 = controller.wallet("delegated1")?;
44-
45-
utils::sending_transactions_to_node_sequentially(
46-
20,
47-
&mut controller,
48-
&mut wallet1,
49-
&wallet2,
50-
&passive,
51-
)?;
52-
53-
utils::assert_are_in_sync(vec![&passive, &leader])?;
54-
55-
passive.shutdown()?;
56-
leader.shutdown()?;
57-
controller.finalize();
58-
Ok(ScenarioResult::Passed)
59-
}
60-
61-
pub fn leader_is_offline(mut context: Context<ChaChaRng>) -> Result<ScenarioResult> {
62-
let scenario_settings = prepare_scenario! {
63-
"L2002-leader_is_offline_while_passive_receives_tx",
64-
&mut context,
65-
topology [
66-
LEADER,
67-
PASSIVE -> LEADER,
68-
]
69-
blockchain {
70-
consensus = GenesisPraos,
71-
number_of_slots_per_epoch = 60,
72-
slot_duration = 1,
73-
leaders = [ LEADER],
74-
initials = [
75-
account "unassigned1" with 500_000_000,
76-
account "delegated1" with 2_000_000_000 delegates to LEADER,
77-
],
78-
}
79-
};
80-
81-
let mut controller = scenario_settings.build(context)?;
82-
83-
controller.monitor_nodes();
84-
let passive =
85-
controller.spawn_node(PASSIVE, LeadershipMode::Passive, PersistenceMode::InMemory)?;
86-
87-
passive.wait_for_bootstrap()?;
88-
89-
let mut wallet1 = controller.wallet("unassigned1")?;
90-
let wallet2 = controller.wallet("delegated1")?;
91-
92-
utils::sending_transactions_to_node_sequentially(
93-
40,
94-
&mut controller,
95-
&mut wallet1,
96-
&wallet2,
97-
&passive,
98-
)?;
99-
100-
passive.shutdown()?;
101-
102-
controller.finalize();
103-
Ok(ScenarioResult::Passed)
104-
}
105-
106-
pub fn leader_is_online_with_delay(mut context: Context<ChaChaRng>) -> Result<ScenarioResult> {
107-
let scenario_settings = prepare_scenario! {
108-
"L2003-leader_is_online_with_delay",
109-
&mut context,
110-
topology [
111-
LEADER,
112-
PASSIVE -> LEADER,
113-
]
114-
blockchain {
115-
consensus = GenesisPraos,
116-
number_of_slots_per_epoch = 60,
117-
slot_duration = 1,
118-
leaders = [ LEADER],
119-
initials = [
120-
account "unassigned1" with 500_000_000,
121-
account "delegated1" with 2_000_000_000 delegates to LEADER,
122-
],
123-
}
124-
};
125-
126-
let mut controller = scenario_settings.build(context)?;
127-
128-
controller.monitor_nodes();
129-
let passive =
130-
controller.spawn_node(PASSIVE, LeadershipMode::Passive, PersistenceMode::InMemory)?;
131-
132-
passive.wait_for_bootstrap()?;
133-
134-
let mut wallet1 = controller.wallet("unassigned1")?;
135-
let wallet2 = controller.wallet("delegated1")?;
43+
let mut wallet2 = controller.wallet("delegated1")?;
13644

13745
utils::sending_transactions_to_node_sequentially(
13846
10,
13947
&mut controller,
14048
&mut wallet1,
141-
&wallet2,
142-
&passive,
143-
)?;
144-
145-
let leader =
146-
controller.spawn_node(LEADER, LeadershipMode::Leader, PersistenceMode::InMemory)?;
147-
leader.wait_for_bootstrap()?;
148-
149-
utils::sending_transactions_to_node_sequentially(
150-
40,
151-
&mut controller,
152-
&mut wallet1,
153-
&wallet2,
49+
&mut wallet2,
15450
&passive,
15551
)?;
15652

15753
utils::assert_are_in_sync(vec![&passive, &leader])?;
15854

15955
passive.shutdown()?;
16056
leader.shutdown()?;
161-
16257
controller.finalize();
16358
Ok(ScenarioResult::Passed)
16459
}
@@ -195,13 +90,13 @@ pub fn leader_restart(mut context: Context<ChaChaRng>) -> Result<ScenarioResult>
19590
passive.wait_for_bootstrap()?;
19691

19792
let mut wallet1 = controller.wallet("unassigned1")?;
198-
let wallet2 = controller.wallet("delegated1")?;
93+
let mut wallet2 = controller.wallet("delegated1")?;
19994

20095
utils::sending_transactions_to_node_sequentially(
20196
10,
20297
&mut controller,
20398
&mut wallet1,
204-
&wallet2,
99+
&mut wallet2,
205100
&passive,
206101
)?;
207102

@@ -211,7 +106,7 @@ pub fn leader_restart(mut context: Context<ChaChaRng>) -> Result<ScenarioResult>
211106
10,
212107
&mut controller,
213108
&mut wallet1,
214-
&wallet2,
109+
&mut wallet2,
215110
&passive,
216111
)?;
217112

@@ -222,7 +117,7 @@ pub fn leader_restart(mut context: Context<ChaChaRng>) -> Result<ScenarioResult>
222117
10,
223118
&mut controller,
224119
&mut wallet1,
225-
&wallet2,
120+
&mut wallet2,
226121
&passive,
227122
)?;
228123

@@ -267,13 +162,13 @@ pub fn passive_node_is_updated(mut context: Context<ChaChaRng>) -> Result<Scenar
267162
passive.wait_for_bootstrap()?;
268163

269164
let mut wallet1 = controller.wallet("unassigned1")?;
270-
let wallet2 = controller.wallet("delegated1")?;
165+
let mut wallet2 = controller.wallet("delegated1")?;
271166

272167
utils::sending_transactions_to_node_sequentially(
273168
40,
274169
&mut controller,
275170
&mut wallet1,
276-
&wallet2,
171+
&mut wallet2,
277172
&leader,
278173
)?;
279174

0 commit comments

Comments
 (0)