Rewrite TestAddressGenerator as a subclass of TestPartialRun,

edit docstrings and add more checks. Closes: #1895
This commit is contained in:
Lee Miller 2022-07-04 04:10:18 +03:00
parent d427c27e7e
commit 799aadc9bc
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -1,35 +1,37 @@
import unittest
"""Tests for AddressGenerator (with thread or not)"""
from binascii import unhexlify
from pybitmessage import pathmagic
from .partial import TestPartialRun
from .samples import (
sample_seed, sample_deterministic_addr3, sample_deterministic_addr4,
sample_deterministic_ripe)
class TestAddressGenerator(unittest.TestCase):
"""Test case for AddressGenerator (with thread or not)"""
class TestAddressGenerator(TestPartialRun):
"""Test case for AddressGenerator thread"""
@classmethod
def setUpClass(cls):
pathmagic.setup() # need this because of import state in network ):
import queues
import state
super(TestAddressGenerator, cls).setUpClass()
state.enableGUI = False
import defaults
import queues
from class_addressGenerator import addressGenerator
# import helper_startup
# from bmconfigparser import BMConfigParser
# helper_startup.loadConfig()
# config = BMConfigParser()
cls.state.enableGUI = False
cls.command_queue = queues.addressGeneratorQueue
cls.return_queue = queues.apiAddressGeneratorReturnQueue
cls.worker_queue = queues.workerQueue
cls.config.set(
'bitmessagesettings', 'defaultnoncetrialsperbyte',
str(defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
cls.config.set(
'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(defaults.networkDefaultPayloadLengthExtraBytes))
thread = addressGenerator()
thread.daemon = True
thread.start()
@ -52,3 +54,12 @@ class TestAddressGenerator(unittest.TestCase):
self.assertEqual(
sample_deterministic_addr4,
self._execute('createChan', 4, 1, 'test', sample_seed, True))
self.assertEqual(
self.worker_queue.get(),
('sendOutOrStoreMyV4Pubkey', sample_deterministic_addr4))
self.assertEqual(
self.config.get(sample_deterministic_addr4, 'label'), 'test')
self.assertTrue(
self.config.getboolean(sample_deterministic_addr4, 'chan'))
self.assertTrue(
self.config.getboolean(sample_deterministic_addr4, 'enabled'))