Exemplo n.º 1
0
    def test_resolve_all_pool_configs(self):
        pool_config_resolver = JsonFilePoolConfigurationResolver(
            'sample_files/sample_pool_config.json')

        actual_pool_configs = pool_config_resolver.resolve_all()

        pool_config_1 = PoolConfiguration('pool1')
        pool_config_2 = PoolConfiguration('pool2')
        pool_config_3 = PoolConfiguration('pool3')
        self.assertListEqual([pool_config_1, pool_config_2, pool_config_3],
                             actual_pool_configs)
        currency_config_1 = PoolCurrencyConfiguration(
            Currency('currency1', 'c1'))
        currency_config_2 = PoolCurrencyConfiguration(
            Currency('currency2', 'c2'))
        currency_config_3 = PoolCurrencyConfiguration(
            Currency('currency3', 'c3'))
        self.assertListEqual(
            [currency_config_1, currency_config_2, currency_config_3],
            actual_pool_configs[0].currency_configs)
        hash_algorithm_config_1 = PoolHashAlgorithmConfiguration('algo1')
        hash_algorithm_config_2 = PoolHashAlgorithmConfiguration('algo2')
        hash_algorithm_config_3 = PoolHashAlgorithmConfiguration('algo3')
        self.assertListEqual([
            hash_algorithm_config_1, hash_algorithm_config_2,
            hash_algorithm_config_3
        ], actual_pool_configs[0].currency_configs[0].hash_algorithm_configs)
        connection_config_1 = PoolConnectionConfiguration(1, 'pool.1', 4201)
        connection_config_2 = PoolConnectionConfiguration(2, 'pool.1', 4202)
        connection_config_3 = PoolConnectionConfiguration(3, 'pool.1', 4203)
        self.assertListEqual(
            [connection_config_1, connection_config_2, connection_config_3],
            actual_pool_configs[0].currency_configs[0].
            hash_algorithm_configs[0].connection_configs)
class PoolConnectionInfoResolverTestCase(unittest.TestCase):

    pool_config = PoolConfiguration('pool1', [
        PoolCurrencyConfiguration(Currency('currency1', 'c1'), []),
        PoolCurrencyConfiguration(Currency('currency2', 'c2'), [
            PoolHashAlgorithmConfiguration('algo1', []),
            PoolHashAlgorithmConfiguration('algo2', [
                PoolConnectionConfiguration(1, 'base_url_1', 4201),
                PoolConnectionConfiguration(2, 'base_url_2', 4202),
                PoolConnectionConfiguration(None, 'base_url_3', 4203)
            ])
        ])
    ])

    def test_resolve_pool_connection_info_from_pool_config_currency_name(self):
        pool_connection_info = resolve_connection_info(self.pool_config,
                                                       'currency2', 'algo2', 2)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_2', pool_connection_info.base_url)
        self.assertEqual(4202, pool_connection_info.port)

    def test_resolve_pool_connection_info_from_pool_config_currency_symbol(
            self):
        pool_connection_info = resolve_connection_info(self.pool_config, 'c2',
                                                       'algo2', 2)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_2', pool_connection_info.base_url)
        self.assertEqual(4202, pool_connection_info.port)

    def test_resolve_pool_connection_info_from_pool_config_unknown_currency(
            self):
        pool_connection_info = resolve_connection_info(self.pool_config, 'c42',
                                                       'algo2', 2)

        self.assertIsNone(pool_connection_info)

    def test_resolve_pool_connection_info_from_pool_config_unknown_hash_algorithm(
            self):
        pool_connection_info = resolve_connection_info(self.pool_config, 'c2',
                                                       'algo42', 2)

        self.assertIsNone(pool_connection_info)

    def test_resolve_pool_connection_info_from_pool_config_c_not_none_a_not_none_d_none(
            self):
        # first difficulty == None else any first if not empty
        pool_connection_info = resolve_connection_info(self.pool_config, 'c2',
                                                       'algo2', None)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_3', pool_connection_info.base_url)
        self.assertEqual(4203, pool_connection_info.port)

    def test_resolve_pool_connection_info_from_pool_config_c_none_a_not_none_d_not_none(
            self):
        pool_connection_info = resolve_connection_info(self.pool_config, None,
                                                       'algo2', 2)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_2', pool_connection_info.base_url)
        self.assertEqual(4202, pool_connection_info.port)

    def test_resolve_pool_connection_info_from_pool_config_c_not_none_a_none_d_none(
            self):
        pool_connection_info = resolve_connection_info(self.pool_config, 'c2',
                                                       None, None)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_3', pool_connection_info.base_url)
        self.assertEqual(4203, pool_connection_info.port)

    def test_resolve_pool_connection_info_from_pool_config_c_none_a_not_none_d_none(
            self):
        pool_connection_info = resolve_connection_info(self.pool_config, None,
                                                       'algo2', None)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_3', pool_connection_info.base_url)
        self.assertEqual(4203, pool_connection_info.port)

    def test_resolve_pool_connection_info_from_pool_config_c_none_a_none_d_none(
            self):
        # for each: any first if not empty
        pool_connection_info = resolve_connection_info(self.pool_config, None,
                                                       None, None)

        self.assertEqual('pool1', pool_connection_info.pool_name)
        self.assertEqual('base_url_3', pool_connection_info.base_url)
        self.assertEqual(4203, pool_connection_info.port)
Exemplo n.º 3
0
 def test_matches_name_same_case(self):
     currency = Currency('Bitcoin', 'BTC')
     self.assertTrue(currency.matches('Bitcoin'))
Exemplo n.º 4
0
 def test_not_matches_name_or_symbol(self):
     currency = Currency('Bitcoin', 'BTC')
     self.assertFalse(currency.matches('Coin'))
Exemplo n.º 5
0
 def test_matches_symbol_not_same_case(self):
     currency = Currency('Bitcoin', 'BTC')
     self.assertTrue(currency.matches('btc'))
def _parse_currency_config(currency):
    return PoolCurrencyConfiguration(
        Currency(currency.name,
                 currency.symbol if hasattr(currency, 'symbol') else None), [])