1717 QuorumId , ser_uint256
1818from test_framework .test_framework import DashTestFramework
1919from test_framework .util import (
20- assert_equal , p2p_port
20+ assert_equal , assert_greater_than_or_equal , p2p_port
2121)
2222
2323
@@ -46,7 +46,7 @@ def getmnlistdiff(self, baseBlockHash, blockHash):
4646
4747class LLMQEvoNodesTest (DashTestFramework ):
4848 def set_test_params (self ):
49- self .set_dash_test_params (5 , 4 , fast_dip3_enforcement = True , evo_count = 7 )
49+ self .set_dash_test_params (5 , 4 , fast_dip3_enforcement = True , evo_count = 5 )
5050 self .set_dash_llmq_test_params (4 , 4 )
5151
5252 def run_test (self ):
@@ -92,7 +92,7 @@ def run_test(self):
9292 self .mine_cycle_quorum (llmq_type_name = 'llmq_test_dip0024' , llmq_type = 103 )
9393
9494 evo_protxhash_list = list ()
95- for i in range (5 ):
95+ for i in range (self . evo_count ):
9696 evo_info = self .dynamically_add_masternode (evo = True )
9797 evo_protxhash_list .append (evo_info .proTxHash )
9898 self .nodes [0 ].generate (8 )
@@ -115,6 +115,7 @@ def run_test(self):
115115
116116 self .log .info ("Test that EvoNodes are paid 4x blocks in a row" )
117117 self .test_evo_payments (window_analysis = 48 )
118+ self .test_masternode_winners ()
118119
119120 self .activate_v20 ()
120121 self .activate_mn_rr ()
@@ -127,6 +128,7 @@ def run_test(self):
127128
128129 self .log .info ("Test that EvoNodes are paid 1 block in a row after MN RewardReallocation activation" )
129130 self .test_evo_payments (window_analysis = 48 , v20active = True )
131+ self .test_masternode_winners (mn_rr_active = True )
130132
131133 self .log .info (self .nodes [0 ].masternodelist ())
132134
@@ -248,6 +250,40 @@ def test_masternode_count(self, expected_mns_count, expected_evo_count):
248250 assert_equal (detailed_count ['regular' ]['total' ], expected_mns_count )
249251 assert_equal (detailed_count ['evo' ]['total' ], expected_evo_count )
250252
253+ def test_masternode_winners (self , mn_rr_active = False ):
254+ # ignore recent winners, test future ones only
255+ # we get up to 21 entries here: tip + up to 20 future payees
256+ winners = self .nodes [0 ].masternode ('winners' , '0' )
257+ weighted_count = self .mn_count + self .evo_count * (1 if mn_rr_active else 4 )
258+ assert_equal (len (winners .keys ()) - 1 , 20 if weighted_count > 20 else weighted_count )
259+ consecutive_payments = 0
260+ full_consecutive_payments_found = 0
261+ payment_cycles = 0
262+ first_payee = None
263+ prev_winner = None
264+ for height in winners .keys ():
265+ winner = winners [height ]
266+ if mn_rr_active :
267+ assert_equal (prev_winner == winner , False )
268+ else :
269+ if prev_winner == winner :
270+ consecutive_payments += 1
271+ else :
272+ if consecutive_payments == 3 :
273+ full_consecutive_payments_found += 1
274+ consecutive_payments = 0
275+ assert_greater_than_or_equal (3 , consecutive_payments )
276+ if consecutive_payments == 0 and winner == first_payee :
277+ payment_cycles += 1
278+ if first_payee is None :
279+ first_payee = winner
280+ prev_winner = winner
281+ if mn_rr_active :
282+ assert_equal (full_consecutive_payments_found , 0 )
283+ else :
284+ assert_greater_than_or_equal (full_consecutive_payments_found , (len (winners .keys ()) - 1 - self .mn_count ) // 4 - 1 )
285+ assert_equal (payment_cycles , (len (winners .keys ()) - 1 ) // weighted_count )
286+
251287 def test_getmnlistdiff (self , baseBlockHash , blockHash , baseMNList , expectedDeleted , expectedUpdated ):
252288 d = self .test_getmnlistdiff_base (baseBlockHash , blockHash )
253289
0 commit comments