From 65505adbab1dd14abb26f5f3d99b91f68f4c24f7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 5 Jun 2019 16:30:05 +0930 Subject: [PATCH] pytest: test that we unreserve txprepare inputs across shutdown/crash. We fail this at the moment, since we rely on shutdown to do the cleanups for us. (Also had to fix the unclean shutdown path: the caller checks the rc unless mayfail is set, and of course it's not zero since we just SIGTERM'd it). Signed-off-by: Rusty Russell --- tests/test_wallet.py | 52 ++++++++++++++++++++++++++++++++++++++++++++ tests/utils.py | 3 --- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/test_wallet.py b/tests/test_wallet.py index ae62a8e44..a43677640 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -321,3 +321,55 @@ def test_txsend(node_factory, bitcoind): # Change address should appear in listfunds() assert decode['vout'][changenum]['scriptPubKey']['addresses'][0] in [f['address'] for f in l1.rpc.listfunds()['outputs']] + + +@pytest.mark.xfail(strict=True) +def test_txprepare_restart(node_factory, bitcoind): + amount = 1000000 + l1 = node_factory.get_node(may_fail=True) + + # 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('bcrt1qeyyk6sl5pr49ycpqyckvmttus5ttj25pd0zpvg', + '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('bcrt1qeyyk6sl5pr49ycpqyckvmttus5ttj25pd0zpvg', + '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) + + prep = l1.rpc.txprepare('bcrt1qeyyk6sl5pr49ycpqyckvmttus5ttj25pd0zpvg', + 'all') + decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) + assert decode['txid'] == prep['txid'] + # All 10 inputs + assert len(decode['vin']) == 10 diff --git a/tests/utils.py b/tests/utils.py index c46f61335..e24fd6f41 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -149,9 +149,6 @@ class TailableProc(object): self.proc.wait() self.thread.join() - if self.proc.returncode: - raise ValueError("Process '{}' did not cleanly shutdown: return code {}".format(self.proc.pid, rc)) - return self.proc.returncode def kill(self):