Example #1
0
    def _check_blog(self, response: List[dict], count=10):
        """Small helper function to verify an RPC response contains valid blog records"""
        res = response

        log.debug(
            f'Length check if result from {self.host} has at least {count} results'
        )
        blog_len = len(res)
        if blog_len < count:
            raise ValidationError(
                f"Too little blog posts. Only {blog_len} blog results (<{count}) for {self.host}"
            )

        # Scan all items in the blog
        for item in res:
            if 'blog' not in item:
                raise ValidationError(
                    f"JSON key 'blog' not found in RPC query for node {self.host}"
                )
            if 'entry_id' not in item:
                raise ValidationError(
                    f"JSON key 'entry_id' not found in RPC query for node {self.host}"
                )
            if 'comment' not in item:
                raise ValidationError(
                    f"JSON key 'comment' not found in RPC query for node {self.host}"
                )

            if 'body' not in item['comment']:
                raise ValidationError(
                    f"JSON key 'body' not found in 'comment' dict from RPC query for node {self.host}"
                )
Example #2
0
    async def test_bridge_trending_topics(
            self,
            host=None,
            *args,
            **kwargs) -> Tuple[Union[list, dict], float, int]:
        """Test a node for functioning bridge.get_trending_topics"""
        host = empty_if(host, self.host)
        mtd = 'bridge.get_trending_topics'
        count = 10
        params = {"limit": count}
        res, tt, tr = await rpc(host=host, method=mtd, params=params)

        log.debug(
            f'bridge.get_trending_topics check if result from {host} has valid trending topics'
        )

        for a in res:
            if len(a) != 2:
                raise ValidationError(
                    f"Community result contained {len(a)} items (expected 2) in bridge.get_trending_topics response from {host}"
                )

            if 'hive-' not in a[0]:
                raise ValidationError(
                    f"Invalid community '{a[0]}' in bridge.get_trending_topics response from {host}"
                )

        return res, tt, tr
Example #3
0
 def _check_follower(self, item: dict):
     if 'follower' not in item:
         raise ValidationError(
             f"JSON key 'follower' not found in follower item from RPC query for node {self.host}"
         )
     if 'following' not in item:
         raise ValidationError(
             f"JSON key 'following' not found in follower item from RPC query for node {self.host}"
         )
     if 'what' not in item:
         raise ValidationError(
             f"JSON key 'what' not found in follower item from RPC query for node {self.host}"
         )
Example #4
0
    async def test_get_followers(
            self,
            host=None,
            *args,
            **kwargs) -> Tuple[Union[list, dict], float, int]:
        """Test a node for functioning full node get_followers"""
        host = empty_if(host, self.host)
        mtd = 'condenser_api.get_followers'
        count = 10
        params = [self.test_acc, None, "blog", count]
        res, tt, tr = await rpc(host=host, method=mtd, params=params)

        log.debug(
            f'Length check if result from {host} has at least {count} results')
        follow_len = len(res)
        if follow_len < count:
            raise ValidationError(
                f"Too little followers. Only {follow_len} follower results (<{count}) for {host}"
            )

        log.debug(
            f'get_followers check if result from {host} has valid follower items'
        )

        for follower in res:
            self._check_follower(follower)

        return res, tt, tr
Example #5
0
    def _check_hist(self, response: dict):
        """Small helper function to verify an RPC response contains valid account history records"""
        res = response

        # Get the first item from the history
        hist = res[0]
        if type(hist[0]) != int or type(hist[1]) != dict:
            raise ValidationError(
                f"History data is malformed in RPC query for node {self.host}")

        log.debug(
            f'Length check if result from {self.host} has at least 5 results')
        hist_len = len(res)
        if hist_len < 5:
            raise ValidationError(
                f"Too little history. Only {hist_len} history results (<5) for {self.host}"
            )
Example #6
0
    def _check_blog_item(self, item: dict):
        if 'body' not in item:
            raise ValidationError(
                f"JSON key 'body' not found in blog content from RPC query for node {self.host}"
            )

        if 'author' not in item:
            raise ValidationError(
                f"JSON key 'author' not found in blog content from RPC query for node {self.host}"
            )

        if 'category' not in item:
            raise ValidationError(
                f"JSON key 'category' not found in blog content from RPC query for node {self.host}"
            )

        if 'title' not in item:
            raise ValidationError(
                f"JSON key 'title' not found in blog content from RPC query for node {self.host}"
            )
Example #7
0
    async def test_condenser_witness(
            self,
            host=None,
            *args,
            **kwargs) -> Tuple[Union[list, dict], float, int]:
        """Test a node for functioning witness lookup (get_witness_by_account)"""
        host = empty_if(host, self.host)
        mtd, params = 'condenser_api.get_witness_by_account', [self.test_acc]
        res, tt, tr = await rpc(host=host, method=mtd, params=params)
        if res['owner'].lower().strip() != self.test_acc:
            raise ValidationError(
                f"Witness {res['owner']} was returned, but expected {self.test_acc} for node {host}"
            )
        prf = res['signing_key'][0:3]
        if prf != PUB_PREFIX:
            raise ValidationError(
                f"Signing key prefix was {prf} but expected {PUB_PREFIX} for node {host}"
            )

        return res, tt, tr
Example #8
0
    async def test_account_history(
            self,
            host=None,
            *args,
            **kwargs) -> Tuple[Union[list, dict], float, int]:
        """Test a node for functioning account_history_api account history"""
        host = empty_if(host, self.host)
        mtd = 'account_history_api.get_account_history'
        params = dict(account=self.test_acc, start=-1, limit=100)
        res, tt, tr = await rpc(host=host, method=mtd, params=params)

        log.debug(f'History check if result from {host} has history key')
        if 'history' not in res:
            raise ValidationError(
                f"JSON key 'history' not found in RPC query for node {host}")

        self._check_hist(res['history'])
        return res, tt, tr
Example #9
0
    async def test_condenser_account(
            self,
            host=None,
            *args,
            **kwargs) -> Tuple[Union[list, dict], float, int]:
        """Test a node for functioning condenser_api get_accounts query"""
        host = empty_if(host, self.host)
        mtd, params = 'condenser_api.get_accounts', [
            [self.test_acc],
        ]
        res, tt, tr = await rpc(host=host, method=mtd, params=params)

        # Normal python exceptions such as IndexError should be thrown if the data isn't formatted correctly
        acc = res[0]
        log.debug(f'Checking if result from {host} has user {self.test_acc}')
        if acc['name'].lower().strip() != self.test_acc:
            raise ValidationError(
                f"Account {acc['name']} was returned, but expected {self.test_acc} for node {host}"
            )
        log.debug(f'Success - result from {host} has user {self.test_acc}')
        return res, tt, tr