Пример #1
0
    def test_do_not_release_if_transaction_is_not_unique(self,
                                                         mock_release_coins,
                                                         mock_health_check,
                                                         mock):
        mock_health_check.return_value = True
        amount_base = 10
        withdraw_address = \
            'xrb_1111111111111111111111111111111111111111111111111111hifc8npp'
        order = self._create_paid_order_api('NANOBTC', amount_base,
                                            withdraw_address)
        NANO = order.pair.base

        def text_callback(request, context):
            body = request._request.body
            params = json.loads(body)
            if all([params.get('action') == 'account_list',
                    params.get('wallet')]):
                return {'accounts': [order.deposit_address.address,
                                     RPC8_PUBLIC_KEY_C1]}
            if all([params.get('action') == 'account_history',
                    params.get('account'), params.get('count')]):
                return self.get_blake2_raw_tx_send(
                    NANO, order.amount_base, withdraw_address
                )

        mock.post(RPC8_URL, json=text_callback)
        exchange_order_release_periodic.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.PRE_RELEASE)
        self.assertTrue(order.flagged, True)
        self.assertEqual(mock_release_coins.call_count, 0)
Пример #2
0
    def test_release_ripple_order(self, pair_name, mock, mock_list_txs):
        mock_list_txs.return_value = []
        amount_base = 10
        withdraw_address = 'r9y63YwVUQtTWHtwcmYc1Epa5KvstfUzSm'
        dest_tag = '123456'
        order = self._create_paid_order_api(pair_name, amount_base,
                                            withdraw_address, dest_tag)

        with_tx_id = self.generate_txn_id()
        value = amount_base * (10**order.pair.base.decimals)
        card_address = RPC13_PUBLIC_KEY_C1

        def text_callback(request, context):
            body = request._request.body
            params = json.loads(body)
            if params.get('method') == 'account_info':
                return {
                    'result': {
                        'account_data': {
                            'Account': card_address,
                            'Balance': '16730415294',
                        },
                        'status': 'success',
                        'validated': False
                    }
                }
            if params.get('method') == 'ledger':
                return {'result': {'closed': {'status': 'success'}}}
            if params.get('method') == 'sign':
                return self.get_ripple_sign_response(card_address, value,
                                                     withdraw_address,
                                                     dest_tag, with_tx_id)
            if params.get('method') == 'submit':
                sign_resp = self.get_ripple_sign_response(
                    card_address, value, withdraw_address, dest_tag,
                    with_tx_id)
                sign_resp['result']['engine_result'] = 'tesSUCCESS'
                return sign_resp
            if params.get('method') == 'tx':
                return self.get_ripple_raw_tx(value, withdraw_address,
                                              dest_tag, with_tx_id)

        mock.post(RPC13_URL, json=text_callback)
        reserves_balance_checker_periodic.apply()
        self.assertTrue(order.coverable)
        exchange_order_release_periodic.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.RELEASED, pair_name)
        tx_w = order.transactions.get(type='W')
        self.assertEqual(tx_w.tx_id, with_tx_id)
        self.assertEqual(tx_w.amount, order.amount_base)
        self.update_confirmation_task.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.COMPLETED, pair_name)
Пример #3
0
    def test_release_omni_order(self, pair_name, mock_call_api, is_coverable,
                                mock_validate_order_amount, mock_lock,
                                mock_unlock, mock_get_main_address,
                                mock_health_check):
        mock_health_check.return_value = \
            mock_lock.return_value = \
            mock_unlock.return_value = True
        is_coverable.return_value = True
        mock_validate_order_amount.start()
        amount_base = 10
        with_tx_id = self.generate_txn_id()
        withdraw_address = '1AnjHn7L7X4di46HF9Sxm7T7fKEkwqefvb'
        mock_amount = self.order.amount_quote
        mock_get_main_address.return_value = 'reserve_address'

        def side_effect(*args):
            if args[1] == 'omni_listtransactions':
                return []
            if args[1] == 'omni_listpendingtransactions':
                return self.get_omni_raw_txs(mock_amount, 'reserve_address')
            if args[1] == 'omni_gettransaction':
                return self.get_omni_tx_raw_confirmed(mock_amount,
                                                      'reserve_address')
            if args[1] == 'omni_getbalance':
                return {
                    'balance': "100.00000000",
                    'reserved': "0",
                    'frozen': "0"
                }
            if args[1] == 'omni_send':
                return with_tx_id
            if args[1] == 'getaddressesbyaccount':
                return ['reserve_address']

        mock_call_api.side_effect = side_effect

        order = self._create_paid_order_api(pair_name, amount_base,
                                            withdraw_address)
        reserves_balance_checker_periodic.apply()

        self.assertTrue(order.coverable)
        exchange_order_release_periodic.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.RELEASED, pair_name)
        tx_w = order.transactions.get(type='W')
        self.assertEqual(tx_w.tx_id, with_tx_id)
        self.assertEqual(tx_w.amount, order.amount_base)
        self.update_confirmation_task.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.COMPLETED, pair_name)
        mock_validate_order_amount.stop()
