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

Function test_funding_external_wallet_corners

tests/test_connection.py:1233–1345  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1231@pytest.mark.developer("needs dev_forget_channel")
1232@pytest.mark.openchannel('v1')
1233def test_funding_external_wallet_corners(node_factory, bitcoind):
1234 l1, l2 = node_factory.get_nodes(2, opts={'may_reconnect': True,
1235 'dev-no-reconnect': None})
1236
1237 amount = 2**24
1238 l1.fundwallet(amount + 10000000)
1239
1240 amount = amount - 1
1241
1242 # make sure we can generate PSBTs.
1243 addr = l1.rpc.newaddr()['bech32']
1244 bitcoind.rpc.sendtoaddress(addr, (amount + 1000000) / 10**8)
1245 bitcoind.generate_block(1)
1246 wait_for(lambda: len(l1.rpc.listfunds()["outputs"]) != 0)
1247
1248 # Some random (valid) psbt
1249 psbt = l1.rpc.fundpsbt(amount, '253perkw', 250, reserve=0)['psbt']
1250
1251 with pytest.raises(RpcError, match=r'Unknown peer'):
1252 l1.rpc.fundchannel_start(l2.info['id'], amount)
1253
1254 with pytest.raises(RpcError, match=r'Unknown peer'):
1255 l1.rpc.fundchannel_complete(l2.info['id'], psbt)
1256
1257 # Should not be able to continue without being in progress.
1258 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1259 with pytest.raises(RpcError, match=r'No channel funding in progress.'):
1260 l1.rpc.fundchannel_complete(l2.info['id'], psbt)
1261
1262 # Fail to open (too large)
1263 with pytest.raises(RpcError, match=r'Amount exceeded 16777215'):
1264 l1.rpc.fundchannel_start(l2.info['id'], amount + 1)
1265
1266 start = l1.rpc.fundchannel_start(l2.info['id'], amount)
1267 with pytest.raises(RpcError, match=r'Already funding channel'):
1268 l1.rpc.fundchannel(l2.info['id'], amount)
1269
1270 # Can't complete with incorrect amount (unchecked on Elements)
1271 if TEST_NETWORK == 'regtest':
1272 wrongamt = l1.rpc.txprepare([{start['funding_address']: amount - 1}])
1273 with pytest.raises(RpcError, match=r'Output to open channel is .*, should be .*'):
1274 l1.rpc.fundchannel_complete(l2.info['id'], wrongamt['psbt'])
1275 l1.rpc.txdiscard(wrongamt['txid'])
1276
1277 # Can't complete with incorrect address.
1278 wrongaddr = l1.rpc.txprepare([{l1.rpc.newaddr()['bech32']: amount}])
1279 with pytest.raises(RpcError, match=r'No output to open channel'):
1280 l1.rpc.fundchannel_complete(l2.info['id'], wrongaddr['psbt'])
1281 l1.rpc.txdiscard(wrongaddr['txid'])
1282
1283 l1.rpc.fundchannel_cancel(l2.info['id'])
1284
1285 # Cancelling causes disconnection.
1286 wait_for(lambda: l1.rpc.listpeers(l2.info['id'])['peers'] == [])
1287 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1288 amount2 = 1000000
1289 funding_addr = l1.rpc.fundchannel_start(l2.info['id'], amount2)['funding_address']
1290

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
only_oneFunction · 0.90
get_nodesMethod · 0.80
fundwalletMethod · 0.80
generate_blockMethod · 0.80
fundpsbtMethod · 0.80
fundchannel_startMethod · 0.80
fundchannel_completeMethod · 0.80
txprepareMethod · 0.80
txdiscardMethod · 0.80
fundchannel_cancelMethod · 0.80
wait_for_logMethod · 0.80

Tested by

no test coverage detected