Browse Source

test_irc_messaging.py: add asyncTearDown

add-joinmarket
zebra-lucky 1 year ago
parent
commit
32522eda95
  1. 16
      electrum/plugins/joinmarket/tests/jmdaemon/test_irc_messaging.py
  2. 72
      electrum/plugins/joinmarket/tests/jmdaemon/test_onionmc.py

16
electrum/plugins/joinmarket/tests/jmdaemon/test_irc_messaging.py

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
'''Tests of joinmarket bots end-to-end (including IRC and bitcoin) '''
import asyncio import asyncio
import io import io
@ -175,22 +173,24 @@ class IRCBaseTestCase(JMTestCase):
await self.mcc2.run() await self.mcc2.run()
self.irc2 = self.mc2.tx_irc_client self.irc2 = self.mc2.tx_irc_client
async def asyncTearDown(self):
async def cb(m): async def cb(m):
# don't try to reconnect # don't try to reconnect
m.give_up = True m.give_up = True
await m.shutdown() await m.shutdown()
self.addCleanup(cb, self.mc) await cb(self.mc)
self.addCleanup(cb, self.mc2) await cb(self.mc2)
class IRCMessageChannelTestCase(IRCBaseTestCase): class IRCMessageChannelTestCase(IRCBaseTestCase):
async def test_wlog(self): async def test_wlog(self):
l = self.logger log = self.logger
wlog(l, 'INFO', 'test info wlog') wlog(log, 'INFO', 'test info wlog')
wlog(l, 'WARNING', 'test warning wlog') wlog(log, 'WARNING', 'test warning wlog')
wlog(l, 'test debug wlog', 'test', b'wlog', 1e9, 5, None) wlog(log, 'test debug wlog', 'test', b'wlog', 1e9, 5, None)
async def test_get_irc_nick(self): async def test_get_irc_nick(self):
assert get_irc_nick('@dummynick! text') == '@dummynick' assert get_irc_nick('@dummynick! text') == '@dummynick'

72
electrum/plugins/joinmarket/tests/jmdaemon/test_onionmc.py

@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
import asyncio
import io
from electrum.plugins.joinmarket.jmdaemon import (
OnionMessageChannel, MessageChannelCollection)
from electrum.plugins.joinmarket.jmdaemon.onionmc import OnionPeer
from electrum.plugins.joinmarket.jmdaemon.onionmc_support import (
TorClientService)
from electrum.plugins.joinmarket.tests import JMTestCase
class DummyTransport(asyncio.Transport):
def __init__(self, logger):
super().__init__()
self._t = io.BytesIO(b'')
self.logger = logger
def write(self, data):
self.logger.debug(f'DummyTransport.write: {data}')
self._t.write(data)
def close(self):
self._t.close()
class DummyTorClientService(TorClientService):
async def _proxy_create_conn(self):
self.logger.debug(f'_proxy_create_conn: {self.factory.buildProtocol}, '
f'{self.host}:{self.port}')
self.transport = DummyTransport(self.logger)
self.protocol = self.factory.buildProtocol()
self.protocol.connection_made(self.transport)
class DummyMC(OnionMessageChannel):
def __init__(self, jmman, configdata, nick):
super().__init__(jmman, configdata,
client_service_cls=DummyTorClientService)
self.set_nick(nick)
class OnionBaseTestCase(JMTestCase):
async def asyncSetUp(self):
await super().asyncSetUp()
jmman = self.jmman
jmconf = jmman.jmconf
jmconf.maker_timeout_sec = 1
configdata = list(jmconf.get_msg_channels().values())[2]
directory_node = configdata['directory_nodes'].split(',')[0]
configdata['directory_nodes'] = directory_node
self.mc = DummyMC(jmman, configdata, 'onionnick')
self.mcc = MessageChannelCollection([self.mc], jmman)
await self.mcc.run()
async def asyncTearDown(self):
async def cb(m):
# don't try to reconnect
m.give_up = True
await m.shutdown()
await cb(self.mc)
async def test_setup(self):
assert 0
Loading…
Cancel
Save