|
30 | 30 | assert_equal,
|
31 | 31 | assert_greater_than,
|
32 | 32 | assert_raises_rpc_error,
|
| 33 | + find_vout_for_address, |
33 | 34 | )
|
34 | 35 | from test_framework.wallet import MiniWallet
|
35 | 36 |
|
@@ -103,6 +104,7 @@ def run_test(self):
|
103 | 104 | # These tests wipe out a number of utxos that are expected in other tests
|
104 | 105 | test_small_output_with_feerate_succeeds(self, rbf_node, dest_address)
|
105 | 106 | test_no_more_inputs_fails(self, rbf_node, dest_address)
|
| 107 | + self.test_provided_change_pos(rbf_node) |
106 | 108 |
|
107 | 109 | def test_invalid_parameters(self, rbf_node, peer_node, dest_address):
|
108 | 110 | self.log.info('Test invalid parameters')
|
@@ -157,9 +159,42 @@ def test_invalid_parameters(self, rbf_node, peer_node, dest_address):
|
157 | 159 | assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
158 | 160 | rbf_node.bumpfee, rbfid, {"estimate_mode": mode})
|
159 | 161 |
|
| 162 | + self.log.info("Test change position option") |
| 163 | + assert_raises_rpc_error(-1, "JSON integer out of range", rbf_node.bumpfee, rbfid, {"reduce_output": -1}) |
| 164 | + assert_raises_rpc_error(-8, "Change position is out of range", rbf_node.bumpfee, rbfid, {"reduce_output": 2}) |
| 165 | + |
160 | 166 | self.clear_mempool()
|
161 | 167 |
|
162 | 168 |
|
| 169 | + def test_provided_change_pos(self, rbf_node): |
| 170 | + self.log.info("Test the reduce_output option") |
| 171 | + |
| 172 | + change_addr = rbf_node.getnewaddress() |
| 173 | + dest_addr = rbf_node.getnewaddress() |
| 174 | + assert_equal(rbf_node.getaddressinfo(change_addr)["ischange"], False) |
| 175 | + assert_equal(rbf_node.getaddressinfo(dest_addr)["ischange"], False) |
| 176 | + |
| 177 | + send_res = rbf_node.send(outputs=[{dest_addr: 1}], options={"change_address": change_addr}) |
| 178 | + assert send_res["complete"] |
| 179 | + txid = send_res["txid"] |
| 180 | + |
| 181 | + tx = rbf_node.gettransaction(txid=txid, verbose=True) |
| 182 | + assert_equal(len(tx["decoded"]["vout"]), 2) |
| 183 | + |
| 184 | + change_pos = find_vout_for_address(rbf_node, txid, change_addr) |
| 185 | + change_value = tx["decoded"]["vout"][change_pos]["value"] |
| 186 | + |
| 187 | + bumped = rbf_node.bumpfee(txid, {"reduce_output": change_pos}) |
| 188 | + new_txid = bumped["txid"] |
| 189 | + |
| 190 | + new_tx = rbf_node.gettransaction(txid=new_txid, verbose=True) |
| 191 | + assert_equal(len(new_tx["decoded"]["vout"]), 2) |
| 192 | + new_change_pos = find_vout_for_address(rbf_node, new_txid, change_addr) |
| 193 | + new_change_value = new_tx["decoded"]["vout"][new_change_pos]["value"] |
| 194 | + |
| 195 | + assert_greater_than(change_value, new_change_value) |
| 196 | + |
| 197 | + |
163 | 198 | def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
|
164 | 199 | self.log.info('Test simple bumpfee: {}'.format(mode))
|
165 | 200 | rbfid = spend_one_input(rbf_node, dest_address)
|
|
0 commit comments