diff --git a/duniterpy/api/bma/network.py b/duniterpy/api/bma/network.py index 6f6ad3d7ea52984f4c94b924fc2802598e2c664a..0437cd503e855e6c503898c8bd20d2f878c1d472 100644 --- a/duniterpy/api/bma/network.py +++ b/duniterpy/api/bma/network.py @@ -103,6 +103,37 @@ PEERS_SCHEMA = schema = { ] } +WS2P_HEADS_SCHEMA = { + "type": "object", + "properties": { + "heads": { + "type": "array", + "items": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "sig": { + "type": "string", + }, + "messageV2": { + "type": "string" + }, + "sigV2": { + "type": "string", + }, + "step": { + "type": "number", + }, + }, + "required": ["messageV2", "sigV2", "step"] + } + } + }, + "required": ["heads"] +} + async def peering(client: Client) -> dict: """ @@ -138,3 +169,13 @@ async def peer(client: Client, peer_signed_raw: str) -> ClientResponse: :return: """ return await client.post(MODULE + '/peering/peers', {'peer': peer_signed_raw}, rtype=RESPONSE_AIOHTTP) + + +async def ws2p_heads(client: Client) -> dict: + """ + GET ws2p heads known by the node + + :param client: Client to connect to the api + :rtype: dict + """ + return await client.get(MODULE + '/ws2p/heads', schema=WS2P_HEADS_SCHEMA) diff --git a/duniterpy/api/ws2p/__init__.py b/duniterpy/api/ws2p/__init__.py deleted file mode 100644 index 2fac55f9b786a25b93e614276e335fa5aec68edd..0000000000000000000000000000000000000000 --- a/duniterpy/api/ws2p/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from . import network - - diff --git a/duniterpy/api/ws2p/network.py b/duniterpy/api/ws2p/network.py deleted file mode 100644 index ec9b3a149309083f077926aca1cb5cf79982103a..0000000000000000000000000000000000000000 --- a/duniterpy/api/ws2p/network.py +++ /dev/null @@ -1,65 +0,0 @@ -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# Authors: -# Caner Candan <caner@candan.fr>, http://caner.candan.fr -# vit -import logging - -from duniterpy.api.client import Client - -logger = logging.getLogger("duniter/network") - -MODULE = 'network' - -WS2P_HEADS_SCHEMA = { - "type": "object", - "properties": { - "heads": { - "type": "array", - "items": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "sig": { - "type": "string", - }, - "messageV2": { - "type": "string" - }, - "sigV2": { - "type": "string", - }, - "step": { - "type": "number", - }, - }, - "required": ["message", "sig"] - } - } - }, - "required": ["heads"] -} - - -def heads(client: Client): - """ - GET Certification data over a member - - :param client: Client to connect to the api - :rtype: dict - """ - return client.get(MODULE + '/ws2p/heads', schema=WS2P_HEADS_SCHEMA) diff --git a/tests/api/bma/test_network.py b/tests/api/bma/test_network.py index 7b5db693a2927a0e5d3bed1f61d097ce38de03fd..baca3a9affb3612e3f01f1c806f6653f22368455 100644 --- a/tests/api/bma/test_network.py +++ b/tests/api/bma/test_network.py @@ -77,3 +77,44 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase): await client.close() self.loop.run_until_complete(go()) + + def test_ws2p_heads(self): + json_sample = { + "heads": [ + { + "messageV2": "WS2POCAIC:HEAD:2:238pNfpkNs4TdRgt6NnJ5Q72CDZbgNqm4cJo4nCP3BxC:367572" + "-000024399D612753E59D44415CFA61F3A663919110CD2EB8D30C93F49C61E07F:96675302:duniter" + ":1.7.10:1:0:0", + "message": "WS2POCAIC:HEAD:1:238pNfpkNs4TdRgt6NnJ5Q72CDZbgNqm4cJo4nCP3BxC:367572" + "-000024399D612753E59D44415CFA61F3A663919110CD2EB8D30C93F49C61E07F:96675302:duniter:1" + ".7.10:1", + "sigV2": "G1YQd5hgW6+bVGSZJgFzBjZyHgiIqzgUzHOVjcelbHJnwFtxl9XtqZiC5Ul0+Wv8im4IcOwgPypzFe/xUVJMBQ==", + "sig": "frlBj5ntC64H/iqNTqsB+igvEn2C9RD6fF2UOvZHWlzEqyaFy0YSRDyvZIyCTi/kPC+f1Xq2PKUItZvQdqPuAQ==", + "step": 0}, + { + "messageV2": "WS2POTAIT:HEAD:2:CrznBiyq8G4RVUprH9jHmAw1n1iuzw8y9FdJbrESnaX7:378529" + "-00028D6F71E384565A1A106C1247E5F4B0392645A84EDB121173AC930540D552:3eaab4c7:duniter" + ":1.7.18:1:30:30", + "message": "WS2POTAIT:HEAD:1:CrznBiyq8G4RVUprH9jHmAw1n1iuzw8y9FdJbrESnaX7:378529" + "-00028D6F71E384565A1A106C1247E5F4B0392645A84EDB121173AC930540D552:3eaab4c7:duniter:1" + ".7.18:1", + "sigV2": "EIa5P8jJSdKR740/fLgu8u+7VFf6tiDs3xGKHxiM8nTVLjsZR8RoZtRGexqG0XIoPGpCty9rIduOu83knsorAA==", + "sig": "up5LLKm9DEXeiEAcMyPv9hignCx/rKlXSfcHVH1EZUOEMcNBiE4WzR4kSU8AA5cSpBYpZ7Uoo9y4ATmrLj3YDw==", + "step": 2} + ] + } + jsonschema.validate(json_sample, network.WS2P_HEADS_SCHEMA) + + def test_ws2p_heads_bad(self): + async def handler(request): + await request.read() + return web.Response(body=b'{}', content_type='application/json') + + async def go(): + _, port, url = await self.create_server('GET', '/network/ws2p/heads', handler) + with self.assertRaises(jsonschema.ValidationError): + client = Client(BMAEndpoint("127.0.0.1", "", "", port)) + await client(network.ws2p_heads) + await client.close() + + self.loop.run_until_complete(go()) diff --git a/tests/api/ws2p/__init__.py b/tests/api/ws2p/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/tests/api/ws2p/test_ws2p.py b/tests/api/ws2p/test_ws2p.py deleted file mode 100644 index 7c97c720bf16ff7aba5955057fa3e203cf1e4b93..0000000000000000000000000000000000000000 --- a/tests/api/ws2p/test_ws2p.py +++ /dev/null @@ -1,63 +0,0 @@ -import unittest - -import jsonschema - -from duniterpy.api.client import Client -from duniterpy.api.endpoint import BMAEndpoint -from duniterpy.api.ws2p.network import heads, WS2P_HEADS_SCHEMA -from tests.api.webserver import WebFunctionalSetupMixin, web - - -class TestWs2pHeads(WebFunctionalSetupMixin, unittest.TestCase): - - def test_block(self): - json_sample = { - "heads": [ - { - "message": "WS2POCAIC:HEAD:1:8iVdpXqFLCxGyPqgVx5YbFSkmWKkceXveRd2yvBKeARL:\ - 102102-000002C0694C7D373A78B095419C86584B81804CFB9641B7EBC3A18040B6FEE6:e66254bf:duniter:1.6.20:1", - "sig": "ZO5gSUMK6IaUEwU4K40nhuHOfnJ6Zfn8VS+4Ko2FM7t+mDsHf+3gDRT9PgV2p0fz81mF6jVYWpq2UYEsnK/gCg==", - "messageV2": "WS2POCAIC:HEAD:2:8iVdpXqFLCxGyPqgVx5YbFSkmWKkceXveRd2yvBKeARL:\ - 102102-000002C0694C7D373A78B095419C86584B81804CFB9641B7EBC3A18040B6FEE6:e66254bf:\ - duniter:1.6.20:1:15:14", - "sigV2": "ReXzbgUya9jo4dL/R4g19Y+RE9BGB0xDkw7mrBWoldlRLkq3KFyRkAf9VthVx1UUb/AINr3nxImZKVQiVH9+DQ==", - "step": 0 - }, - { - "message": "WS2POCAIC:HEAD:1:2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ:\ - 102102-000002C0694C7D373A78B095419C86584B81804CFB9641B7EBC3A18040B6FEE6:a0a45ed2:duniter:1.6.21:1", - "sig": "pXLMmOpyEMdWihT183g/rnCvMzA2gHki5Cxg7rEl3psQu0RuK0ObCv5YFhmQnRlg+QZ1CWfbYEEbm3G1eGplAQ==", - "messageV2": "WS2POCAIC:HEAD:2:2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ:\ - 102102-000002C0694C7D373A78B095419C86584B81804CFB9641B7EBC3A18040B6FEE6:a0a45ed2:\ - duniter:1.6.21:1:34:28", - "sigV2": "p5f7/KfQqjTaCYSMUXpjUDH7uF2DafetHNgphGzkOXgxM+Upeii0Fz2RFBwnZvN+Gjp81hAqSuH48PJP6HJSAw==", - "step": 1 - }, - { - "message": "WS2POCA:HEAD:1:GRBPV3Y7PQnB9LaZhSGuS3BqBJbSHyibzYq65kTh1nQ4:\ - 102102-000002C0694C7D373A78B095419C86584B81804CFB9641B7EBC3A18040B6FEE6:6d0e96f9:duniter:1.6.21:1", - "sig": "h9o1XBEV18gUzbvj1jdQB1M7U8ifZprIyVwLdlSQEfeG9WZLvZAjYzLGA2nD6h/9RkJLOJPzIQJXysHUHJ2dDQ==", - "messageV2": "WS2POCA:HEAD:2:GRBPV3Y7PQnB9LaZhSGuS3BqBJbSHyibzYq65kTh1nQ4:\ - 102102-000002C0694C7D373A78B095419C86584B81804CFB9641B7EBC3A18040B6FEE6:6d0e96f9:\ - duniter:1.6.21:1:20:20", - "sigV2": "VsyQmXOUYrfHWy0FeS4rJrIJCUBI+3BergbSYQ78icJWV6MQzZSw7Z+Yl7urujCYZriDQM76D6GW+6F0EELpBQ==", - "step": 2 - }, - ] - } - - jsonschema.validate(json_sample, WS2P_HEADS_SCHEMA) - - def test_ws2p_heads_bad(self): - async def handler(request): - await request.read() - return web.Response(body=b'{}', content_type='application/json') - - async def go(): - _, port, url = await self.create_server('GET', '/network/ws2p/heads', handler) - with self.assertRaises(jsonschema.ValidationError): - client = Client(BMAEndpoint("127.0.0.1", "", "", port)) - await client(heads) - await client.close() - - self.loop.run_until_complete(go())