1
1
use crate :: common:: {
2
2
configuration:: genesis_model:: Fund ,
3
+ data:: address:: { Account , AddressDataProvider , Utxo } ,
3
4
jcli_wrapper,
4
5
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
+ } ,
6
9
startup,
7
10
} ;
8
11
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
+
9
71
#[ test]
10
72
pub fn test_node_recovers_from_node_restart ( ) {
11
73
let sender = startup:: create_new_utxo_address ( ) ;
@@ -21,47 +83,41 @@ pub fn test_node_recovers_from_node_restart() {
21
83
22
84
let jormungandr = Starter :: new ( ) . config ( config. clone ( ) ) . start ( ) . unwrap ( ) ;
23
85
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) ;
25
90
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
+ }
33
97
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 ( ) ;
35
103
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 ( ) ;
42
110
43
- let jormungandr = restart_jormungandr_node_as_leader ( jormungandr ) ;
111
+ let jormungandr = Starter :: new ( ) . config ( config . clone ( ) ) . start ( ) . unwrap ( ) ;
44
112
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) ;
51
117
52
118
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
66
122
) ;
67
123
}
0 commit comments