Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/tests/test_addressgenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest
from binascii import unhexlify

from pybitmessage import pathmagic

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)"""

@classmethod
def setUpClass(cls):
pathmagic.setup() # need this because of import state in network ):
import queues
import state

state.enableGUI = False
from class_addressGenerator import addressGenerator

# import helper_startup
# from bmconfigparser import BMConfigParser

# helper_startup.loadConfig()
# config = BMConfigParser()

cls.command_queue = queues.addressGeneratorQueue
cls.return_queue = queues.apiAddressGeneratorReturnQueue
cls.worker_queue = queues.workerQueue

thread = addressGenerator()
thread.daemon = True
thread.start()

def _execute(self, command, *args):
self.command_queue.put((command,) + args)
try:
return self.return_queue.get()[0]
except IndexError:
self.fail('Failed to execute command %s' % command)

def test_createChan(self):
"""Test createChan command"""
self.assertEqual(
sample_deterministic_addr3,
self._execute('createChan', 3, 1, 'test', sample_seed, True))
self.assertEqual(
self.worker_queue.get(),
('sendOutOrStoreMyV3Pubkey', unhexlify(sample_deterministic_ripe)))
self.assertEqual(
sample_deterministic_addr4,
self._execute('createChan', 4, 1, 'test', sample_seed, True))