Пример #4
0
    def test_release_blake2_order(self, pair_name, mock,
                                  mock_list_txs):
        mock_list_txs.return_value = []
        amount_base = 10
        withdraw_address = \
            'xrb_1111111111111111111111111111111111111111111111111111hifc8npp'
        order = self._create_paid_order_api(pair_name, amount_base,
                                            withdraw_address)
        with_tx_id = self.generate_txn_id()
        value = amount_base * (10**order.pair.base.decimals)

        def text_callback(request, context):
            body = request._request.body
            params = json.loads(body)
            if all([params.get('action') == 'account_balance',
                    params.get('account')]):
                return {'balance': str(value * 2), 'pending': '0'}
            if all([params.get('action') == 'send',
                    params.get('wallet'),
                    params.get('source') == RPC8_PUBLIC_KEY_C1,
                    params.get('destination') == withdraw_address,
                    params.get('amount') == str(value)]):
                return {'block': with_tx_id}
            if all([params.get('action') == 'password_enter',
                    params.get('wallet'), 'password' in params]):
                return {'valid': 1}
            if all([params.get('action') == 'pending_exists',
                    params.get('hash') == with_tx_id]):
                return {'exists': '0'}

        mock.post(RPC8_URL, json=text_callback)
        reserves_balance_checker_periodic.apply()
        self.assertTrue(order.coverable)
        exchange_order_release_periodic.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.RELEASED, pair_name)
        tx_w = order.transactions.get(type='W')
        self.assertEqual(tx_w.tx_id, with_tx_id)
        self.assertEqual(tx_w.amount, order.amount_base)
        self.update_confirmation_task.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.COMPLETED, pair_name)
Пример #5
0
    def test_do_not_release_if_transaction_is_not_unique(
            self, mock_call_api, mock_validate_order_amount, mock_health_check,
            mock_release_coins):
        mock_health_check.return_value = True
        withdraw_address = '1AnjHn7L7X4di46HF9Sxm7T7fKEkwqefvb'
        amount_base = 0.5
        order = self._create_paid_order_api('USDTBTC', amount_base,
                                            withdraw_address)
        mock_validate_order_amount.start()

        def side_effect(*args):
            if args[1] == 'omni_listtransactions':
                return self.get_omni_raw_txs(str(amount_base),
                                             withdraw_address)

        mock_call_api.side_effect = side_effect
        exchange_order_release_periodic.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.PRE_RELEASE)
        self.assertTrue(order.flagged, True)
        self.assertEqual(mock_release_coins.call_count, 0)
        mock_validate_order_amount.stop()
Пример #6
0
 def test_release_ethash_order_with_util(self, pair_name, get_balance,
                                         unlock, lock, send_tx, eth_listen,
                                         eth_list_txs):
     eth_list_txs.return_value = []
     eth_listen.return_value = True
     amount_base = 50
     pair = Pair.objects.get(name=pair_name)
     base = pair.base
     if base.minimal_amount >= Decimal(amount_base):
         base.minimal_amount = Decimal(amount_base) / Decimal('2')
         base.save()
     order = self._create_paid_order_api(
         pair_name, amount_base,
         '0x77454e832261aeed81422348efee52d5bd3a3684')
     get_balance.return_value = amount_base * 2
     reserves_balance_checker_periodic.apply()
     send_tx.return_value = None
     exchange_order_release_periodic.apply()
     order.refresh_from_db()
     self.assertEqual(order.status, Order.PRE_RELEASE, pair_name)
     self.assertEqual(send_tx.call_count, 1)
     pre_called_with = send_tx.call_args[0][0]
     send_tx.return_value = tx_id = self.generate_txn_id()
     release_order(order)
     self.assertEqual(send_tx.call_count, 2)
     order.refresh_from_db()
     self.assertEqual(order.status, Order.RELEASED, pair_name)
     called_with = send_tx.call_args[0][0]
     self.assertEqual(called_with, pre_called_with)
     tx = order.transactions.get(type='W')
     self.assertEqual(tx.tx_id, tx_id)
     self.assertEqual(tx.address_to, order.withdraw_address)
     self.assertEqual(called_with['to'], order.withdraw_address.address)
     self.assertEqual(tx.amount, order.amount_base)
     self.assertEqual(
         Decimal(called_with['value']) * Decimal('1e-18'),
         order.amount_base)
