Skip to content

Commit

Permalink
pytest: test that we unreserve txprepare inputs across shutdown/crash.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed Jun 6, 2019
1 parent cdab75e commit 65505ad
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
52 changes: 52 additions & 0 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ def stop(self, timeout=10):
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):
Expand Down

0 comments on commit 65505ad

Please sign in to comment.