@@ -125,7 +125,7 @@ def run_test(self):
125125 assert_equal ('6.00' , spending_address_last_7d )
126126 assert_equal ('4.00' , staking_address_last_7d )
127127
128- # Load the averages for stake amounts
128+ # Load the averages for stake amounts
129129 avg_last7d = self .nodes [0 ].getstakereport ()['Last 7 Days Avg' ]
130130 avg_last30d = self .nodes [0 ].getstakereport ()['Last 30 Days Avg' ]
131131 avg_last365d = self .nodes [0 ].getstakereport ()['Last 365 Days Avg' ]
@@ -161,7 +161,7 @@ def run_test(self):
161161 assert_equal ('2.00' , spending_address_last_7d )
162162 assert_equal ('2.00' , staking_address_last_7d )
163163
164- # Load the averages for stake amounts
164+ # Load the averages for stake amounts
165165 avg_last7d = self .nodes [0 ].getstakereport ()['Last 7 Days Avg' ]
166166 avg_last30d = self .nodes [0 ].getstakereport ()['Last 30 Days Avg' ]
167167 avg_last365d = self .nodes [0 ].getstakereport ()['Last 365 Days Avg' ]
@@ -197,7 +197,7 @@ def run_test(self):
197197 assert_equal ('0.00' , spending_address_last_7d )
198198 assert_equal ('0.00' , staking_address_last_7d )
199199
200- # Load the averages for stake amounts
200+ # Load the averages for stake amounts
201201 avg_last7d = self .nodes [0 ].getstakereport ()['Last 7 Days Avg' ]
202202 avg_last30d = self .nodes [0 ].getstakereport ()['Last 30 Days Avg' ]
203203 avg_last365d = self .nodes [0 ].getstakereport ()['Last 365 Days Avg' ]
@@ -207,7 +207,34 @@ def run_test(self):
207207 assert_equal ('0.06666666' , avg_last30d )
208208 assert_equal ('0.19354838' , avg_last365d )
209209
210- def stake_block (self , node ):
210+ # Disconnect the nodes
211+ for node in self .nodes [0 ].getpeerinfo ():
212+ self .nodes [0 ].disconnectnode (node ['addr' ])
213+ time .sleep (2 ) #disconnecting a node needs a little bit of time
214+ assert (self .nodes [0 ].getpeerinfo () == [])
215+
216+ # Stake a block on node 0
217+ orphaned_block_hash = self .stake_block (self .nodes [0 ], False )
218+
219+ # Generate some blocks on node 1
220+ self .nodes [1 ].generate (100 )
221+
222+ # Reconnect the nodes
223+ connect_nodes (self .nodes [0 ], 1 )
224+ connect_nodes (self .nodes [1 ], 2 )
225+ connect_nodes (self .nodes [2 ], 0 )
226+
227+ # Wait for blocks to sync
228+ self .sync_all ()
229+
230+ # Make sure the block was orphaned
231+ assert (self .nodes [0 ].getblock (orphaned_block_hash )['confirmations' ] == - 1 )
232+
233+ # Check the staked amount
234+ # Should be 0 (Zero) as the last staked block is orphaned
235+ assert_equal ('0.00' , self .nodes [0 ].getstakereport ()['Last 7 Days' ])
236+
237+ def stake_block (self , node , mature = True ):
211238 # Get the current block count to check against while we wait for a stake
212239 blockcount = node .getblockcount ()
213240
@@ -225,9 +252,17 @@ def stake_block(self, node):
225252 # Turn staking off
226253 node .staking (False )
227254
228- # Make sure the blocks are mature before we check the report
229- slow_gen (node , 5 , 0.5 )
230- self .sync_all ()
255+ # Get the staked block
256+ block_hash = node .getbestblockhash ()
257+
258+ # Only mature the blocks if we asked for it
259+ if (mature ):
260+ # Make sure the blocks are mature before we check the report
261+ slow_gen (node , 5 , 0.5 )
262+ self .sync_all ()
263+
264+ # return the block hash to the function caller
265+ return block_hash
231266
232267
233268if __name__ == '__main__' :
0 commit comments