From b3d4e161b5b361bb0b86fb35530d994908412633 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 6 Feb 2018 15:48:51 +0100 Subject: [PATCH] pytest: Add test for `dev-forget-channel` Signed-off-by: Christian Decker --- tests/test_lightningd.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 821fabb1a..220725483 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -1053,7 +1053,7 @@ class LightningDTests(BaseLightningDTests): p.daemon.wait_for_log(' to ONCHAIND_MUTUAL') l1.daemon.wait_for_logs([' to ONCHAIND_MUTUAL'] * num_peers) - + @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") def test_permfail(self): l1,l2 = self.connect() @@ -3364,7 +3364,7 @@ class LightningDTests(BaseLightningDTests): '-J', 'help', 'command=help']).decode('utf-8') j, _ = json.JSONDecoder().raw_decode(out) - assert 'help [command]' in j['verbose'] + assert 'help [command]' in j['verbose'] # Test keyword input (forced) out = subprocess.check_output(['cli/lightning-cli', @@ -3373,7 +3373,7 @@ class LightningDTests(BaseLightningDTests): '-J', '-k', 'help', 'command=help']).decode('utf-8') j, _ = json.JSONDecoder().raw_decode(out) - assert 'help [command]' in j['verbose'] + assert 'help [command]' in j['verbose'] # Test ordered input (autodetect) out = subprocess.check_output(['cli/lightning-cli', @@ -3382,7 +3382,7 @@ class LightningDTests(BaseLightningDTests): '-J', 'help', 'help']).decode('utf-8') j, _ = json.JSONDecoder().raw_decode(out) - assert 'help [command]' in j['verbose'] + assert 'help [command]' in j['verbose'] # Test ordered input (forced) out = subprocess.check_output(['cli/lightning-cli', @@ -3391,7 +3391,7 @@ class LightningDTests(BaseLightningDTests): '-J', '-o', 'help', 'help']).decode('utf-8') j, _ = json.JSONDecoder().raw_decode(out) - assert 'help [command]' in j['verbose'] + assert 'help [command]' in j['verbose'] # Test missing parameters. try: @@ -3405,6 +3405,28 @@ class LightningDTests(BaseLightningDTests): except: pass + @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") + def test_forget_channel(self): + l1 = self.node_factory.get_node() + l2 = self.node_factory.get_node() + self.give_funds(l1, 10**6) + l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port']) + l1.rpc.fundchannel(l2.info['id'], 10**5) + + assert len(l1.rpc.listpeers()['peers']) == 1 + + # This should fail, the funding tx is in the mempool and may confirm + self.assertRaises(ValueError, l1.rpc.dev_forget_channel, l2.info['id']) + assert len(l1.rpc.listpeers()['peers']) == 1 + + # Forcing should work + l1.rpc.dev_forget_channel(l2.info['id'], True) + assert len(l1.rpc.listpeers()['peers']) == 0 + + # And restarting should keep that peer forgotten + l1.restart() + assert len(l1.rpc.listpeers()['peers']) == 0 + if __name__ == '__main__': unittest.main(verbosity=2)