Пример #1
0
 def test_info_not_call_encrypt_decrypt(self, call_api, unlock, lock):
     api = ScryptRpcApiClient()
     curr = Currency(code='BTC', wallet='rpc5')
     api.get_info(curr)
     self.assertEqual(call_api.call_count, 1)
     self.assertEqual(unlock.call_count, 0)
     self.assertEqual(lock.call_count, 0)
Пример #2
0
 def test_release_call_decrypt(self, get_pass, get_api, call_api, unlock,
                               lock):
     get_pass.return_value = 'randomPass'
     get_api.return_value = mock.MagicMock()
     api = ScryptRpcApiClient()
     curr = Currency(code='BTC', wallet='rpc5')
     addr = Address()
     amount = 42
     api.release_coins(curr, addr, amount)
     self.assertEqual(call_api.call_count, 1)
     self.assertEqual(lock.call_count, 1)
     get_api.assert_called_with('rpc5')
Пример #3
0
class ApiClientFactory:
    UPHOLD = UpholdApiClient()
    SCRYPT = ScryptRpcApiClient()
    ETHASH = EthashRpcApiClient()
    BITTREX = BittrexApiClient()
    KRAKEN = KrakenApiClient()
    BLAKE2 = Blake2RpcApiClient()
    ZCASH = ZcashRpcApiClient()
    OMNI = OmniRpcApiClient()
    CRYPTONIGHT = CryptonightRpcApiClient()
    RIPPLE = RippleRpcApiClient()

    @classmethod
    def get_api_client(cls, node):
        if node in cls.UPHOLD.related_nodes:
            return cls.UPHOLD
        elif node in cls.SCRYPT.related_nodes:
            return cls.SCRYPT
        elif node in cls.BITTREX.related_nodes:
            return cls.BITTREX
        elif node in cls.KRAKEN.related_nodes:
            return cls.KRAKEN
        elif node in cls.ETHASH.related_nodes:
            return cls.ETHASH
        elif node in cls.BLAKE2.related_nodes:
            return cls.BLAKE2
        elif node in cls.ZCASH.related_nodes:
            return cls.ZCASH
        elif node in cls.OMNI.related_nodes:
            return cls.OMNI
        elif node in cls.CRYPTONIGHT.related_nodes:
            return cls.CRYPTONIGHT
        elif node in cls.RIPPLE.related_nodes:
            return cls.RIPPLE
Пример #4
0
    def test_do_not_release_if_same_tx_available_xvg(self,
                                                     release_coins,
                                                     scrypt_health,
                                                     list_txs):
        # XVG has 6 decimal points rounding on most wallets so need
        # to make sure
        actual_rounding = 6
        legacy_rounding = 8
        xvg = Currency.objects.get(code='XVG')

        xvg.rounding = legacy_rounding
        xvg.save()
        scrypt_health.return_value = {}
        scrypt = ScryptRpcApiClient()
        amount = Decimal('100.12345678')
        order_legacy = self._create_paid_order(
            pair_name='XVGBTC', amount_base=amount
        )

        xvg.rounding = actual_rounding
        xvg.save()
        self.assertEqual(order_legacy.amount_base, amount)
        xvg.rounding = actual_rounding
        xvg.save()
        amount_on_blockchain = money_format(amount, places=actual_rounding)
        order = self._create_paid_order(pair_name='XVGBTC', amount_base=amount)
        self.assertEqual(order.amount_base, amount_on_blockchain)
        list_txs.return_value = [{
            'account': '',
            'address': order.withdraw_address.address,
            'category': 'send',
            'amount': -amount_on_blockchain,
            'txid': self.generate_txn_id(),
        }]
        scrypt_health.return_value = {}
        order.refresh_from_db()
        order.pair.base.refresh_from_db()
        with self.assertRaises(ValidationError):
            scrypt.assert_tx_unique(
                order.pair.base, order.withdraw_address, order.amount_base
            )
        order_legacy.refresh_from_db()
        order_legacy.pair.base.refresh_from_db()
        with self.assertRaises(ValidationError):
            scrypt.assert_tx_unique(
                order_legacy.pair.base, order_legacy.withdraw_address,
                order_legacy.amount_base
            )
        self.assertEqual(order.status, order.PAID)
        exchange_order_release_periodic.apply_async()
        order.refresh_from_db()
        self.assertEqual(order.status, order.PRE_RELEASE)
        release_coins.assert_not_called()
        self.assertTrue(order.flagged)
