# Path: duniterpy/api/endpoint.py
# class BMAEndpoint(Endpoint):
#     API = "BASIC_MERKLED_API"
#     re_inline = re.compile(
#         "^BASIC_MERKLED_API(?: ({host_regex}))?(?: ({ipv4_regex}))?(?: ({ipv6_regex}))?(?: ([0-9]+))$".format(
#             host_regex=constants.HOST_REGEX,
#             ipv4_regex=constants.IPV4_REGEX,
#             ipv6_regex=constants.IPV6_REGEX,
#         )
#     )
# 
#     def __init__(self, server: str, ipv4: str, ipv6: str, port: int) -> None:
#         """
#         Init BMAEndpoint instance
# 
#         :param server: IP or domain name
#         :param ipv4: IP as IPv4 format
#         :param ipv6: IP as IPv6 format
#         :param port: Port number
#         """
#         self.server = server
#         self.ipv4 = ipv4
#         self.ipv6 = ipv6
#         self.port = port
# 
#     @classmethod
#     def from_inline(cls: Type[BMAEndpointType], inline: str) -> BMAEndpointType:
#         """
#         Return BMAEndpoint instance from endpoint string
# 
#         :param inline: Endpoint string
#         :return:
#         """
#         m = BMAEndpoint.re_inline.match(inline)
#         if m is None:
#             raise MalformedDocumentError(BMAEndpoint.API)
#         server = m.group(1)
#         ipv4 = m.group(2)
#         ipv6 = m.group(3)
#         port = int(m.group(4))
#         return cls(server, ipv4, ipv6, port)
# 
#     def inline(self) -> str:
#         """
#         Return endpoint string
# 
#         :return:
#         """
#         return BMAEndpoint.API + "{DNS}{IPv4}{IPv6}{PORT}".format(
#             DNS=(" {0}".format(self.server) if self.server else ""),
#             IPv4=(" {0}".format(self.ipv4) if self.ipv4 else ""),
#             IPv6=(" {0}".format(self.ipv6) if self.ipv6 else ""),
#             PORT=(" {0}".format(self.port) if self.port else ""),
#         )
# 
#     def conn_handler(
#         self, session: ClientSession, proxy: str = None
#     ) -> ConnectionHandler:
#         """
#         Return connection handler instance for the endpoint
# 
#         :param session: AIOHTTP client session instance
#         :param proxy: Proxy url
#         :return:
#         """
#         if self.server:
#             conn_handler = ConnectionHandler(
#                 "http", "ws", self.server, self.port, "", session, proxy
#             )
#         elif self.ipv6:
#             conn_handler = ConnectionHandler(
#                 "http", "ws", "[{0}]".format(self.ipv6), self.port, "", session, proxy
#             )
#         else:
#             conn_handler = ConnectionHandler(
#                 "http", "ws", self.ipv4, self.port, "", session, proxy
#             )
# 
#         return conn_handler
# 
#     def __str__(self) -> str:
#         return self.inline()
# 
#     def __eq__(self, other: Any) -> bool:
#         if not isinstance(other, BMAEndpoint):
#             return NotImplemented
#         return (
#             self.server == other.server
#             and self.ipv4 == other.ipv4
#             and self.ipv6 == other.ipv6
#             and self.port == other.port
#         )
# 
#     def __hash__(self) -> int:
#         return hash((self.server, self.ipv4, self.ipv6, self.port))


import unittest
import jsonschema
from jsonschema import SchemaError, ValidationError
from duniterpy.api.bma.blockchain import (
    parameters,
    block,
    current,
    hardship,
    memberships,
    newcomers,
    certifications,
    joiners,
    actives,
    leavers,
    ud,
    tx,
    BLOCK_NUMBERS_SCHEMA,
    BLOCK_SCHEMA,
    BLOCKS_SCHEMA,
    HARDSHIP_SCHEMA,
    MEMBERSHIPS_SCHEMA,
    PARAMETERS_SCHEMA,
)
from duniterpy.api.client import Client
from duniterpy.api.endpoint import BMAEndpoint
from tests.api.webserver import WebFunctionalSetupMixin, web
            "sigValidity": 63115200,
            "sigQty": 5,
            "idtyWindow": 5259600,
            "msWindow": 5259600,
            "xpercent": 0.8,
            "msValidity": 31557600,
            "stepMax": 5,
            "medianTimeBlocks": 24,
            "avgGenTime": 300,
            "dtDiffEval": 12,
            "percentRot": 0.67,
            "udTime0": 1488970800,
            "udReevalTime0": 1490094000,
            "dtReeval": 15778800,
        }
        try:
            jsonschema.validate(json_sample, PARAMETERS_SCHEMA)
        except (SchemaError, ValidationError) as e:
            raise self.failureException from e

    def test_parameters_bad(self):
        async def handler(request):
            await request.read()
            return web.Response(body=b"{}", content_type="application/json")

        async def go():
            _, port, _ = await self.create_server(
                "GET", "/blockchain/parameters", handler
            )
            with self.assertRaises(jsonschema.exceptions.ValidationError):

