From 799aadc9bcb5fe7b8b22d7efafaaee771f35fc04 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Mon, 4 Jul 2022 04:10:18 +0300 Subject: [PATCH] Rewrite TestAddressGenerator as a subclass of TestPartialRun, edit docstrings and add more checks. Closes: #1895 --- src/tests/test_addressgenerator.py | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/tests/test_addressgenerator.py b/src/tests/test_addressgenerator.py index 0549242f..764286e8 100644 --- a/src/tests/test_addressgenerator.py +++ b/src/tests/test_addressgenerator.py @@ -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'))