Skip to content

Commit 3478f14

Browse files
authored
[Tests] Recovery new testcase (automation for #1011) (#1017)
* added few getters for jormungandr process and starter * added LedgerSnapthot struct to hold comparable data. introduced some helper method to avoid duplication. added new test case
1 parent d6de99e commit 3478f14

File tree

3 files changed

+103
-37
lines changed

3 files changed

+103
-37
lines changed

jormungandr-integration-tests/src/common/jormungandr/process.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ impl JormungandrProcess {
5454
pub fn rest_address(&self) -> String {
5555
self.config.get_node_address()
5656
}
57+
58+
pub fn config(&self) -> JormungandrConfig {
59+
self.config.clone()
60+
}
5761
}
5862

5963
impl Drop for JormungandrProcess {

jormungandr-integration-tests/src/common/jormungandr/starter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ impl Starter {
139139
self
140140
}
141141

142+
pub fn role(&mut self, role: Role) -> &mut Self {
143+
self.role = role;
144+
self
145+
}
146+
142147
pub fn verify_by(&mut self, verification_mode: StartupVerificationMode) -> &mut Self {
143148
self.verification_mode = verification_mode;
144149
self
@@ -258,12 +263,13 @@ impl Starter {
258263
}
259264
}
260265

261-
pub fn restart_jormungandr_node_as_leader(process: JormungandrProcess) -> JormungandrProcess {
266+
pub fn restart_jormungandr_node(process: JormungandrProcess, role: Role) -> JormungandrProcess {
262267
let config = process.config.clone();
263268
std::mem::drop(process);
264269

265270
Starter::new()
266271
.config(config)
272+
.role(role)
267273
.start()
268274
.expect("Jormungandr restart failed")
269275
}
Lines changed: 92 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,73 @@
11
use crate::common::{
22
configuration::genesis_model::Fund,
3+
data::address::{Account, AddressDataProvider, Utxo},
34
jcli_wrapper,
45
jcli_wrapper::jcli_transaction_wrapper::JCLITransactionWrapper,
5-
jormungandr::{starter::restart_jormungandr_node_as_leader, ConfigurationBuilder, Starter},
6+
jormungandr::{
7+
starter::restart_jormungandr_node, ConfigurationBuilder, JormungandrProcess, Role, Starter,
8+
},
69
startup,
710
};
811

12+
use jormungandr_lib::interfaces::{AccountState, SettingsDto, UTxOInfo};
13+
14+
#[derive(Clone, Debug)]
15+
struct LedgerSnapshot {
16+
settings: SettingsDto,
17+
utxos: Vec<UTxOInfo>,
18+
account_state: AccountState,
19+
}
20+
21+
impl PartialEq for LedgerSnapshot {
22+
fn eq(&self, other: &Self) -> bool {
23+
self.settings == other.settings
24+
&& self.utxos == other.utxos
25+
&& self.account_state == other.account_state
26+
}
27+
}
28+
impl Eq for LedgerSnapshot {}
29+
30+
impl LedgerSnapshot {
31+
pub fn new(settings: SettingsDto, utxos: Vec<UTxOInfo>, account_state: AccountState) -> Self {
32+
LedgerSnapshot {
33+
settings,
34+
utxos,
35+
account_state,
36+
}
37+
}
38+
}
39+
40+
fn take_snapshot(account_receiver: &Account, jormungandr: &JormungandrProcess) -> LedgerSnapshot {
41+
let settings = jcli_wrapper::assert_get_rest_settings(&jormungandr.rest_address());
42+
let utxos = jcli_wrapper::assert_rest_utxo_get(&jormungandr.rest_address());
43+
let account = jcli_wrapper::assert_rest_account_get_stats(
44+
&account_receiver.address,
45+
&jormungandr.rest_address(),
46+
);
47+
48+
LedgerSnapshot::new(settings, utxos, account)
49+
}
50+
51+
pub fn do_simple_transaction<T: AddressDataProvider>(
52+
sender: &T,
53+
account_receiver: &Account,
54+
utxo_receiver: &Utxo,
55+
jormungandr: &JormungandrProcess,
56+
) {
57+
let config = jormungandr.config();
58+
let utxo = startup::get_utxo_for_address(sender, &jormungandr.rest_address());
59+
60+
let transaction_message = JCLITransactionWrapper::new_transaction(&config.genesis_block_hash)
61+
.assert_add_input_from_utxo(&utxo)
62+
.assert_add_output(&account_receiver.address, &50.into())
63+
.assert_add_output(&utxo_receiver.address, &50.into())
64+
.assert_finalize()
65+
.seal_with_witness_for_address(sender)
66+
.assert_to_message();
67+
68+
jcli_wrapper::assert_transaction_in_block(&transaction_message, &jormungandr.rest_address());
69+
}
70+
971
#[test]
1072
pub fn test_node_recovers_from_node_restart() {
1173
let sender = startup::create_new_utxo_address();
@@ -21,47 +83,41 @@ pub fn test_node_recovers_from_node_restart() {
2183

2284
let jormungandr = Starter::new().config(config.clone()).start().unwrap();
2385

24-
let utxo = startup::get_utxo_for_address(&sender, &jormungandr.rest_address());
86+
do_simple_transaction(&sender, &account_receiver, &utxo_receiver, &jormungandr);
87+
let snapshot_before = take_snapshot(&account_receiver, &jormungandr);
88+
let jormungandr = restart_jormungandr_node(jormungandr, Role::Leader);
89+
let snapshot_after = take_snapshot(&account_receiver, &jormungandr);
2590

26-
let transaction_message = JCLITransactionWrapper::new_transaction(&config.genesis_block_hash)
27-
.assert_add_input_from_utxo(&utxo)
28-
.assert_add_output(&account_receiver.address, &50.into())
29-
.assert_add_output(&utxo_receiver.address, &50.into())
30-
.assert_finalize()
31-
.seal_with_witness_for_address(&sender)
32-
.assert_to_message();
91+
assert_eq!(
92+
snapshot_before, snapshot_after,
93+
"Different snaphot after restart {:?} vs {:?}",
94+
snapshot_before, snapshot_after
95+
);
96+
}
3397

34-
jcli_wrapper::assert_transaction_in_block(&transaction_message, &jormungandr.rest_address());
98+
#[test]
99+
pub fn test_node_recovers_kill_signal() {
100+
let sender = startup::create_new_utxo_address();
101+
let account_receiver = startup::create_new_account_address();
102+
let utxo_receiver = startup::create_new_utxo_address();
35103

36-
let expected_settings = jcli_wrapper::assert_get_rest_settings(&jormungandr.rest_address());
37-
let expected_utxos = jcli_wrapper::assert_rest_utxo_get(&jormungandr.rest_address());
38-
let expected_account_state = jcli_wrapper::assert_rest_account_get_stats(
39-
&account_receiver.address,
40-
&jormungandr.rest_address(),
41-
);
104+
let config = ConfigurationBuilder::new()
105+
.with_funds(vec![Fund {
106+
address: sender.address.clone(),
107+
value: 100.into(),
108+
}])
109+
.build();
42110

43-
let jormungandr = restart_jormungandr_node_as_leader(jormungandr);
111+
let jormungandr = Starter::new().config(config.clone()).start().unwrap();
44112

45-
let actual_settings = jcli_wrapper::assert_get_rest_settings(&jormungandr.rest_address());
46-
let actual_utxos = jcli_wrapper::assert_rest_utxo_get(&jormungandr.rest_address());
47-
let actual_account_state = jcli_wrapper::assert_rest_account_get_stats(
48-
&account_receiver.address,
49-
&jormungandr.rest_address(),
50-
);
113+
do_simple_transaction(&sender, &account_receiver, &utxo_receiver, &jormungandr);
114+
let snapshot_before = take_snapshot(&account_receiver, &jormungandr);
115+
let jormungandr = restart_jormungandr_node(jormungandr, Role::Passive);
116+
let snapshot_after = take_snapshot(&account_receiver, &jormungandr);
51117

52118
assert_eq!(
53-
actual_settings, expected_settings,
54-
"Different setting after restart {:?} vs {:?}",
55-
actual_settings, expected_settings
56-
);
57-
assert_eq!(
58-
actual_utxos, expected_utxos,
59-
"Different utxos after restart {:?} vs {:?}",
60-
actual_utxos, expected_utxos
61-
);
62-
assert_eq!(
63-
actual_account_state, expected_account_state,
64-
"Different account state after restart {:?} vs {:?}",
65-
actual_account_state, expected_account_state
119+
snapshot_before, snapshot_after,
120+
"Different snaphot after restart {:?} vs {:?}",
121+
snapshot_before, snapshot_after
66122
);
67123
}

0 commit comments

Comments
 (0)