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

Function test_emergencyrecover

tests/test_misc.py:3197–3244  ·  view source on GitHub ↗

Test emergencyrecover

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

3195
3196@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")
3197def test_emergencyrecover(node_factory, bitcoind):
3198 """
3199 Test emergencyrecover
3200 """
3201 l1, l2 = node_factory.get_nodes(2, opts=[{'may_reconnect': True,
3202 'broken_log': 'ERROR: Unknown commitment #.*, recovering our funds|plugin-bookkeeper: Cannot find the open_event for '},
3203 {'may_reconnect': True}])
3204
3205 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
3206 c12, _ = l1.fundchannel(l2)
3207 stubs = l1.rpc.emergencyrecover()["stubs"]
3208 assert l1.daemon.is_in_log('channel {} already exists!'.format(_['channel_id']))
3209
3210 l1.stop()
3211
3212 os.unlink(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3"))
3213
3214 l1.start()
3215 assert l1.daemon.is_in_log('Server started with public key')
3216 stubs = l1.rpc.emergencyrecover()["stubs"]
3217 assert len(stubs) == 1
3218 assert stubs[0] == _["channel_id"]
3219 assert l1.daemon.is_in_log('channel {} already exists!'.format(_['channel_id']))
3220
3221 listfunds = l1.rpc.listfunds()["channels"][0]
3222 assert listfunds["short_channel_id"] == "1x1x1"
3223
3224 l1.daemon.wait_for_log('Sending a bogus channel_reestablish message to make the peer unilaterally close the channel.')
3225 l1.daemon.wait_for_log('peer_out WIRE_ERROR')
3226
3227 l2.daemon.wait_for_log('bad reestablish commitment_number: 0')
3228 l2.daemon.wait_for_log('State changed from CHANNELD_NORMAL to AWAITING_UNILATERAL')
3229
3230 bitcoind.generate_block(5, wait_for_mempool=1)
3231 sync_blockheight(bitcoind, [l1, l2])
3232
3233 l1.daemon.wait_for_log(r'All outputs resolved.*')
3234 # Make sure l1 can spend its recovered funds.
3235 wait_for(lambda: l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN")
3236 wait_for(lambda: l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN")
3237
3238 # Does bookkeeper get upset?
3239 l1.rpc.bkpr_listbalances()
3240
3241 withdraw = l1.rpc.withdraw(l2.rpc.newaddr('bech32')['bech32'], 'all')
3242 # Should have two inputs
3243 assert len(bitcoind.rpc.decoderawtransaction(withdraw['tx'])['vin']) == 2
3244 bitcoind.generate_block(1, wait_for_mempool=withdraw['txid'])
3245
3246
3247@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "sqlite3-specific DB rollback")

Callers

nothing calls this directly

Calls 14

sync_blockheightFunction · 0.90
wait_forFunction · 0.90
get_nodesMethod · 0.80
is_in_logMethod · 0.80
joinMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
stopMethod · 0.45
startMethod · 0.45
listfundsMethod · 0.45

Tested by

no test coverage detected