15
15
class WalletGroupTest (BitcoinTestFramework ):
16
16
def set_test_params (self ):
17
17
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
+ ]
20
26
self .rpc_timeout = 480
21
27
22
28
def skip_test_if_missing_module (self ):
@@ -50,8 +56,8 @@ def run_test(self):
50
56
# one output should be 0.2, the other should be ~0.3
51
57
v = [vout ["value" ] for vout in tx1 ["vout" ]]
52
58
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 )
55
61
56
62
txid2 = self .nodes [2 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 0.2 )
57
63
tx2 = self .nodes [2 ].getrawtransaction (txid2 , True )
@@ -61,8 +67,8 @@ def run_test(self):
61
67
# one output should be 0.2, the other should be ~1.3
62
68
v = [vout ["value" ] for vout in tx2 ["vout" ]]
63
69
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 )
66
72
67
73
# Test 'avoid partial if warranted, even if disabled'
68
74
self .sync_all ()
@@ -75,8 +81,8 @@ def run_test(self):
75
81
# - C0 1.0 - E1 0.5
76
82
# - C1 0.5 - F ~1.3
77
83
# - 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 )
80
86
# Sending 1.4 btc should pick one 1.0 + one more. For node #1,
81
87
# this could be (A / B0 / C0) + (B1 / C1 / D). We ensure that it is
82
88
# B0 + B1 or C0 + C1, because this avoids partial spends while not being
@@ -90,8 +96,8 @@ def run_test(self):
90
96
# ~0.1 and 1.4 and should come from the same destination
91
97
values = [vout ["value" ] for vout in tx3 ["vout" ]]
92
98
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 )
95
101
96
102
input_txids = [vin ["txid" ] for vin in tx3 ["vin" ]]
97
103
input_addrs = [self .nodes [1 ].gettransaction (txid )['details' ][0 ]['address' ] for txid in input_txids ]
@@ -104,13 +110,38 @@ def run_test(self):
104
110
self .nodes [0 ].sendtoaddress (addr_aps , 1.0 )
105
111
self .nodes [0 ].generate (1 )
106
112
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 )
108
115
tx4 = self .nodes [3 ].getrawtransaction (txid4 , True )
109
116
# tx4 should have 2 inputs and 2 outputs although one output would
110
117
# have been enough and the transaction caused higher fees
111
118
assert_equal (2 , len (tx4 ["vin" ]))
112
119
assert_equal (2 , len (tx4 ["vout" ]))
113
120
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
+
114
145
# Empty out node2's wallet
115
146
self .nodes [2 ].sendtoaddress (address = self .nodes [0 ].getnewaddress (), amount = self .nodes [2 ].getbalance (), subtractfeefromamount = True )
116
147
self .sync_all ()
0 commit comments