A test case for address generator #2170

Merged
PeterSurda merged 6 commits from gitea-33 into v0.6 2024-01-17 09:34:05 +01:00
Showing only changes of commit c45f1eae14 - Show all commits

View File

@ -2,11 +2,15 @@
from binascii import unhexlify
from six.moves import queue
from .partial import TestPartialRun
from .samples import (
sample_seed, sample_deterministic_addr3, sample_deterministic_addr4,
sample_deterministic_ripe)
TEST_LABEL = 'test'
class TestAddressGenerator(TestPartialRun):
"""Test case for AddressGenerator thread"""
@ -39,26 +43,44 @@ class TestAddressGenerator(TestPartialRun):
def _execute(self, command, *args):
self.command_queue.put((command,) + args)
try:
return self.return_queue.get()[0]
except IndexError:
return self.return_queue.get(timeout=30)[0]
except (IndexError, queue.Empty):
self.fail('Failed to execute command %s' % command)
def test_createChan(self):
"""Test createChan command"""
def test_deterministic(self):
"""Test deterministic commands"""
self.command_queue.put((
'getDeterministicAddress', 3, 1,
TEST_LABEL, 1, sample_seed, False))
self.assertEqual(sample_deterministic_addr3, self.return_queue.get())
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._execute(
'createDeterministicAddresses', 3, 1, TEST_LABEL, 2,
sample_seed, False, 0, 0))
try:
self.assertEqual(
self.worker_queue.get(timeout=30),
('sendOutOrStoreMyV3Pubkey',
unhexlify(sample_deterministic_ripe)))
self.worker_queue.get(timeout=30) # get the next addr's task
except queue.Empty:
self.fail('No commands in the worker queue')
self.assertEqual(
sample_deterministic_addr4,
self._execute('createChan', 4, 1, 'test', sample_seed, True))
self._execute('createChan', 4, 1, TEST_LABEL, sample_seed, True))
try:
self.assertEqual(
self.worker_queue.get(),
('sendOutOrStoreMyV4Pubkey', sample_deterministic_addr4))
except queue.Empty:
self.fail('No commands in the worker queue')
self.assertEqual(
self.worker_queue.get(),
('sendOutOrStoreMyV4Pubkey', sample_deterministic_addr4))
self.assertEqual(
self.config.get(sample_deterministic_addr4, 'label'), 'test')
self.config.get(sample_deterministic_addr4, 'label'), TEST_LABEL)
self.assertTrue(
self.config.getboolean(sample_deterministic_addr4, 'chan'))
self.assertTrue(