Browse Source

pytest: Stabilize and parameterize closing_specified_destination

This test was doing a few contortions, so I disentangled it a bit and
parametrized it
travis-debug
Christian Decker 5 years ago
parent
commit
43dfb4dae7
  1. 3
      contrib/pyln-testing/pyln/testing/fixtures.py
  2. 39
      tests/test_closing.py

3
contrib/pyln-testing/pyln/testing/fixtures.py

@ -305,6 +305,7 @@ def chainparams():
"""Return the chainparams for the TEST_NETWORK.
- chain_hash is in network byte order, not the RPC return order.
- example_addr doesn't belong to any node in the test (randomly generated)
"""
chainparams = {
@ -324,7 +325,7 @@ def chainparams():
"name": "liquid-regtest",
"p2sh_prefix": 'X',
"elements": True,
"example_addr": "ert1qq8adjz4u6enf0cjey9j8yt0y490tact9fahkwf",
"example_addr": "ert1qjsesxflhs3632syhcz7llpfx20p5tr0kpllfve",
"feeoutput": True,
"chain_hash": "9f87eb580b9e5f11dc211e9fb66abb3699999044f8fe146801162393364286c6",
}

39
tests/test_closing.py

@ -298,7 +298,7 @@ def test_closing_negotiation_reconnect(node_factory, bitcoind):
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_closing_specified_destination(node_factory, bitcoind):
def test_closing_specified_destination(node_factory, bitcoind, chainparams):
l1, l2, l3, l4 = node_factory.get_nodes(4)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
@ -314,7 +314,7 @@ def test_closing_specified_destination(node_factory, bitcoind):
l1.pay(l4, 100000000)
bitcoind.generate_block(5)
addr = 'bcrt1qeyyk6sl5pr49ycpqyckvmttus5ttj25pd0zpvg'
addr = chainparams['example_addr']
l1.rpc.close(chan12, None, addr)
l1.rpc.call('close', {'id': chan13, 'destination': addr})
l1.rpc.call('close', [chan14, None, addr])
@ -327,38 +327,33 @@ def test_closing_specified_destination(node_factory, bitcoind):
assert bitcoind.rpc.getmempoolinfo()['size'] == 3
# Now grab the close transaction
closetxid = bitcoind.rpc.getrawmempool(False)
assert len(closetxid) == 3
idindex = {}
for n in [l2, l3, l4]:
billboard = only_one(l1.rpc.listpeers(n.info['id'])['peers'][0]['channels'])['status']
idindex[n] = [i for i in range(3) if billboard == [
'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi for tx:{}'.format(closetxid[i]),
]][0]
assert idindex[n] in range(3)
closetxs = {}
for i, n in enumerate([l2, l3, l4]):
billboard = only_one(l1.rpc.listpeers(n.info['id'])['peers'][0]['channels'])['status'][0]
m = re.search(r'CLOSINGD_SIGEXCHANGE.* tx:([a-f0-9]{64})', billboard)
closetxs[n] = m.group(1)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1, l2, l3, l4])
# l1 can't spent the output to addr.
assert not l1.daemon.is_in_log(r'Owning output.* \(SEGWIT\).* txid %s.* CONFIRMED' % closetxid[0])
assert not l1.daemon.is_in_log(r'Owning output.* \(SEGWIT\).* txid %s.* CONFIRMED' % closetxid[1])
assert not l1.daemon.is_in_log(r'Owning output.* \(SEGWIT\).* txid %s.* CONFIRMED' % closetxid[2])
for txid in closetxs.values():
assert not l1.daemon.is_in_log(r'Owning output.* \(SEGWIT\).* txid {}.* CONFIRMED'.format(txid))
# Check the txid has at least 1 confirmation
l2.daemon.wait_for_log(r'Owning output.* \(SEGWIT\).* txid %s.* CONFIRMED' % closetxid[idindex[l2]])
l3.daemon.wait_for_log(r'Owning output.* \(SEGWIT\).* txid %s.* CONFIRMED' % closetxid[idindex[l3]])
l4.daemon.wait_for_log(r'Owning output.* \(SEGWIT\).* txid %s.* CONFIRMED' % closetxid[idindex[l4]])
for n, txid in closetxs.items():
n.daemon.wait_for_log(r'Owning output.* \(SEGWIT\).* txid {}.* CONFIRMED'.format(txid))
for n in [l2, l3, l4]:
# Make sure both nodes have grabbed their close tx funds
closetx = closetxs[n]
outputs = n.rpc.listfunds()['outputs']
assert closetxid[idindex[n]] in set([o['txid'] for o in outputs])
output_num2 = [o for o in outputs if o['txid'] == closetxid[idindex[n]]][0]['output']
assert closetx in set([o['txid'] for o in outputs])
output_num2 = [o for o in outputs if o['txid'] == closetx][0]['output']
output_num1 = 0 if output_num2 == 1 else 1
# Check the another address is addr
assert addr == bitcoind.rpc.gettxout(closetxid[idindex[n]], output_num1)['scriptPubKey']['addresses'][0]
assert 1 == bitcoind.rpc.gettxout(closetxid[idindex[n]], output_num1)['confirmations']
assert addr == bitcoind.rpc.gettxout(closetx, output_num1)['scriptPubKey']['addresses'][0]
assert 1 == bitcoind.rpc.gettxout(closetx, output_num1)['confirmations']
@unittest.skipIf(not COMPAT, "needs COMPAT=1")

Loading…
Cancel
Save