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

Function test_reserve_enforcement

tests/test_misc.py:1741–1768  ·  view source on GitHub ↗

Channeld should disallow you spending into your reserve

(node_factory, executor)

Source from the content-addressed store, hash-verified

1739@pytest.mark.openchannel('v1')
1740@pytest.mark.openchannel('v2')
1741def test_reserve_enforcement(node_factory, executor):
1742 """Channeld should disallow you spending into your reserve"""
1743 l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True,
1744 'dev-no-reconnect': None,
1745 'allow_warning': True})
1746
1747 # Pay 1000 satoshi to l2.
1748 l1.pay(l2, 1000000)
1749 l2.stop()
1750
1751 # They should both aim for 1%.
1752 reserves = l2.db.query('SELECT channel_reserve_satoshis FROM channel_configs')
1753 assert reserves == [{'channel_reserve_satoshis': 10**6 // 100}] * 2
1754
1755 # Edit db to reduce reserve to 0 so it will try to violate it.
1756 l2.db.execute('UPDATE channel_configs SET channel_reserve_satoshis=0')
1757
1758 l2.start()
1759 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
1760
1761 # This should be impossible to pay entire thing back: l1 should warn and
1762 # close connection for trying to violate reserve.
1763 executor.submit(l2.pay, l1, 1000000)
1764 l1.daemon.wait_for_log(
1765 'Peer transient failure in CHANNELD_NORMAL: channeld.*'
1766 ' CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED'
1767 )
1768 wait_for(lambda: only_one(l1.rpc.listpeers()['peers'])['connected'] is False)
1769
1770
1771def test_ipv4_and_ipv6(node_factory):

Callers

nothing calls this directly

Calls 11

wait_forFunction · 0.90
only_oneFunction · 0.90
line_graphMethod · 0.80
wait_for_logMethod · 0.80
payMethod · 0.45
stopMethod · 0.45
queryMethod · 0.45
executeMethod · 0.45
startMethod · 0.45
connectMethod · 0.45
listpeersMethod · 0.45

Tested by

no test coverage detected