Пример #5
0
 def queryset(self, request, queryset):
     if self.value() == 'SCRYPT':
         _client = ScryptRpcApiClient()
     elif self.value() == 'ETHASH':
         _client = EthashRpcApiClient()
     elif self.value() == 'OMNI':
         _client = OmniRpcApiClient()
     elif self.value() == 'MONERO':
         _client = CryptonightRpcApiClient()
     elif self.value() == 'NANO':
         _client = Blake2RpcApiClient()
     elif self.value() == 'ZCASH':
         _client = ZcashRpcApiClient()
     elif self.value() == 'RIPPLE':
         _client = RippleRpcApiClient()
     else:
         return queryset
     nodes = _client.related_nodes
     return queryset.filter(currency__wallet__in=nodes)
Пример #6
0
from nexchange.rpc.scrypt import ScryptRpcApiClient
from nexchange.rpc.ethash import EthashRpcApiClient
from nexchange.rpc.blake2 import Blake2RpcApiClient
from nexchange.rpc.zcash import ZcashRpcApiClient
from nexchange.rpc.omni import OmniRpcApiClient
from nexchange.rpc.cryptonight import CryptonightRpcApiClient
from nexchange.rpc.ripple import RippleRpcApiClient

scrypt_client = ScryptRpcApiClient()
ethash_client = EthashRpcApiClient()
blake2_client = Blake2RpcApiClient()
zcash_client = ZcashRpcApiClient()
omni_client = OmniRpcApiClient()
cryptonight_client = CryptonightRpcApiClient()
ripple_client = RippleRpcApiClient()

assert \
    scrypt_client.related_nodes[0] \
    != scrypt_client.related_nodes[1] \
    != scrypt_client.related_nodes[2] \
    != scrypt_client.related_nodes[3] \
    != scrypt_client.related_nodes[4] \
    != scrypt_client.related_nodes[5] \
    != zcash_client.related_nodes[0] \
    != omni_client.related_nodes[0] \
    != ethash_client.related_nodes[0] \
    != blake2_client.related_nodes[0] \
    != cryptonight_client.related_nodes[0] \
    != ripple_client.related_nodes[0]

clients_lookup = {
Пример #7
0
 def move_order_status_up(self, order, _from, _to, list_txs):
     list_txs.return_value = []
     api = ScryptRpcApiClient()
     sc = SafeChargeListenView()
     while order.status != _to:
         _before = order.status
         _crypto = order.pair.is_crypto
         if order.status == Order.INITIAL:
             tx_data = {
                 'order': order,
                 'currency': order.pair.quote,
                 'type': Transaction.DEPOSIT,
             }
             if not _crypto:
                 pref = sc.get_or_create_payment_preference(
                     self.generate_txn_id(),
                     'Test McFerrin',
                     order.unique_reference,
                     order.payment_preference.payment_method,
                 )
                 tx_data.update({
                     'amount_cash':
                     order.amount_quote,
                     'user':
                     order.user,
                     'payment_preference':
                     pref,
                     'payment_system_id':
                     self.generate_txn_id(),
                     'secondary_payment_system_id':
                     self.generate_txn_id(),
                     'auth_code':
                     self.generate_txn_id(),
                     'reference':
                     order.unique_reference,
                 })
             else:
                 tx_data.update({
                     'amount': order.amount_quote,
                     'address_to': order.deposit_address
                 })
             order.register_deposit(tx_data, crypto=order.pair.is_crypto)
         elif order.status == Order.PAID_UNCONFIRMED:
             tx = order.transactions.get() if _crypto else order.\
                 payment_set.get()
             order.confirm_deposit(tx, crypto=_crypto)
         elif order.status == Order.PAID:
             with patch(SCRYPT_ROOT + 'health_check') as _health:
                 _health.return_value = True
                 order.pre_release(api=api)
         elif order.status == Order.PRE_RELEASE:
             tx_data = {
                 'order': order,
                 'address_to': order.withdraw_address,
                 'amount': order.amount_base,
                 'currency': order.pair.base,
                 'type': Transaction.WITHDRAW
             }
             with patch(SCRYPT_ROOT + 'release_coins') as _release:
                 _release.return_value = self.generate_txn_id(), True
                 order.release(tx_data, api=api)
         elif order.status == Order.RELEASED:
             tx = order.transactions.get(type='W') if _crypto else order. \
                 payment_set.get()
             order.complete(tx)
         self.assertEqual(_before + 1, order.status)