# Path: duniterpy/api/endpoint.py
# class BMAEndpoint(Endpoint):
#     API = "BASIC_MERKLED_API"
#     re_inline = re.compile(
#         "^BASIC_MERKLED_API(?: ({host_regex}))?(?: ({ipv4_regex}))?(?: ({ipv6_regex}))?(?: ([0-9]+))$".format(
#             host_regex=constants.HOST_REGEX,
#             ipv4_regex=constants.IPV4_REGEX,
#             ipv6_regex=constants.IPV6_REGEX,
#         )
#     )
# 
#     def __init__(self, server: str, ipv4: str, ipv6: str, port: int) -> None:
#         """
#         Init BMAEndpoint instance
# 
#         :param server: IP or domain name
#         :param ipv4: IP as IPv4 format
#         :param ipv6: IP as IPv6 format
#         :param port: Port number
#         """
#         self.server = server
#         self.ipv4 = ipv4
#         self.ipv6 = ipv6
#         self.port = port
# 
#     @classmethod
#     def from_inline(cls: Type[BMAEndpointType], inline: str) -> BMAEndpointType:
#         """
#         Return BMAEndpoint instance from endpoint string
# 
#         :param inline: Endpoint string
#         :return:
#         """
#         m = BMAEndpoint.re_inline.match(inline)
#         if m is None:
#             raise MalformedDocumentError(BMAEndpoint.API)
#         server = m.group(1)
#         ipv4 = m.group(2)
#         ipv6 = m.group(3)
#         port = int(m.group(4))
#         return cls(server, ipv4, ipv6, port)
# 
#     def inline(self) -> str:
#         """
#         Return endpoint string
# 
#         :return:
#         """
#         return BMAEndpoint.API + "{DNS}{IPv4}{IPv6}{PORT}".format(
#             DNS=(" {0}".format(self.server) if self.server else ""),
#             IPv4=(" {0}".format(self.ipv4) if self.ipv4 else ""),
#             IPv6=(" {0}".format(self.ipv6) if self.ipv6 else ""),
#             PORT=(" {0}".format(self.port) if self.port else ""),
#         )
# 
#     def conn_handler(
#         self, session: ClientSession, proxy: str = None
#     ) -> ConnectionHandler:
#         """
#         Return connection handler instance for the endpoint
# 
#         :param session: AIOHTTP client session instance
#         :param proxy: Proxy url
#         :return:
#         """
#         if self.server:
#             conn_handler = ConnectionHandler(
#                 "http", "ws", self.server, self.port, "", session, proxy
#             )
#         elif self.ipv6:
#             conn_handler = ConnectionHandler(
#                 "http", "ws", "[{0}]".format(self.ipv6), self.port, "", session, proxy
#             )
#         else:
#             conn_handler = ConnectionHandler(
#                 "http", "ws", self.ipv4, self.port, "", session, proxy
#             )
# 
#         return conn_handler
# 
#     def __str__(self) -> str:
#         return self.inline()
# 
#     def __eq__(self, other: Any) -> bool:
#         if not isinstance(other, BMAEndpoint):
#             return NotImplemented
#         return (
#             self.server == other.server
#             and self.ipv4 == other.ipv4
#             and self.ipv6 == other.ipv6
#             and self.port == other.port
#         )
# 
#     def __hash__(self) -> int:
#         return hash((self.server, self.ipv4, self.ipv6, self.port))


# Path: tests/api/bma/test_blockchain.py
import unittest
import jsonschema
from jsonschema import SchemaError, ValidationError
from duniterpy.api.bma.blockchain import (
    parameters,
    block,
    current,
    hardship,
    memberships,
    newcomers,
    certifications,
    joiners,
    actives,
    leavers,
    ud,
    tx,
    BLOCK_NUMBERS_SCHEMA,
    BLOCK_SCHEMA,
    BLOCKS_SCHEMA,
    HARDSHIP_SCHEMA,
    MEMBERSHIPS_SCHEMA,
    PARAMETERS_SCHEMA,
)
from duniterpy.api.client import Client
from duniterpy.api.endpoint import BMAEndpoint
from tests.api.webserver import WebFunctionalSetupMixin, web

            "sigValidity": 63115200,
            "sigQty": 5,
            "idtyWindow": 5259600,
            "msWindow": 5259600,
            "xpercent": 0.8,
            "msValidity": 31557600,
            "stepMax": 5,
            "medianTimeBlocks": 24,
            "avgGenTime": 300,
            "dtDiffEval": 12,
            "percentRot": 0.67,
            "udTime0": 1488970800,
            "udReevalTime0": 1490094000,
            "dtReeval": 15778800,
        }
        try:
            jsonschema.validate(json_sample, PARAMETERS_SCHEMA)
        except (SchemaError, ValidationError) as e:
            raise self.failureException from e

    def test_parameters_bad(self):
        async def handler(request):
            await request.read()
            return web.Response(body=b"{}", content_type="application/json")

        async def go():
            _, port, _ = await self.create_server(
                "GET", "/blockchain/parameters", handler
            )
            with self.assertRaises(jsonschema.exceptions.ValidationError):

                client = Client(BMAEndpoint("127.0.0.1", "", "", port))