예제 #1
0
    def test_bitcoin_send_low_balance(self):
        """Test :class:`.NotEnoughBalance` is raised when sending too much"""
        mgr = ch.get_manager('BTC')

        bal = mgr.balance()
        with self.assertRaises(NotEnoughBalance):
            mgr.send(bal * Decimal('2'), '1Br7KPLQJFuS2naqidyzdciWUYhnMZAzKA')
예제 #2
0
 def test_bitcoin_get_deposit(self):
     """Test BitcoinManager get_deposit returns the correct deposit type and a valid looking address"""
     mgr = ch.get_manager('BTC')
     dep_type, addr = mgr.get_deposit()
     self.assertEqual(dep_type, 'address')
     self.assertEqual(addr[0], '1')
     self.assertGreater(len(addr), 20)
예제 #3
0
    def test_bitcoin_send(self):
        """Test a valid send call works as expected"""
        mgr = ch.get_manager('BTC')
        dep_type, addr = mgr.get_deposit()

        tx = mgr.send(Decimal('0.001'), address=addr)
        self.assertEqual(tx['coin'], 'BTC')
        self.assertEqual(tx['amount'], Decimal('0.001'))
        self.assertEqual(tx['send_type'], 'send')
        self.assertEqual(tx['fee'], Decimal('0'))
def init_privex_handler(name: str):
    """
    Attempt to import a :py:mod:`privex.coin_handlers` handler module, adapting it for SteemEngine's older
    Coin Handler system.
    
     * Extracts the handler type and description for injection into ``settings.COIN_TYPES`` (since privex handlers
       are framework independent and cannot auto-inject into ``settings.COIN_TYPE``)
     * Configures the Privex coin_handlers coin object based on a database :class:`.Coin` row
     * Detects coins which are mapped to a Privex coin handler and registers the handler's manager/loader into
       the global handlers dictionary
     
    :param str name: The name of a :py:mod:`privex.coin_handlers` handler module, e.g. ``Golos``
    """
    from payments.models import Coin

    modpath = name if '.' in name else f'privex.coin_handlers.{name}'

    i = import_module(modpath)
    ctype, cdesc = i.COIN_TYPE, i.HANDLER_DESC

    # Inject the handler type + description into settings.COIN_TYPE if it's not already there, so it can be used
    # in the admin panel and other areas.
    if ctype not in dict(settings.COIN_TYPES):
        log.debug('(Privex) %s not in COIN_TYPES, adding it.', ctype)
        settings.COIN_TYPES += ((
            ctype,
            cdesc,
        ), )

    # Find any coins which are already configured to use this handler, then register the Privex coin handler with
    # the global handler storage
    hcoins = Coin.objects.filter(coin_type=ctype)
    for coin in hcoins:  # type: Coin
        ch.configure_coin(coin.symbol_id,
                          our_account=coin.our_account,
                          display_name=coin.display_name,
                          **coin.settings,
                          **coin.settings['json'])
        ch.add_handler_coin(name, coin.symbol_id)
        if coin.symbol not in handlers:
            handlers[coin.symbol] = dict(loaders=[], managers=[])
        # After re-configuring each coin, we need to reload Privex's coin handlers before getting the manager/loader
        ch.reload_handlers()
        # We hand off to privex.coin_handlers.get_manager/loader to initialise the handler's classes, rather than
        # trying to do it ourselves. Then we register them with the global handler store.
        handlers[coin.symbol]['managers'].append(ch.get_manager(
            coin.symbol_id))
        handlers[coin.symbol]['loaders'].append(ch.get_loader(coin.symbol_id))
예제 #5
0
    def test_bitcoin_send_invalid_addr(self):
        """Test :class:`.AccountNotFound` is raised when sending to non-existent address"""
        mgr = ch.get_manager('BTC')

        with self.assertRaises(AccountNotFound):
            mgr.send(Decimal('0.001'), address='NotAnAddress')
예제 #6
0
 def test_bitcoin_validate(self):
     """Test BitcoinManager address_valid returns True for valid addr and False for invalid"""
     mgr = ch.get_manager('BTC')
     self.assertTrue(
         mgr.address_valid('1Br7KPLQJFuS2naqidyzdciWUYhnMZAzKA'))
     self.assertFalse(mgr.address_valid('NotAnAddress'))