From 6d79f7679cc35b05aac7678ae410aa35b287a87c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 31 Jul 2018 14:04:42 +0930 Subject: [PATCH] pytest: test reserve enforcement. A bit tricky, since we don't normally let ourselves make bad HTLCs. Signed-off-by: Rusty Russell --- tests/test_lightningd.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 021d8e00d..706a51ccd 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -7,6 +7,7 @@ from utils import wait_for import copy import json import logging +import pytest import queue import os import random @@ -5113,6 +5114,29 @@ class LightningDTests(BaseLightningDTests): # fundee will also forget and disconnect from peer. assert len(l2.rpc.listpeers(l1.info['id'])['peers']) == 0 + @pytest.mark.xfail(strict=True) + def test_reserve_enforcement(self): + """Channeld should disallow you spending into your reserve""" + l1, l2 = self.connect(may_reconnect=True) + + self.fund_channel(l1, l2, 10**6) + # Pay 1000 satoshi to l2. + self.pay(l1, l2, 1000000) + + l2.stop() + + # Edit db to reduce reserve to 0 so it will try to violate it. + l2.db_query('UPDATE channel_configs SET channel_reserve_satoshis=0', + use_copy=False) + + l2.start() + wait_for(lambda: only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['connected']) + + # This should be impossible to pay entire thing back: l1 should + # kill us for trying to violate reserve. + self.pay(l2, l1, 1000000, async=True) + l1.daemon.wait_for_log('Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR Bad peer_add_htlc: CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED') + if __name__ == '__main__': unittest.main(verbosity=2)