|
|
@ -5,7 +5,7 @@ from fixtures import TEST_NETWORK |
|
|
|
from flaky import flaky # noqa: F401 |
|
|
|
from pyln.client import RpcError, Millisatoshi |
|
|
|
from utils import ( |
|
|
|
only_one, wait_for, sync_blockheight, EXPERIMENTAL_FEATURES, COMPAT, |
|
|
|
only_one, wait_for, sync_blockheight, EXPERIMENTAL_FEATURES, |
|
|
|
VALGRIND, check_coin_moves |
|
|
|
) |
|
|
|
|
|
|
@ -232,50 +232,6 @@ def test_addfunds_from_block(node_factory, bitcoind): |
|
|
|
assert output['address'] == addr |
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipIf(not COMPAT, "needs COMPAT=1") |
|
|
|
def test_deprecated_txprepare(node_factory, bitcoind): |
|
|
|
"""Test the deprecated old-style: |
|
|
|
txprepare {destination} {satoshi} {feerate} {minconf} |
|
|
|
""" |
|
|
|
amount = 10**4 |
|
|
|
l1 = node_factory.get_node(options={'allow-deprecated-apis': True}) |
|
|
|
addr = l1.rpc.newaddr()['bech32'] |
|
|
|
|
|
|
|
for i in range(7): |
|
|
|
l1.fundwallet(10**8) |
|
|
|
|
|
|
|
bitcoind.generate_block(1) |
|
|
|
sync_blockheight(bitcoind, [l1]) |
|
|
|
|
|
|
|
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 7) |
|
|
|
|
|
|
|
# Array type |
|
|
|
with pytest.raises(RpcError, match=r'.* should be an amount in satoshis or all, not .*'): |
|
|
|
l1.rpc.call('txprepare', [addr, 'slow']) |
|
|
|
|
|
|
|
with pytest.raises(RpcError, match=r'Need set \'satoshi\' field.'): |
|
|
|
l1.rpc.call('txprepare', [addr]) |
|
|
|
|
|
|
|
with pytest.raises(RpcError, match=r'Could not parse destination address.*'): |
|
|
|
l1.rpc.call('txprepare', [Millisatoshi(amount * 100), 'slow', 1]) |
|
|
|
|
|
|
|
l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100), 'slow', 1]) |
|
|
|
l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100), 'normal']) |
|
|
|
l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100), None, 1]) |
|
|
|
l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100)]) |
|
|
|
|
|
|
|
# Object type |
|
|
|
with pytest.raises(RpcError, match=r'Need set \'outputs\' field.'): |
|
|
|
l1.rpc.call('txprepare', {'destination': addr, 'feerate': 'slow'}) |
|
|
|
|
|
|
|
with pytest.raises(RpcError, match=r'Need set \'outputs\' field.'): |
|
|
|
l1.rpc.call('txprepare', {'satoshi': Millisatoshi(amount * 100), 'feerate': '10perkw', 'minconf': 2}) |
|
|
|
|
|
|
|
l1.rpc.call('txprepare', {'destination': addr, 'satoshi': Millisatoshi(amount * 100), 'feerate': '2000perkw', 'minconf': 1}) |
|
|
|
l1.rpc.call('txprepare', {'destination': addr, 'satoshi': Millisatoshi(amount * 100), 'feerate': '2000perkw'}) |
|
|
|
l1.rpc.call('txprepare', {'destination': addr, 'satoshi': Millisatoshi(amount * 100)}) |
|
|
|
|
|
|
|
|
|
|
|
def test_txprepare_multi(node_factory, bitcoind): |
|
|
|
amount = 10000000 |
|
|
|
l1 = node_factory.get_node(random_hsm=True) |
|
|
@ -880,60 +836,6 @@ def test_txsend(node_factory, bitcoind, chainparams): |
|
|
|
assert decode['vout'][changenum]['scriptPubKey']['addresses'][0] in [f['address'] for f in l1.rpc.listfunds()['outputs']] |
|
|
|
|
|
|
|
|
|
|
|
def test_txprepare_restart(node_factory, bitcoind, chainparams): |
|
|
|
amount = 1000000 |
|
|
|
l1 = node_factory.get_node(may_fail=True) |
|
|
|
addr = chainparams['example_addr'] |
|
|
|
|
|
|
|
# Add some funds to withdraw later: both bech32 and p2sh |
|
|
|
for i in range(5): |
|
|
|
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], |
|
|
|
amount / 10**8) |
|
|
|
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('p2sh-segwit')['p2sh-segwit'], |
|
|
|
amount / 10**8) |
|
|
|
bitcoind.generate_block(1) |
|
|
|
wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 10) |
|
|
|
|
|
|
|
prep = l1.rpc.txprepare([{addr: 'all'}]) |
|
|
|
decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) |
|
|
|
assert decode['txid'] == prep['txid'] |
|
|
|
# All 10 inputs |
|
|
|
assert len(decode['vin']) == 10 |
|
|
|
|
|
|
|
# L1 will forget all about it. |
|
|
|
l1.restart() |
|
|
|
|
|
|
|
# It goes backwards in blockchain just in case there was a reorg. Wait. |
|
|
|
wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 10) |
|
|
|
|
|
|
|
with pytest.raises(RpcError, match=r'not an unreleased txid'): |
|
|
|
l1.rpc.txdiscard(prep['txid']) |
|
|
|
|
|
|
|
prep = l1.rpc.txprepare([{addr: 'all'}]) |
|
|
|
|
|
|
|
decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) |
|
|
|
assert decode['txid'] == prep['txid'] |
|
|
|
# All 10 inputs |
|
|
|
assert len(decode['vin']) == 10 |
|
|
|
|
|
|
|
# This will also work if we simply kill it. |
|
|
|
l1.restart(clean=False) |
|
|
|
|
|
|
|
# It goes backwards in blockchain just in case there was a reorg. Wait. |
|
|
|
wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 10) |
|
|
|
|
|
|
|
# It should have logged this for each output (any order) |
|
|
|
template = r'wallet: reserved output {}/{} reset to available' |
|
|
|
lines = [template.format(i['txid'], i['vout']) for i in decode['vin']] |
|
|
|
l1.daemon.wait_for_logs(lines) |
|
|
|
|
|
|
|
prep = l1.rpc.txprepare([{addr: 'all'}]) |
|
|
|
decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) |
|
|
|
assert decode['txid'] == prep['txid'] |
|
|
|
# All 10 inputs |
|
|
|
assert len(decode['vin']) == 10 |
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipIf(TEST_NETWORK != 'regtest', "Fee outputs throw off our output matching logic") |
|
|
|
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Tests annotations which are compiled only with experimental features") |
|
|
|
def test_transaction_annotations(node_factory, bitcoind): |
|
|
|