mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
df-tests: test_openchannel_hook
Have it check both openchannel + openchannel2
This commit is contained in:
committed by
Christian Decker
parent
0d45823b82
commit
b0a8b10b41
@@ -5,20 +5,37 @@ We just refuse to let them open channels with an odd amount of millisatoshis.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pyln.client import Plugin, Millisatoshi
|
from pyln.client import Plugin, Millisatoshi
|
||||||
|
from pyln.testing.utils import env
|
||||||
|
|
||||||
plugin = Plugin()
|
plugin = Plugin()
|
||||||
|
|
||||||
|
|
||||||
|
EXPERIMENTAL_FEATURES = env("EXPERIMENTAL_FEATURES", "0") == "1"
|
||||||
|
|
||||||
|
|
||||||
|
def run_check(funding_amt_str):
|
||||||
|
if Millisatoshi(funding_amt_str).to_satoshi() % 2 == 1:
|
||||||
|
return {'result': 'reject', 'error_message': "I don't like odd amounts"}
|
||||||
|
|
||||||
|
return {'result': 'continue'}
|
||||||
|
|
||||||
|
|
||||||
@plugin.hook('openchannel')
|
@plugin.hook('openchannel')
|
||||||
def on_openchannel(openchannel, plugin, **kwargs):
|
def on_openchannel(openchannel, plugin, **kwargs):
|
||||||
print("{} VARS".format(len(openchannel.keys())))
|
print("{} VARS".format(len(openchannel.keys())))
|
||||||
for k in sorted(openchannel.keys()):
|
for k in sorted(openchannel.keys()):
|
||||||
print("{}={}".format(k, openchannel[k]))
|
print("{}={}".format(k, openchannel[k]))
|
||||||
|
return run_check(openchannel['funding_satoshis'])
|
||||||
|
|
||||||
if Millisatoshi(openchannel['funding_satoshis']).to_satoshi() % 2 == 1:
|
|
||||||
return {'result': 'reject', 'error_message': "I don't like odd amounts"}
|
|
||||||
|
|
||||||
return {'result': 'continue'}
|
if EXPERIMENTAL_FEATURES:
|
||||||
|
@plugin.hook('openchannel2')
|
||||||
|
def on_openchannel2(openchannel2, plugin, **kwargs):
|
||||||
|
print("{} VARS".format(len(openchannel2.keys())))
|
||||||
|
for k in sorted(openchannel2.keys()):
|
||||||
|
print("{}={}".format(k, openchannel2[k]))
|
||||||
|
|
||||||
|
return run_check(openchannel2['their_funding'])
|
||||||
|
|
||||||
|
|
||||||
plugin.run()
|
plugin.run()
|
||||||
|
|||||||
@@ -563,18 +563,39 @@ def test_openchannel_hook(node_factory, bitcoind):
|
|||||||
l1.rpc.fundchannel(l2.info['id'], 100000)
|
l1.rpc.fundchannel(l2.info['id'], 100000)
|
||||||
|
|
||||||
# Make sure plugin got all the vars we expect
|
# Make sure plugin got all the vars we expect
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: 11 VARS')
|
expected = {
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: channel_flags=1')
|
'channel_flags': '1',
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: channel_reserve_satoshis=1000000msat')
|
'dust_limit_satoshis': '546000msat',
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: dust_limit_satoshis=546000msat')
|
'htlc_minimum_msat': '0msat',
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: feerate_per_kw=7500')
|
'id': l1.info['id'],
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: funding_satoshis=100000000msat')
|
'max_accepted_htlcs': '483',
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: htlc_minimum_msat=0msat')
|
'max_htlc_value_in_flight_msat': '18446744073709551615msat',
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: id={}'.format(l1.info['id']))
|
'to_self_delay': '5',
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: max_accepted_htlcs=483')
|
}
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: max_htlc_value_in_flight_msat=18446744073709551615msat')
|
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: push_msat=0msat')
|
if l2.config('experimental-dual-fund'):
|
||||||
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: to_self_delay=5')
|
# openchannel2 var checks
|
||||||
|
expected.update({
|
||||||
|
'commitment_feerate_per_kw': '750',
|
||||||
|
'feerate_our_max': '150000',
|
||||||
|
'feerate_our_min': '1875',
|
||||||
|
'funding_feerate_best': '7500',
|
||||||
|
'funding_feerate_max': '150000',
|
||||||
|
'funding_feerate_min': '1875',
|
||||||
|
'locktime': '.*',
|
||||||
|
'their_funding': '100000000msat',
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
expected.update({
|
||||||
|
'channel_reserve_satoshis': '1000000msat',
|
||||||
|
'feerate_per_kw': '7500',
|
||||||
|
'funding_satoshis': '100000000msat',
|
||||||
|
'push_msat': '0msat',
|
||||||
|
})
|
||||||
|
|
||||||
|
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: {} VARS'.format(len(expected)))
|
||||||
|
for k, v in expected.items():
|
||||||
|
assert l2.daemon.is_in_log('reject_odd_funding_amounts.py: {}={}'.format(k, v))
|
||||||
|
|
||||||
# Close it.
|
# Close it.
|
||||||
txid = l1.rpc.close(l2.info['id'])['txid']
|
txid = l1.rpc.close(l2.info['id'])['txid']
|
||||||
|
|||||||
Reference in New Issue
Block a user