Exemplo n.º 1
0
    def test_valid_address(self):
        for symbol in self.currencies:
            with self.subTest(symbol):
                api_classes = blockapi.get_api_classes_for_coin(symbol)
                addresses = test_addresses[symbol]

                for api_class, address in itertools.product(
                        api_classes, addresses):
                    #if 'api_key' in api_class.__init__.__code__.co_varnames:
                    #    continue

                    try:
                        api_inst = api_class(address)
                    except APIKeyMissing:
                        # skip test if api key is required
                        continue

                    if not api_inst.xpub_support and address.startswith(
                            'xpub'):
                        # skip testing against xpub address if xpub is not supported
                        continue

                    try:
                        b = api_inst.get_balance()
                    except (AddressNotExist, BadGateway, GatewayTimeOut,
                            InternalServerError, APIError,
                            CloudflareCaptchaError):
                        self.fail(
                            "get_balance for {} [{}] failed unexpectedly with a valid address {}"
                            .format(api_inst.__class__.__name__, symbol,
                                    address))
Exemplo n.º 2
0
    def test_invalid_address(self):
        for symbol in self.currencies:
            with self.subTest(symbol):
                api_classes = blockapi.get_api_classes_for_coin(symbol)
                addresses = test_invalid_addresses[symbol]

                for api_class, address in itertools.product(api_classes, addresses):
                    #if 'api_key' in api_class.__init__.__code__.co_varnames:
                    #    continue

                    try:
                        api_inst = api_class(address)
                        assert not api_inst.address_info.valid
                    except APIKeyMissing:
                        continue
Exemplo n.º 3
0
    def test_get_balance(self):
        for symbol in self.currencies:
            with self.subTest(symbol):
                api_classes = blockapi.get_api_classes_for_coin(symbol)
                addresses = test_addresses[symbol]

                for api_class, address in itertools.product(
                        api_classes, addresses):
                    #if 'api_key' in api_class.__init__.__code__.co_varnames:
                    #    continue

                    try:
                        api_inst = api_class(address)
                    except APIKeyMissing:
                        continue

                    if not api_inst.xpub_support and address.startswith(
                            'xpub'):
                        # skip testing against xpub address if xpub is not supported
                        continue

                    try:
                        b = api_inst.get_balance()
                    except:
                        self.fail(
                            "get_balance for {} [{}] - {} failed unexpectedly".
                            format(api_inst.__class__.__name__, symbol,
                                   address))
                    is_ok = True

                    try:
                        tmp = float(b)
                    except (ValueError, TypeError):
                        is_ok = False

                    if not is_ok:
                        is_ok = True
                        if not isinstance(b, list):
                            is_ok = False

                    if not is_ok:
                        self.fail(
                            "get_balance for {} [{}] failed unexpectedly - returned value is not a number or list"
                            .format(api_inst.__class__.__name__, symbol))
Exemplo n.º 4
0
    def run(self):
        """Runs tests for given data"""

        for currency in self.data:
            classes = get_api_classes_for_coin(symbol=currency['currency'])

            for class_ in classes:

                # try to load api_key
                api_key = get_test_api_key(class_.__name__)
                try:
                    class_instance = class_(address=currency['address'],
                                            api_key=api_key)
                except Exception as e:
                    self.error_api.append({
                        'api': class_.__name__,
                        'error': 'Init error',
                        'message': e
                    })
                    continue

                for method in self.methods:
                    try:
                        self.results[method].append({
                            'result':
                            getattr(class_instance, method)(),
                            'api':
                            class_.__name__,
                            'currency':
                            currency['currency'],
                            'success':
                            True
                        })
                    except Exception as e:
                        self.error_api.append({
                            'api': class_.__name__,
                            'error': f'{method} error',
                            'message': e
                        })