Пример #7
0
 def test_release_ethash_order(self, pair_name, get_balance, unlock, lock,
                               send_tx, get_tx_eth, get_block_eth,
                               get_tx_eth_receipt, eth_listen,
                               eth_list_txs):
     eth_list_txs.return_value = []
     eth_listen.return_value = True
     amount_base = 50
     pair = Pair.objects.get(name=pair_name)
     base = pair.base
     if base.minimal_amount >= Decimal(amount_base):
         base.minimal_amount = Decimal(amount_base) / Decimal('2')
         base.save()
     order = self._create_paid_order_api(
         pair_name, amount_base,
         '0x77454e832261aeed81422348efee52d5bd3a3684')
     get_balance.return_value = amount_base * 2
     reserves_balance_checker_periodic.apply()
     send_tx.return_value = self.generate_txn_id()
     exchange_order_release_periodic.apply()
     order.refresh_from_db()
     self.assertEqual(order.status, Order.RELEASED, pair_name)
     get_tx_eth_receipt.return_value = self.get_ethash_tx_receipt_raw(
         order.pair.base,
         order.amount_base,
         status=1,
         _to=order.withdraw_address.address)
     confs = order.pair.base.min_confirmations + 1
     get_tx_eth.return_value = self.get_ethash_tx_raw(
         order.pair.base,
         order.amount_base,
         order.withdraw_address.address,
         block_number=0)
     get_block_eth.return_value = confs
     self.update_confirmation_task.apply()
     order.refresh_from_db()
     self.assertEqual(order.status, Order.COMPLETED, pair_name)
Пример #8
0
    def test_release_cryptonight_order(self, pair_name, mock,
                                       mock_assert_tx_unique):
        amount_base = 10
        withdraw_address = \
            '41pLNkSGSJK8pWAG9dd57YcWB82gH5ucHNEPnGt1FBN' \
            '59PrdYqKUGB1SfZxGQPcYcDEbctmpN2kpVbtupm6yCRf16oXkjuY'
        payment_id = '0123456789ABCDEF'
        order = self._create_paid_order_api(pair_name, amount_base,
                                            withdraw_address, payment_id)
        with_tx_id = self.generate_txn_id()
        value = amount_base * (10**order.pair.base.decimals)

        def text_callback(request, context):
            body = request._request.body
            params = json.loads(body)
            if params.get('method') == 'transfer':
                return {
                    "id": "0",
                    "jsonrpc": "2.0",
                    "result": {
                        "amount":
                        value,
                        "fee":
                        939900000,
                        "multisig_txset":
                        "",
                        "tx_hash":
                        with_tx_id,
                        "tx_key":
                        "63e660b49ff678fa6f7f4a103977d96646"
                        "f4c564c0c37e9bed50d019939cae06",
                    }
                }
            if params.get('method') in ['open_wallet', 'store']:
                return {'id': 0, 'jsonrpc': '2.0', 'result': {}}
            if params.get('method') == 'get_transfer_by_txid':
                return {
                    'id': 0,
                    'jsonrpc': '2.0',
                    'result': {
                        'transfer': {
                            'double_spend_seen': False,
                            'height': 10
                        }
                    }
                }
            if params.get('method') in ['getheight', 'get_info']:
                return {'id': 0, 'jsonrpc': '2.0', 'result': {"height": 21}}
            if params.get('method') == 'getbalance':
                return {
                    'id': '0',
                    'jsonrpc': '2.0',
                    'result': {
                        'balance': value * 2,
                        'unlocked_balance': value * 2
                    }
                }

        mock.post(RPC11_URL, json=text_callback)
        reserves_balance_checker_periodic.apply()
        self.assertTrue(order.coverable)
        exchange_order_release_periodic.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.RELEASED, pair_name)
        tx_w = order.transactions.get(type='W')
        self.assertEqual(tx_w.tx_id, with_tx_id)
        self.assertEqual(tx_w.amount, order.amount_base)
        self.update_confirmation_task.apply()
        order.refresh_from_db()
        self.assertEqual(order.status, Order.COMPLETED, pair_name)