@@ -363,11 +363,42 @@ def run_test (self):
363363 self .nodes [0 ].generate (1 )
364364
365365 # Make a long chain of unconfirmed payments without hitting mempool limit
366+ # Each tx we make leaves only one output of change on a chain 1 longer
367+ # Since the amount to send is always much less than the outputs, we only ever need one output
368+ # So we should be able to generate exactly chainlimit txs for each original output
369+ sending_addr = self .nodes [1 ].getnewaddress ()
366370 txid_list = []
367371 for i in range (chainlimit * 2 ):
368- txid_list .append (self .nodes [0 ].sendtoaddress (chain_addrs [ 0 ] , Decimal ('0.0001' )))
372+ txid_list .append (self .nodes [0 ].sendtoaddress (sending_addr , Decimal ('0.0001' )))
369373 assert_equal (self .nodes [0 ].getmempoolinfo ()['size' ], chainlimit * 2 )
370374 assert_equal (len (txid_list ), chainlimit * 2 )
371375
376+ # Without walletrejectlongchains, we will still generate a txid
377+ # The tx will be stored in the wallet but not accepted to the mempool
378+ extra_txid = self .nodes [0 ].sendtoaddress (sending_addr , Decimal ('0.0001' ))
379+ assert (extra_txid not in self .nodes [0 ].getrawmempool ())
380+ assert (extra_txid in [tx ["txid" ] for tx in self .nodes [0 ].listtransactions ()])
381+ self .nodes [0 ].abandontransaction (extra_txid )
382+ total_txs = len (self .nodes [0 ].listtransactions ("*" ,99999 ))
383+
384+ # Try with walletrejectlongchains
385+ # Double chain limit but require combining inputs, so we pass SelectCoinsMinConf
386+ stop_node (self .nodes [0 ],0 )
387+ self .nodes [0 ] = start_node (0 , self .options .tmpdir , ["-walletrejectlongchains" , "-limitancestorcount=" + str (2 * chainlimit )])
388+
389+ # wait for loadmempool
390+ timeout = 10
391+ while (timeout > 0 and len (self .nodes [0 ].getrawmempool ()) < chainlimit * 2 ):
392+ time .sleep (0.5 )
393+ timeout -= 0.5
394+ assert_equal (len (self .nodes [0 ].getrawmempool ()), chainlimit * 2 )
395+
396+ node0_balance = self .nodes [0 ].getbalance ()
397+ # With walletrejectlongchains we will not create the tx and store it in our wallet.
398+ assert_raises_message (JSONRPCException , "mempool chain" , self .nodes [0 ].sendtoaddress , sending_addr , node0_balance - Decimal ('0.01' ))
399+
400+ # Verify nothing new in wallet
401+ assert_equal (total_txs , len (self .nodes [0 ].listtransactions ("*" ,99999 )))
402+
372403if __name__ == '__main__' :
373404 WalletTest ().main ()
0 commit comments