2525
2626class MnehfTest (DashTestFramework ):
2727 def set_test_params (self ):
28- extra_args = [["-vbparams=testdummy:0:999999999999:12:12:12:5:0" ] for _ in range (4 )]
28+ extra_args = [["-vbparams=testdummy:0:999999999999:12:12:12:5:0" , "-persistmempool=0" ] for _ in range (4 )]
2929 self .set_dash_test_params (4 , 3 , fast_dip3_enforcement = True , extra_args = extra_args )
3030
3131 def skip_test_if_missing_module (self ):
@@ -164,14 +164,12 @@ def run_test(self):
164164 ehf_tx_sent = self .send_tx (ehf_tx )
165165 ehf_unknown_tx_sent = self .send_tx (ehf_unknown_tx )
166166 self .send_tx (ehf_invalid_tx , expected_error = 'bad-mnhf-non-ehf' )
167- node .generate (1 )
168- ehf_height = node .getblockcount ()
167+ ehf_blockhash = node .generate (1 )[0 ]
169168 self .sync_all ()
170169
171- ehf_block = node .getbestblockhash ()
172- self .log .info (f"Check MnEhfTx { ehf_tx_sent } was mined in { ehf_block } " )
173- assert ehf_tx_sent in node .getblock (ehf_block )['tx' ]
174- assert ehf_unknown_tx_sent in node .getblock (ehf_block )['tx' ]
170+ self .log .info (f"Check MnEhfTx { ehf_tx_sent } was mined in { ehf_blockhash } " )
171+ assert ehf_tx_sent in node .getblock (ehf_blockhash )['tx' ]
172+ assert ehf_unknown_tx_sent in node .getblock (ehf_blockhash )['tx' ]
175173
176174 self .log .info (f"MnEhf tx: '{ ehf_tx } ' is sent: { ehf_tx_sent } " )
177175 self .log .info (f"MnEhf 'unknown' tx: '{ ehf_unknown_tx } ' is sent: { ehf_unknown_tx_sent } " )
@@ -201,10 +199,10 @@ def run_test(self):
201199
202200 self .check_fork ('active' )
203201
204- block_fork_active = node .getbestblockhash ()
205- self .log .info (f"Invalidate block: { ehf_block } with tip { block_fork_active } " )
202+ fork_active_blockhash = node .getbestblockhash ()
203+ self .log .info (f"Invalidate block: { ehf_blockhash } with tip { fork_active_blockhash } " )
206204 for inode in self .nodes :
207- inode .invalidateblock (ehf_block )
205+ inode .invalidateblock (ehf_blockhash )
208206
209207 self .log .info ("Expecting for fork to be defined in next blocks because no MnEHF tx here" )
210208 for i in range (12 ):
@@ -215,12 +213,11 @@ def run_test(self):
215213
216214 self .log .info ("Re-sending MnEHF for new fork" )
217215 tx_sent_2 = self .send_tx (ehf_tx )
218- node .generate (1 )
216+ ehf_blockhash_2 = node .generate (1 )[ 0 ]
219217 self .sync_all ()
220218
221- ehf_block_2 = node .getbestblockhash ()
222- self .log .info (f"Check MnEhfTx again { tx_sent_2 } was mined in { ehf_block_2 } " )
223- assert tx_sent_2 in node .getblock (ehf_block_2 )['tx' ]
219+ self .log .info (f"Check MnEhfTx again { tx_sent_2 } was mined in { ehf_blockhash_2 } " )
220+ assert tx_sent_2 in node .getblock (ehf_blockhash_2 )['tx' ]
224221
225222 self .log .info (f"Generate some more block to jump to `started` status" )
226223 for i in range (12 ):
@@ -230,42 +227,43 @@ def run_test(self):
230227 self .check_fork ('started' )
231228
232229
233- self .log .info (f"Re-consider block { ehf_block } to the old MnEHF and forget new fork" )
230+ self .log .info (f"Re-consider block { ehf_blockhash } to the old MnEHF and forget new fork" )
234231 for inode in self .nodes :
235- inode .reconsiderblock (ehf_block )
236- assert_equal (node .getbestblockhash (), block_fork_active )
232+ inode .reconsiderblock (ehf_blockhash )
233+ assert_equal (node .getbestblockhash (), fork_active_blockhash )
237234
238235 self .check_fork ('active' )
239236 self .restart_all_nodes ()
240237 self .check_fork ('active' )
241238
239+ self .log .info ("Testing duplicate EHF signal with same bit" )
240+ ehf_tx_duplicate = self .send_tx (self .create_mnehf (28 , pubkey ))
241+ tip_blockhash = node .generate (1 )[0 ]
242+ self .sync_blocks ()
243+ block = node .getblock (tip_blockhash )
244+ assert ehf_tx_duplicate in node .getrawmempool () and ehf_tx_duplicate not in block ['tx' ]
245+
246+ self .log .info ("Testing EHF signal with same bit but with newer start time" )
242247 self .bump_mocktime (int (60 * 60 * 24 * 14 ))
243248 node .generate (1 )
244- self .sync_all ()
249+ self .sync_blocks ()
245250 self .restart_all_nodes (params = [self .mocktime , self .mocktime + 1000000 ])
246251 self .mine_quorum ()
247252
248- ehf_tx_second = self .create_mnehf (28 , pubkey )
249- assert_equal ( get_bip9_details ( node , 'testdummy' )[ 'status' ], 'defined' )
253+ ehf_tx_new_start = self .create_mnehf (28 , pubkey )
254+ self . check_fork ( 'defined' )
250255
251- self .log .info ("Testing EHF signal with same bit" )
252- self .log .info (f"Previous signal at height={ ehf_height } , total blocks={ node .getblockcount ()} , should success at { ehf_height + 576 } " )
253- self .slowly_generate_batch (576 - (node .getblockcount () - ehf_height ) - 1 )
254- ehf_tx_sent = self .send_tx (ehf_tx_second )
255- self .log .info ("Mine block and ensure not mined yet..." )
256- node .generate (1 )
257- self .ensure_tx_is_not_mined (ehf_tx_sent )
258- node .generate (1 )
256+ self .log .info ("Mine one block and ensure EHF tx for the new deployment is mined" )
257+ ehf_tx_sent = self .send_tx (ehf_tx_new_start )
258+ tip_blockhash = node .generate (1 )[0 ]
259259 self .sync_all ()
260- self .log .info ("Mine one more block and ensure it is mined" )
261- block = node .getblock (node .getbestblockhash ())
260+ block = node .getblock (tip_blockhash )
262261 assert ehf_tx_sent in block ['tx' ]
263262
264263 self .check_fork ('defined' )
265264 self .slowly_generate_batch (12 * 4 )
266265 self .check_fork ('active' )
267266
268267
269-
270268if __name__ == '__main__' :
271269 MnehfTest ().main ()
0 commit comments