MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_channel_abandon

Function test_channel_abandon

tests/test_connection.py:380–411  ·  view source on GitHub ↗

Our open tx isn't mined, we doublespend it away

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

378
379
380def test_channel_abandon(node_factory, bitcoind):
381 """Our open tx isn't mined, we doublespend it away"""
382 l1, l2 = node_factory.get_nodes(2)
383
384 SATS = 10**6
385
386 # Add some for fees
387 l1.fundwallet(SATS + 10000)
388 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
389 l1.rpc.fundchannel(l2.info['id'], SATS, feerate='1875perkw')
390
391 opening_utxo = only_one([o for o in l1.rpc.listfunds()['outputs'] if o['reserved']])
392 psbt = l1.rpc.utxopsbt(0, "253perkw", 0, [opening_utxo['txid'] + ':' + str(opening_utxo['output'])], reserve=0, reservedok=True)['psbt']
393
394 # We expect a reservation for 2016 blocks; unreserve it.
395 reservations = only_one(l1.rpc.unreserveinputs(psbt, reserve=2015)['reservations'])
396 assert reservations['reserved']
397 assert reservations['reserved_to_block'] == bitcoind.rpc.getblockchaininfo()['blocks'] + 1
398
399 assert only_one(l1.rpc.unreserveinputs(psbt, reserve=1)['reservations'])['reserved'] is False
400
401 # Now it's unreserved, we can doublespend it (as long as we exceed
402 # previous fee to RBF!).
403 withdraw = l1.rpc.withdraw(l1.rpc.newaddr()['bech32'], "all")
404
405 assert bitcoind.rpc.decoderawtransaction(withdraw['tx'])['vout'][0]['value'] > SATS / 10**8
406 bitcoind.generate_block(1, wait_for_mempool=withdraw['txid'])
407
408 # FIXME: lightningd should notice channel will never now open!
409 print(l1.rpc.listpeers())
410 assert (only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['state']
411 == 'CHANNELD_AWAITING_LOCKIN')
412
413
414@pytest.mark.developer

Callers

nothing calls this directly

Calls 12

only_oneFunction · 0.90
get_nodesMethod · 0.80
fundwalletMethod · 0.80
utxopsbtMethod · 0.80
unreserveinputsMethod · 0.80
generate_blockMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
listfundsMethod · 0.45
withdrawMethod · 0.45
newaddrMethod · 0.45
listpeersMethod · 0.45

Tested by

no test coverage detected