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

Function test_funding_push

tests/test_connection.py:1142–1186  ·  view source on GitHub ↗

Try to push peer some sats

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1140
1141@pytest.mark.openchannel('v1')
1142def test_funding_push(node_factory, bitcoind, chainparams):
1143 """ Try to push peer some sats """
1144 # We track balances, to verify that accounting is ok.
1145 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1146
1147 l1 = node_factory.get_node(options={'plugin': coin_mvt_plugin})
1148 l2 = node_factory.get_node(options={'plugin': coin_mvt_plugin})
1149
1150 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1151
1152 # Send funds.
1153 amount = 2**24
1154 push_msat = 20000 * 1000
1155 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
1156 bitcoind.generate_block(1)
1157
1158 # Wait for it to arrive.
1159 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
1160
1161 # Fail to open (try to push too much)
1162 with pytest.raises(RpcError, match=r'Requested to push_msat of 20000000msat is greater than available funding amount 10000sat'):
1163 l1.rpc.fundchannel(l2.info['id'], 10000, push_msat=push_msat)
1164
1165 # This should work.
1166 amount = amount - 1
1167 l1.rpc.fundchannel(l2.info['id'], amount, push_msat=push_msat)
1168
1169 bitcoind.generate_block(1)
1170 sync_blockheight(bitcoind, [l1])
1171 funds = only_one(l1.rpc.listfunds()['channels'])
1172 assert funds['our_amount_msat'] + push_msat == funds['amount_msat']
1173
1174 chanid = first_channel_id(l2, l1)
1175 channel_mvts_1 = [
1176 {'type': 'chain_mvt', 'credit_msat': 16777215000, 'debit_msat': 0, 'tags': ['channel_open', 'opener']},
1177 {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 20000000, 'tags': ['pushed'], 'fees_msat': '0msat'},
1178 ]
1179 channel_mvts_2 = [
1180 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']},
1181 {'type': 'channel_mvt', 'credit_msat': 20000000, 'debit_msat': 0, 'tags': ['pushed'], 'fees_msat': '0msat'},
1182 ]
1183 check_coin_moves(l1, chanid, channel_mvts_1, chainparams)
1184 check_coin_moves(l2, chanid, channel_mvts_2, chainparams)
1185
1186 assert account_balance(l1, chanid) == amount * 1000 - push_msat
1187
1188
1189@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