1515class WalletGroupTest (BitcoinTestFramework ):
1616 def set_test_params (self ):
1717 self .setup_clean_chain = True
18- self .num_nodes = 4
19- self .extra_args = [[], [], ['-avoidpartialspends' ], ["-maxapsfee=0.0001" ]]
18+ self .num_nodes = 5
19+ self .extra_args = [
20+ [],
21+ [],
22+ ["-avoidpartialspends" ],
23+ ["-maxapsfee=0.00002719" ],
24+ ["-maxapsfee=0.00002720" ],
25+ ]
2026 self .rpc_timeout = 480
2127
2228 def skip_test_if_missing_module (self ):
@@ -50,8 +56,8 @@ def run_test(self):
5056 # one output should be 0.2, the other should be ~0.3
5157 v = [vout ["value" ] for vout in tx1 ["vout" ]]
5258 v .sort ()
53- assert_approx (v [0 ], 0.2 )
54- assert_approx (v [1 ], 0.3 , 0.0001 )
59+ assert_approx (v [0 ], vexp = 0.2 , vspan = 0.0001 )
60+ assert_approx (v [1 ], vexp = 0.3 , vspan = 0.0001 )
5561
5662 txid2 = self .nodes [2 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 0.2 )
5763 tx2 = self .nodes [2 ].getrawtransaction (txid2 , True )
@@ -61,8 +67,8 @@ def run_test(self):
6167 # one output should be 0.2, the other should be ~1.3
6268 v = [vout ["value" ] for vout in tx2 ["vout" ]]
6369 v .sort ()
64- assert_approx (v [0 ], 0.2 )
65- assert_approx (v [1 ], 1.3 , 0.0001 )
70+ assert_approx (v [0 ], vexp = 0.2 , vspan = 0.0001 )
71+ assert_approx (v [1 ], vexp = 1.3 , vspan = 0.0001 )
6672
6773 # Test 'avoid partial if warranted, even if disabled'
6874 self .sync_all ()
@@ -75,8 +81,8 @@ def run_test(self):
7581 # - C0 1.0 - E1 0.5
7682 # - C1 0.5 - F ~1.3
7783 # - D ~0.3
78- assert_approx (self .nodes [1 ].getbalance (), 4.3 , 0.0001 )
79- assert_approx (self .nodes [2 ].getbalance (), 4.3 , 0.0001 )
84+ assert_approx (self .nodes [1 ].getbalance (), vexp = 4.3 , vspan = 0.0001 )
85+ assert_approx (self .nodes [2 ].getbalance (), vexp = 4.3 , vspan = 0.0001 )
8086 # Sending 1.4 btc should pick one 1.0 + one more. For node #1,
8187 # this could be (A / B0 / C0) + (B1 / C1 / D). We ensure that it is
8288 # B0 + B1 or C0 + C1, because this avoids partial spends while not being
@@ -90,8 +96,8 @@ def run_test(self):
9096 # ~0.1 and 1.4 and should come from the same destination
9197 values = [vout ["value" ] for vout in tx3 ["vout" ]]
9298 values .sort ()
93- assert_approx (values [0 ], 0.1 , 0.0001 )
94- assert_approx (values [1 ], 1.4 )
99+ assert_approx (values [0 ], vexp = 0.1 , vspan = 0.0001 )
100+ assert_approx (values [1 ], vexp = 1.4 , vspan = 0.0001 )
95101
96102 input_txids = [vin ["txid" ] for vin in tx3 ["vin" ]]
97103 input_addrs = [self .nodes [1 ].gettransaction (txid )['details' ][0 ]['address' ] for txid in input_txids ]
@@ -104,13 +110,38 @@ def run_test(self):
104110 self .nodes [0 ].sendtoaddress (addr_aps , 1.0 )
105111 self .nodes [0 ].generate (1 )
106112 self .sync_all ()
107- txid4 = self .nodes [3 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 0.1 )
113+ with self .nodes [3 ].assert_debug_log (['Fee non-grouped = 2820, grouped = 4160, using grouped' ]):
114+ txid4 = self .nodes [3 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 0.1 )
108115 tx4 = self .nodes [3 ].getrawtransaction (txid4 , True )
109116 # tx4 should have 2 inputs and 2 outputs although one output would
110117 # have been enough and the transaction caused higher fees
111118 assert_equal (2 , len (tx4 ["vin" ]))
112119 assert_equal (2 , len (tx4 ["vout" ]))
113120
121+ addr_aps2 = self .nodes [3 ].getnewaddress ()
122+ [self .nodes [0 ].sendtoaddress (addr_aps2 , 1.0 ) for _ in range (5 )]
123+ self .nodes [0 ].generate (1 )
124+ self .sync_all ()
125+ with self .nodes [3 ].assert_debug_log (['Fee non-grouped = 5520, grouped = 8240, using non-grouped' ]):
126+ txid5 = self .nodes [3 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 2.95 )
127+ tx5 = self .nodes [3 ].getrawtransaction (txid5 , True )
128+ # tx5 should have 3 inputs (1.0, 1.0, 1.0) and 2 outputs
129+ assert_equal (3 , len (tx5 ["vin" ]))
130+ assert_equal (2 , len (tx5 ["vout" ]))
131+
132+ # Test wallet option maxapsfee with node 4, which sets maxapsfee
133+ # 1 sat higher, crossing the threshold from non-grouped to grouped.
134+ addr_aps3 = self .nodes [4 ].getnewaddress ()
135+ [self .nodes [0 ].sendtoaddress (addr_aps3 , 1.0 ) for _ in range (5 )]
136+ self .nodes [0 ].generate (1 )
137+ self .sync_all ()
138+ with self .nodes [4 ].assert_debug_log (['Fee non-grouped = 5520, grouped = 8240, using grouped' ]):
139+ txid6 = self .nodes [4 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 2.95 )
140+ tx6 = self .nodes [4 ].getrawtransaction (txid6 , True )
141+ # tx6 should have 5 inputs and 2 outputs
142+ assert_equal (5 , len (tx6 ["vin" ]))
143+ assert_equal (2 , len (tx6 ["vout" ]))
144+
114145 # Empty out node2's wallet
115146 self .nodes [2 ].sendtoaddress (address = self .nodes [0 ].getnewaddress (), amount = self .nodes [2 ].getbalance (), subtractfeefromamount = True )
116147 self .sync_all ()
0 commit comments