3
3
4
4
use futures:: SinkExt ;
5
5
use proptest_state_machine:: ReferenceStateMachine ;
6
- use reference:: AssosiatedData ;
6
+ use reference:: { AssosiatedData , Transition } ;
7
7
use tokio:: runtime:: Runtime ;
8
8
9
9
use crate :: {
@@ -13,6 +13,8 @@ use crate::{
13
13
pub mod reference;
14
14
mod stream_mock;
15
15
16
+ const BLOCKS_NEW_LEN : usize = 11 ;
17
+
16
18
struct TheSut {
17
19
main_sim : crate :: mpsc:: Receiver < PeerTaskToMain > ,
18
20
// h: PeerLoopHandler,
@@ -25,6 +27,7 @@ struct TheSut {
25
27
g : GlobalStateLock ,
26
28
peer_address : std:: net:: SocketAddr ,
27
29
// h: PeerLoopHandler,
30
+ stopped : bool ,
28
31
}
29
32
impl proptest_state_machine:: StateMachineTest for TheSut {
30
33
type SystemUnderTest = Self ;
@@ -83,6 +86,7 @@ impl proptest_state_machine::StateMachineTest for TheSut {
83
86
g : g. clone ( ) ,
84
87
peer_address,
85
88
// h
89
+ stopped : false ,
86
90
}
87
91
}
88
92
@@ -91,6 +95,9 @@ impl proptest_state_machine::StateMachineTest for TheSut {
91
95
_ref_state : & <Self :: Reference as ReferenceStateMachine >:: State ,
92
96
transition : <Self :: Reference as ReferenceStateMachine >:: Transition ,
93
97
) -> Self :: SystemUnderTest {
98
+ if state. stopped {
99
+ return state;
100
+ }
94
101
let Self {
95
102
// mut h,
96
103
mut main_sim,
@@ -103,14 +110,54 @@ impl proptest_state_machine::StateMachineTest for TheSut {
103
110
g,
104
111
peer_address,
105
112
// h
113
+ mut stopped,
106
114
} = state;
107
115
116
+ let mut g_cloned = g. clone ( ) ;
117
+ let mut blocks_stuff = async |bs : Vec < crate :: models:: blockchain:: block:: Block > | {
118
+ let jq = g_cloned. vm_job_queue ( ) . clone ( ) ;
119
+ let mut g_guard = g_cloned. lock_guard_mut ( ) . await ;
120
+ for b in bs {
121
+ dbg ! ( g_guard. set_new_tip( b) . await . unwrap( ) )
122
+ . into_iter ( )
123
+ . for_each ( |j| {
124
+ rt. block_on ( async {
125
+ j. upgrade ( & jq, Default :: default ( ) ) . await . unwrap ( ) ;
126
+ } )
127
+ } ) ;
128
+ }
129
+ } ;
130
+ // this gives a path problem
131
+ // let mut g_cloned = g.clone();
132
+ // let mut blocks_stuff_t = async |bs: Vec<crate::models::blockchain::block::Block>| {
133
+ // let mut g_guard = g_cloned.lock_guard_mut().await;
134
+ // let archival = g_guard.chain.archival_state_mut();
135
+ // for b in bs {
136
+ // crate::tests::shared::add_block_to_archival_state(archival, b).await.unwrap();
137
+ // }
138
+ // };
139
+ #[ allow( clippy:: shadow_unrelated) ]
108
140
let g_cloned = g. clone ( ) ;
109
141
110
- if let Some ( AssosiatedData :: Randomness ( _r) ) = transition. 1 {
111
- todo ! ( "h.set_rng(StdRng::from(r));" ) ;
112
- }
113
142
rt. block_on ( async {
143
+ dbg ! ( & transition) ;
144
+ match transition {
145
+ Transition ( _, Some ( AssosiatedData :: MakeNewBlocks ( ..) ) ) => {
146
+ // blocks_stuff(ref_state.blocks[ref_state.blocks.len()-1 - BLOCKS_NEW_LEN..].into()).await;
147
+
148
+ // let mut g_guard = g_cloned.lock_guard_mut().await;
149
+ // let l = ref_state.blocks.len();
150
+ // for i in BLOCKS_NEW_LEN..1 {
151
+ // // let _ = g_guard.store_block_not_tip(ref_state.blocks[l-1 -i].clone());
152
+ // }
153
+ // // let _ = dbg!(g_guard.set_new_tip(ref_state.blocks[l-1].clone()).await);
154
+ }
155
+ Transition ( _, Some ( AssosiatedData :: NewBlock ( b) ) ) => {
156
+ blocks_stuff ( vec ! [ b] ) . await ;
157
+ }
158
+ _ => { }
159
+ } ;
160
+
114
161
// h.handle_peer_message_test(transition, &mut sink, &mut counter)
115
162
sock. send ( transition. 0 ) . await . unwrap ( ) ;
116
163
@@ -126,6 +173,18 @@ impl proptest_state_machine::StateMachineTest for TheSut {
126
173
// .standing;
127
174
// PeerTaskToMain::,
128
175
// ];
176
+
177
+ if let Some ( crate :: models:: peer:: peer_info:: PeerInfo { standing, .. } ) = g_cloned
178
+ . lock_guard ( )
179
+ . await
180
+ . net
181
+ . peer_map
182
+ . get ( & state. peer_address )
183
+ {
184
+ if standing. is_bad ( ) {
185
+ stopped = true ;
186
+ }
187
+ }
129
188
} ) ;
130
189
131
190
Self {
@@ -136,6 +195,7 @@ impl proptest_state_machine::StateMachineTest for TheSut {
136
195
g,
137
196
peer_address,
138
197
// h
198
+ stopped,
139
199
}
140
200
}
141
201
}
0 commit comments