URI: 
       ttest_lnpeer: use less side-effects - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 9734546fe9cd2df32ea89425c37e6499b31eab7b
   DIR parent e3630d87b249dbb538e431def45c78519a61bf0c
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Wed, 12 Feb 2020 10:32:55 +0100
       
       ttest_lnpeer: use less side-effects
       
       Diffstat:
         M electrum/tests/test_lnpeer.py       |      54 ++++++++++++++++----------------
       
       1 file changed, 27 insertions(+), 27 deletions(-)
       ---
   DIR diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py
       t@@ -180,23 +180,23 @@ class TestPeer(ElectrumTestCase):
                self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
                self._loop_thread.join(timeout=1)
        
       -    def prepare_peers(self):
       +    def prepare_peers(self, alice_channel, bob_channel):
                k1, k2 = keypair(), keypair()
       -        t1, t2 = transport_pair(self.alice_channel.name, self.bob_channel.name)
       +        t1, t2 = transport_pair(alice_channel.name, bob_channel.name)
                q1, q2 = asyncio.Queue(), asyncio.Queue()
       -        w1 = MockLNWallet(k1, k2, self.alice_channel, tx_queue=q1)
       -        w2 = MockLNWallet(k2, k1, self.bob_channel, tx_queue=q2)
       +        w1 = MockLNWallet(k1, k2, alice_channel, tx_queue=q1)
       +        w2 = MockLNWallet(k2, k1, bob_channel, tx_queue=q2)
                p1 = Peer(w1, k1.pubkey, t1)
                p2 = Peer(w2, k2.pubkey, t2)
                w1.peer = p1
                w2.peer = p2
                # mark_open won't work if state is already OPEN.
                # so set it to FUNDED
       -        self.alice_channel._state = channel_states.FUNDED
       -        self.bob_channel._state = channel_states.FUNDED
       +        alice_channel._state = channel_states.FUNDED
       +        bob_channel._state = channel_states.FUNDED
                # this populates the channel graph:
       -        p1.mark_open(self.alice_channel)
       -        p2.mark_open(self.bob_channel)
       +        p1.mark_open(alice_channel)
       +        p2.mark_open(bob_channel)
                return p1, p2, w1, w2, q1, q2
        
            @staticmethod
       t@@ -218,14 +218,14 @@ class TestPeer(ElectrumTestCase):
                return lnencode(lnaddr, w2.node_keypair.privkey)
        
            def test_reestablish(self):
       -        self.alice_channel, self.bob_channel = create_test_channels()
       -        p1, p2, w1, w2, _q1, _q2 = self.prepare_peers()
       +        alice_channel, bob_channel = create_test_channels()
       +        p1, p2, w1, w2, _q1, _q2 = self.prepare_peers(alice_channel, bob_channel)
                async def reestablish():
                    await asyncio.gather(
       -                p1.reestablish_channel(self.alice_channel),
       -                p2.reestablish_channel(self.bob_channel))
       -            self.assertEqual(self.alice_channel.peer_state, peer_states.GOOD)
       -            self.assertEqual(self.bob_channel.peer_state, peer_states.GOOD)
       +                p1.reestablish_channel(alice_channel),
       +                p2.reestablish_channel(bob_channel))
       +            self.assertEqual(alice_channel.peer_state, peer_states.GOOD)
       +            self.assertEqual(bob_channel.peer_state, peer_states.GOOD)
                    gath.cancel()
                gath = asyncio.gather(reestablish(), p1._message_loop(), p2._message_loop())
                async def f():
       t@@ -234,19 +234,19 @@ class TestPeer(ElectrumTestCase):
                    run(f())
        
            def test_reestablish_with_old_state(self):
       -        self.alice_channel, self.bob_channel = create_test_channels()
       -        self.alice_channel_0, self.bob_channel_0 = create_test_channels() # these are identical
       -        p1, p2, w1, w2, _q1, _q2 = self.prepare_peers()
       +        alice_channel, bob_channel = create_test_channels()
       +        alice_channel_0, bob_channel_0 = create_test_channels() # these are identical
       +        p1, p2, w1, w2, _q1, _q2 = self.prepare_peers(alice_channel, bob_channel)
                pay_req = self.prepare_invoice(w2)
                async def reestablish():
                    result = await LNWallet._pay(w1, pay_req)
                    self.assertEqual(result, True)
       -            w1.channels = {self.alice_channel_0.channel_id: self.alice_channel_0}
       +            w1.channels = {alice_channel_0.channel_id: alice_channel_0}
                    await asyncio.gather(
       -                p1.reestablish_channel(self.alice_channel_0),
       -                p2.reestablish_channel(self.bob_channel))
       -            self.assertEqual(self.alice_channel_0.peer_state, peer_states.BAD)
       -            self.assertEqual(self.bob_channel._state, channel_states.FORCE_CLOSING)
       +                p1.reestablish_channel(alice_channel_0),
       +                p2.reestablish_channel(bob_channel))
       +            self.assertEqual(alice_channel_0.peer_state, peer_states.BAD)
       +            self.assertEqual(bob_channel._state, channel_states.FORCE_CLOSING)
                    # wait so that pending messages are processed
                    #await asyncio.sleep(1)
                    gath.cancel()
       t@@ -257,8 +257,8 @@ class TestPeer(ElectrumTestCase):
                    run(f())
        
            def test_payment(self):
       -        self.alice_channel, self.bob_channel = create_test_channels()
       -        p1, p2, w1, w2, _q1, _q2 = self.prepare_peers()
       +        alice_channel, bob_channel = create_test_channels()
       +        p1, p2, w1, w2, _q1, _q2 = self.prepare_peers(alice_channel, bob_channel)
                pay_req = self.prepare_invoice(w2)
                async def pay():
                    result = await LNWallet._pay(w1, pay_req)
       t@@ -271,14 +271,14 @@ class TestPeer(ElectrumTestCase):
                    run(f())
        
            def test_channel_usage_after_closing(self):
       -        self.alice_channel, self.bob_channel = create_test_channels()
       -        p1, p2, w1, w2, q1, q2 = self.prepare_peers()
       +        alice_channel, bob_channel = create_test_channels()
       +        p1, p2, w1, w2, q1, q2 = self.prepare_peers(alice_channel, bob_channel)
                pay_req = self.prepare_invoice(w2)
        
                addr = w1._check_invoice(pay_req)
                route = run(w1._create_route_from_invoice(decoded_invoice=addr))
        
       -        run(w1.force_close_channel(self.alice_channel.channel_id))
       +        run(w1.force_close_channel(alice_channel.channel_id))
                # check if a tx (commitment transaction) was broadcasted:
                assert q1.qsize() == 1