@@ -25,6 +25,8 @@ def run_test(self):
2525 # Check the failure conditions for setautocombinethreshold
2626 assert_raises_rpc_error (- 8 , "Missing threshold value" , self .nodes [0 ].setautocombinethreshold , True )
2727 assert_raises_rpc_error (- 8 , "The threshold value cannot be less than 1.00" , self .nodes [0 ].setautocombinethreshold , True , 0.99 )
28+ assert_raises_rpc_error (- 8 , "Frequency must be greater than 0" , self .nodes [0 ].setautocombinethreshold , True , 2 , - 1 )
29+ assert_raises_rpc_error (- 8 , "The threshold value cannot be less than 1.00" , self .nodes [0 ].setautocombinethreshold , True , 0.99 )
2830
2931 self .log .info ("Mining initial 100 blocks..." )
3032 self .nodes [0 ].generate (100 )
@@ -37,39 +39,46 @@ def run_test(self):
3739 self .nodes [0 ].generate (2 )
3840
3941 walletinfo = self .nodes [0 ].getwalletinfo ()
40- assert_equal (walletinfo ['balance' ], 500 )
42+ assert_equal (walletinfo ['balance' ], 250 * 2 )
4143 assert_equal (walletinfo ['txcount' ], 102 )
4244
43- self .log .info ("Set autocombine to 500 PIV" )
44- setautocombine = self .nodes [0 ].setautocombinethreshold (True , 500 )
45+ self .log .info ("Set autocombine to 500 PIV and frequency of 10 " )
46+ setautocombine = self .nodes [0 ].setautocombinethreshold (True , 500 , 10 )
4547 assert_equal (setautocombine ['enabled' ], True )
4648 assert_equal (setautocombine ['threshold' ], 500 )
49+ assert_equal (setautocombine ['frequency' ], 10 )
4750 getautocombine = self .nodes [0 ].getautocombinethreshold ()
4851 assert_equal (getautocombine ['enabled' ], True )
4952 assert_equal (getautocombine ['threshold' ], 500 )
53+ assert_equal (getautocombine ['frequency' ], 10 )
5054 walletinfo = self .nodes [0 ].getwalletinfo ()
5155 assert_equal (walletinfo ['autocombine_enabled' ], True )
5256 assert_equal (walletinfo ['autocombine_threshold' ], 500 )
57+ assert_equal (walletinfo ['autocombine_frequency' ], 10 )
5358
54- self .log .info ("Mine 1 more block to initiate an autocombine transaction" )
55- self .nodes [0 ].generate (1 )
59+ self .log .info ("Mine 8 more block to initiate an autocombine transaction" )
60+
61+ self .nodes [0 ].generate (8 ) # we need 8 more blocks to get a multiple of 10
62+ assert_equal (0 , self .nodes [0 ].getblockcount () % 10 )
5663 time .sleep (1 )
5764
5865 mempool = self .nodes [0 ].getrawmempool ()
5966 assert_equal (len (mempool ), 1 )
6067 tx = mempool [0 ]
6168 nFee = self .nodes [0 ].getrawmempool (True )[mempool [0 ]]['fee' ]
6269 walletinfo = self .nodes [0 ].getwalletinfo ()
63- assert_equal (walletinfo ['balance' ], 750 - nFee )
64- assert_equal (walletinfo ['txcount' ], 104 )
70+ assert_equal (walletinfo ['balance' ], 250 * 10 - nFee )
71+ assert_equal (walletinfo ['txcount' ], 111 ) # 110 coinbase txs + 1 to autocollect
6572
6673 self .log .info ("Mine 1 more block to confirm the autocombine transaction" )
6774 block = self .nodes [0 ].generate (1 )
6875 time .sleep (1 )
6976
7077 walletinfo = self .nodes [0 ].getwalletinfo ()
71- assert_equal (walletinfo ['balance' ], 250 + 750 - nFee )
72- assert_equal (walletinfo ['txcount' ], 105 )
78+ assert_equal (walletinfo ['balance' ], 250 * 11 - nFee )
79+ # 111 coinbase txs + 1 autocollect, good autocollect was not called again since nBlock % 10 = 1
80+ assert_equal (1 , self .nodes [0 ].getblockcount () % 10 )
81+ assert_equal (walletinfo ['txcount' ], 112 )
7382
7483 txinfo = self .nodes [0 ].gettransaction (tx )
7584 assert_equal (txinfo ['fee' ], 0 - nFee )
@@ -81,12 +90,17 @@ def run_test(self):
8190 setautocombine = self .nodes [0 ].setautocombinethreshold (False )
8291 assert_equal (setautocombine ['enabled' ], False )
8392 assert_equal (setautocombine ['threshold' ], 0 )
93+ assert_equal (setautocombine ['frequency' ], 30 ) # set back to default value
94+
8495 getautocombine = self .nodes [0 ].getautocombinethreshold ()
8596 assert_equal (getautocombine ['enabled' ], False )
8697 assert_equal (getautocombine ['threshold' ], 0 )
98+ assert_equal (getautocombine ['frequency' ], 30 )
99+
87100 walletinfo = self .nodes [0 ].getwalletinfo ()
88101 assert_equal (walletinfo ['autocombine_enabled' ], False )
89102 assert_equal (walletinfo ['autocombine_threshold' ], 0 )
103+ assert_equal (walletinfo ['autocombine_frequency' ], 30 )
90104
91105 self .log .info ("Mine 1 more block to make sure autocombine is disabled" )
92106 self .nodes [0 ].generate (1 )
@@ -96,8 +110,8 @@ def run_test(self):
96110 assert_equal (len (mempool ), 0 )
97111
98112 walletinfo = self .nodes [0 ].getwalletinfo ()
99- assert_equal (walletinfo ['balance' ], 250 + 250 + 750 - nFee )
100- assert_equal (walletinfo ['txcount' ], 106 )
113+ assert_equal (walletinfo ['balance' ], 250 * 12 - nFee )
114+ assert_equal (walletinfo ['txcount' ], 113 )
101115
102116
103117if __name__ == '__main__' :
0 commit comments