|
1 | 1 | from fixtures import *
|
2 |
| -from test_framework.serializations import PSBT |
| 2 | +from test_framework.serializations import ( |
| 3 | + PSBT, |
| 4 | + PSBT_IN_NON_WITNESS_UTXO, |
| 5 | +) |
3 | 6 | from test_framework.utils import wait_for, COIN, RpcError
|
4 | 7 |
|
5 | 8 |
|
@@ -332,6 +335,24 @@ def test_coin_selection(lianad, bitcoind):
|
332 | 335 | assert auto_psbt.tx.vout[1].nValue == manual_psbt.tx.vout[1].nValue
|
333 | 336 |
|
334 | 337 |
|
| 338 | +def test_coin_selection_changeless(lianad, bitcoind): |
| 339 | + """We choose the changeless solution with lowest fee.""" |
| 340 | + # Get two coins with similar amounts. |
| 341 | + txid_a = bitcoind.rpc.sendtoaddress(lianad.rpc.getnewaddress()["address"], 0.00031) |
| 342 | + txid_b = bitcoind.rpc.sendtoaddress(lianad.rpc.getnewaddress()["address"], 0.00032) |
| 343 | + bitcoind.generate_block(1, wait_for_mempool=[txid_a, txid_b]) |
| 344 | + wait_for(lambda: len(lianad.rpc.listcoins(["confirmed"])["coins"]) == 2) |
| 345 | + # Send an amount that can be paid by just one of our coins. |
| 346 | + res = lianad.rpc.createspend({bitcoind.rpc.getnewaddress(): 30800}, [], 1) |
| 347 | + psbt = PSBT.from_base64(res["psbt"]) |
| 348 | + # Only one input needed. |
| 349 | + assert len(psbt.i) == 1 |
| 350 | + # Coin A is used as input. |
| 351 | + assert [psbt_in.map[PSBT_IN_NON_WITNESS_UTXO] for psbt_in in psbt.i][ |
| 352 | + 0 |
| 353 | + ] == bytes.fromhex(bitcoind.rpc.gettransaction(txid_a)["hex"]) |
| 354 | + |
| 355 | + |
335 | 356 | def test_sweep(lianad, bitcoind):
|
336 | 357 | """
|
337 | 358 | Test we can leverage the change_address parameter to partially or completely sweep
|
|
0 commit comments