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

Function test_funding_push

tests/test_connection.py:1200–1244  ·  view source on GitHub ↗

Try to push peer some sats

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1198
1199@pytest.mark.openchannel('v1')
1200def test_funding_push(node_factory, bitcoind, chainparams):
1201 """ Try to push peer some sats """
1202 # We track balances, to verify that accounting is ok.
1203 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1204
1205 l1 = node_factory.get_node(options={'plugin': coin_mvt_plugin})
1206 l2 = node_factory.get_node(options={'plugin': coin_mvt_plugin})
1207
1208 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1209
1210 # Send funds.
1211 amount = 2**24
1212 push_msat = 20000 * 1000
1213 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('bech32')['bech32'], amount / 10**8 + 0.01)
1214 bitcoind.generate_block(1)
1215
1216 # Wait for it to arrive.
1217 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
1218
1219 # Fail to open (try to push too much)
1220 with pytest.raises(RpcError, match=r'Requested to push_msat of 20000000msat is greater than available funding amount 10000sat'):
1221 l1.rpc.fundchannel(l2.info['id'], 10000, push_msat=push_msat)
1222
1223 # This should work.
1224 amount = amount - 1
1225 l1.rpc.fundchannel(l2.info['id'], amount, push_msat=push_msat)
1226
1227 bitcoind.generate_block(1)
1228 sync_blockheight(bitcoind, [l1])
1229 funds = only_one(l1.rpc.listfunds()['channels'])
1230 assert funds['our_amount_msat'] + push_msat == funds['amount_msat']
1231
1232 chanid = first_channel_id(l2, l1)
1233 channel_mvts_1 = [
1234 {'type': 'chain_mvt', 'credit_msat': 16777215000, 'debit_msat': 0, 'tags': ['channel_open', 'opener']},
1235 {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 20000000, 'tags': ['pushed'], 'fees_msat': '0msat'},
1236 ]
1237 channel_mvts_2 = [
1238 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']},
1239 {'type': 'channel_mvt', 'credit_msat': 20000000, 'debit_msat': 0, 'tags': ['pushed'], 'fees_msat': '0msat'},
1240 ]
1241 check_coin_moves(l1, chanid, channel_mvts_1, chainparams)
1242 check_coin_moves(l2, chanid, channel_mvts_2, chainparams)
1243
1244 assert account_balance(l1, chanid) == amount * 1000 - push_msat
1245
1246
1247@pytest.mark.openchannel('v1')

Callers

nothing calls this directly

Calls 13

wait_forFunction · 0.90
sync_blockheightFunction · 0.90
only_oneFunction · 0.90
first_channel_idFunction · 0.90
check_coin_movesFunction · 0.90
account_balanceFunction · 0.90
joinMethod · 0.80
generate_blockMethod · 0.80
get_nodeMethod · 0.45
connectMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45

Tested by

no test coverage detected