diff --git a/requirements.txt b/requirements.txt index ffecd9a6b22ae1748442aaf6a73db09970e0174b..b7f8790d49973d4559773ddba91e290fe6b5dcae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ asynctest networkx git+https://github.com/hynek/attrs.git@master git+https://github.com/duniter/duniter-python-api.git@dev +pytest +pytest-asyncio \ No newline at end of file diff --git a/src/sakia/app.py b/src/sakia/app.py index b9ba33e057d448e9b43e103da96523283c8fefd7..e7308cbe2b6624f285bc955b98419c62f3bd2a21 100644 --- a/src/sakia/app.py +++ b/src/sakia/app.py @@ -88,6 +88,9 @@ class Application(QObject): self._parameters = UserParametersFile.in_config_path(self.options.config_path, profile_name).load_or_init() self.db = SakiaDatabase.load_or_init(self.options.config_path, profile_name) + self.instanciate_services() + + def instanciate_services(self): nodes_processor = NodesProcessor(self.db.nodes_repo) bma_connector = BmaConnector(nodes_processor) connections_processor = ConnectionsProcessor(self.db.connections_repo) @@ -104,19 +107,26 @@ class Application(QObject): self.transactions_services = {} for currency in self.db.connections_repo.get_currencies(): - self.identities_services[currency] = IdentitiesService(currency, connections_processor, + if currency not in self.identities_services: + self.identities_services[currency] = IdentitiesService(currency, connections_processor, identities_processor, certs_processor, blockchain_processor, bma_connector) - self.transactions_services[currency] = TransactionsService(currency, transactions_processor, + + if currency not in self.transactions_services: + self.transactions_services[currency] = TransactionsService(currency, transactions_processor, identities_processor, bma_connector) - self.blockchain_services[currency] = BlockchainService(self, currency, blockchain_processor, bma_connector, + if currency not in self.blockchain_services: + self.blockchain_services[currency] = BlockchainService(self, currency, blockchain_processor, bma_connector, self.identities_services[currency], self.transactions_services[currency]) - self.network_services[currency] = NetworkService.load(self, currency, nodes_processor, + + if currency not in self.network_services: + self.network_services[currency] = NetworkService.load(self, currency, nodes_processor, self.blockchain_services[currency]) - self.sources_services[currency] = SourcesServices(currency, sources_processor, bma_connector) + if currency not in self.sources_services: + self.sources_services[currency] = SourcesServices(currency, sources_processor, bma_connector) def set_proxy(self): if self.preferences['enable_proxy'] is True: diff --git a/src/sakia/data/repositories/nodes.py b/src/sakia/data/repositories/nodes.py index ebc92b3e9741004707df7b563ef3dd47ef5f432b..5a95b1d6920adc4bebfc0e47a3aff6b103197627 100644 --- a/src/sakia/data/repositories/nodes.py +++ b/src/sakia/data/repositories/nodes.py @@ -17,7 +17,7 @@ class NodesRepo: """ node_tuple = attr.astuple(node, tuple_factory=list) node_tuple[2] = "\n".join([str(n) for n in node_tuple[2]]) - node_tuple[12] = "\n".join([str(n) for n in node_tuple[11]]) + node_tuple[12] = "\n".join([str(n) for n in node_tuple[12]]) values = ",".join(['?'] * len(node_tuple)) self._conn.execute("INSERT INTO nodes VALUES ({0})".format(values), node_tuple) diff --git a/src/sakia/gui/dialogs/connection_cfg/__init__.py b/src/sakia/gui/dialogs/connection_cfg/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..28a47ef45ea3b576216d2009ecd3fd877d27b4f0 100644 --- a/src/sakia/gui/dialogs/connection_cfg/__init__.py +++ b/src/sakia/gui/dialogs/connection_cfg/__init__.py @@ -0,0 +1 @@ +from .controller import ConnectionConfigController \ No newline at end of file diff --git a/src/sakia/gui/dialogs/connection_cfg/controller.py b/src/sakia/gui/dialogs/connection_cfg/controller.py index ca964ad02afc55eaa324dbd6d97f4b5fb11df019..003a813d78e87b750ca9c8d7be61f49728f8efed 100644 --- a/src/sakia/gui/dialogs/connection_cfg/controller.py +++ b/src/sakia/gui/dialogs/connection_cfg/controller.py @@ -26,10 +26,12 @@ class ConnectionConfigController(QObject): """ Constructor of the AccountConfigController component - :param sakia.gui.account_cfg.view.AccountConfigCView: the view - :param sakia.gui.account_cfg.model.AccountConfigModel model: the model + :param sakia.gui.dialogs.connection_cfg.view.ConnectionConfigView: the view + :param sakia.gui.dialogs.connection_cfg.model.ConnectionConfigView model: the model """ super().__init__(parent) + self.view = view + self.model = model self.step_node = asyncio.Future() self.step_key = asyncio.Future() @@ -40,7 +42,8 @@ class ConnectionConfigController(QObject): self.view.button_guest.clicked.connect( lambda: self.step_node.set_result(ConnectionConfigController.GUEST)) self.password_asker = None - self.view.values_changed.connect(self.check_key) + self.view.values_changed.connect(lambda: self.view.button_next.setEnabled(self.check_key())) + self.view.values_changed.connect(lambda: self.view.button_generate.setEnabled(self.check_key())) self._logger = logging.getLogger('sakia') @classmethod @@ -68,10 +71,10 @@ class ConnectionConfigController(QObject): :param app: :return: """ - connection_cfg = cls.create(parent, app, account=None) + connection_cfg = cls.create(parent, app) connection_cfg.view.set_creation_layout() asyncio.ensure_future(connection_cfg.process()) - connection_cfg.view.exec() + return connection_cfg @classmethod def modify_connection(cls, parent, app, connection): @@ -133,7 +136,7 @@ class ConnectionConfigController(QObject): self._logger.debug("Registering mode") self.view.button_next.clicked.connect(self.check_register) self.view.stacked_pages.setCurrentWidget(self.view.page_connection) - await self.step_key + connection_identity = await self.step_key elif mode == ConnectionConfigController.CONNECT: self._logger.debug("Connect mode") self.view.button_next.clicked.connect(self.check_connect) @@ -144,35 +147,46 @@ class ConnectionConfigController(QObject): self.view.stacked_pages.setCurrentWidget(self.view.page_services) self.view.progress_bar.setValue(0) self.view.progress_bar.setMaximum(3) - await self.model.initialize_blockchain(self.view.stream_log) - self.view.progress_bar.setValue(1) - - if mode in (ConnectionConfigController.REGISTER, ConnectionConfigController.CONNECT): - self.view.stream_log("Saving identity...") - self.model.insert_or_update_identity(connection_identity) - self.view.stream_log("Initializing identity informations...") - await self.model.initialize_identity(connection_identity, log_stream=self.view.stream_log) - self.view.stream_log("Initializing certifications informations...") - await self.model.initialize_certifications(connection_identity, log_stream=self.view.stream_log) - self.view.stream_log("Initializing transactions history...") - await self.model.initialize_transactions(connection_identity, log_stream=self.view.stream_log) - - self.view.progress_bar.setValue(2) - if mode == ConnectionConfigController.REGISTER: - self.view.display_info(self.tr("Broadcasting identity...")) - self.view.stream_log("Broadcasting identity...") - password = await self.password_asker.async_exec() - result, connection_identity = await self.model.publish_selfcert(self.model.connection.salt, password) - if result[0]: - self.view.show_success(self.model.notification()) - else: - self.view.show_error(self.model.notification(), result[1]) - - self.view.progress_bar.setValue(3) - await self.model.initialize_sources(self.view.stream_log) - - self._logger.debug("Validate changes") - self.model.app.db.commit() + try: + await self.model.initialize_blockchain(self.view.stream_log) + self.view.progress_bar.setValue(1) + + if mode == ConnectionConfigController.REGISTER: + self.view.display_info(self.tr("Broadcasting identity...")) + self.view.stream_log("Broadcasting identity...") + password = await self.password_asker.async_exec() + result, connection_identity = await self.model.publish_selfcert(self.model.connection.salt, password) + if result[0]: + self.view.show_success(self.model.notification()) + else: + self.view.show_error(self.model.notification(), result[1]) + + self.view.progress_bar.setValue(2) + + if mode in (ConnectionConfigController.REGISTER, ConnectionConfigController.CONNECT): + self.view.stream_log("Saving identity...") + self.model.insert_or_update_identity(connection_identity) + self.view.stream_log("Initializing identity informations...") + await self.model.initialize_identity(connection_identity, log_stream=self.view.stream_log) + self.view.stream_log("Initializing certifications informations...") + await self.model.initialize_certifications(connection_identity, log_stream=self.view.stream_log) + self.view.stream_log("Initializing transactions history...") + await self.model.initialize_transactions(connection_identity, log_stream=self.view.stream_log) + + + self.view.progress_bar.setValue(3) + await self.model.initialize_sources(self.view.stream_log) + + self._logger.debug("Validate changes") + self.model.app.db.commit() + except NoPeerAvailable as e: + self._logger.debug(str(e)) + self.view.stacked_pages.setCurrentWidget(self.view.page_connection) + self.step_node = asyncio.Future() + self.step_node.set_result(True) + self.step_key = asyncio.Future() + asyncio.ensure_future(self.process()) + return self.accept() def check_key(self): @@ -259,13 +273,4 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) future = asyncio.Future() self.view.finished.connect(lambda r: future.set_result(r)) self.view.open() - self.refresh() return future - - @property - def view(self) -> ConnectionConfigView: - return self._view - - @property - def model(self) -> ConnectionConfigModel: - return self._model \ No newline at end of file diff --git a/src/sakia/gui/main_window/toolbar/controller.py b/src/sakia/gui/main_window/toolbar/controller.py index db44a5f2fe24f8aa6bc16ebc8e16512ba0cfa49d..df17200a8cacbc4b51fd96ab9dfa7ccedec5f180 100644 --- a/src/sakia/gui/main_window/toolbar/controller.py +++ b/src/sakia/gui/main_window/toolbar/controller.py @@ -195,7 +195,7 @@ The process to join back the community later will have to be done again.""") password_asker=self.password_asker) def open_create_account_dialog(self): - ConnectionConfigController.create_connection(self, self.model.app) + ConnectionConfigController.create_connection(self, self.model.app).exec() def retranslateUi(self, widget): """ diff --git a/src/sakia/tests/conftest.py b/src/sakia/tests/conftest.py index e89c080c0bbffba8942bfdb7531a4e6271344bb7..6cbd2e1cd6de7b1f05f9cdba86a3bae0dceb8729 100644 --- a/src/sakia/tests/conftest.py +++ b/src/sakia/tests/conftest.py @@ -2,14 +2,19 @@ import pytest import asyncio import quamash import sqlite3 +import mirage from duniterpy.documents import BlockUID -from sakia.data.repositories.meta import SakiaDatabase +from sakia.app import Application +from sakia.options import SakiaOptions +from sakia.data.files import AppDataFile +from sakia.data.entities import * +from sakia.data.repositories import * _application_ = [] -@pytest.yield_fixture() +@pytest.yield_fixture def event_loop(): qapplication = get_application() loop = quamash.QSelectorEventLoop(qapplication) @@ -25,17 +30,99 @@ def event_loop(): raise exc -@pytest.fixture() +@pytest.fixture def meta_repo(): sqlite3.register_adapter(BlockUID, str) sqlite3.register_adapter(bool, int) sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v))) - meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) + con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES) + meta_repo = SakiaDatabase(con, + ConnectionsRepo(con), IdentitiesRepo(con), + BlockchainsRepo(con), CertificationsRepo(con), TransactionsRepo(con), + NodesRepo(con), SourcesRepo(con)) meta_repo.prepare() meta_repo.upgrade_database() return meta_repo +@pytest.fixture +def sakia_options(tmpdir): + return SakiaOptions(tmpdir.dirname) + + +@pytest.fixture +def app_data(sakia_options): + return AppDataFile.in_config_path(sakia_options.config_path).load_or_init() + + +@pytest.fixture +def user_parameters(): + return UserParameters() + +@pytest.fixture +def connection(bob): + return Connection(currency="testcurrency", + pubkey=bob.key.pubkey, + salt=bob.salt, uid=bob.uid, + scrypt_N=4096, scrypt_r=4, scrypt_p=2, + blockstamp=bob.blockstamp, + password="bobpassword") + + +@pytest.fixture +def application(event_loop, meta_repo, sakia_options, app_data, user_parameters): + return Application(get_application(), event_loop, sakia_options, app_data, user_parameters, meta_repo, {}, {}, {}, {}, {}) + + +@pytest.fixture +def fake_server(event_loop): + return event_loop.run_until_complete(mirage.Node.start(None, "testcurrency", "12356", "123456", event_loop)) + + +@pytest.fixture +def alice(): + return mirage.User.create("testcurrency", "alice", "alicesalt", "alicepassword", BlockUID.empty()) + + +@pytest.fixture +def bob(): + return mirage.User.create("testcurrency", "bob", "bobsalt", "bobpassword", BlockUID.empty()) + + +@pytest.fixture +def simple_fake_server(fake_server, alice, bob): + fake_server.forge.push(alice.identity()) + fake_server.forge.push(bob.identity()) + fake_server.forge.push(alice.join(BlockUID.empty())) + fake_server.forge.push(bob.join(BlockUID.empty())) + fake_server.forge.push(alice.certify(bob, BlockUID.empty())) + fake_server.forge.push(bob.certify(alice, BlockUID.empty())) + fake_server.forge.forge_block() + fake_server.forge.set_member(alice.key.pubkey, True) + fake_server.forge.set_member(bob.key.pubkey, True) + fake_server.forge.forge_block() + fake_server.forge.forge_block() + return fake_server + + +@pytest.fixture +def application_with_one_connection(application, connection, simple_fake_server): + application.db.connections_repo.insert(connection) + application.instanciate_services() + application.db.nodes_repo.insert(Node(currency=simple_fake_server.forge.currency, + pubkey=simple_fake_server.forge.key.pubkey, + endpoints=simple_fake_server.peer_doc().endpoints, + peer_blockstamp=simple_fake_server.peer_doc().blockstamp, + uid=simple_fake_server.peer_doc.uid, + current_buid=BlockUID(simple_fake_server.current_block(None)["number"], + simple_fake_server.current_block(None)["hash"]), + current_ts=simple_fake_server.current_block(None)["medianTime"], + state=Node.ONLINE, + software="duniter", + version="0.40.2")) + return application + + def unitttest_exception_handler(exceptions, loop, context): """ An exception handler which exists the program if the exception diff --git a/src/sakia/tests/functional/process_cfg_account/__init__.py b/src/sakia/tests/functional/process_cfg_account/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/sakia/tests/functional/process_cfg_account/test_add_account.py b/src/sakia/tests/functional/process_cfg_account/test_add_account.py deleted file mode 100644 index 44c370414b10904da05c64a6c474a0a827cc6b24..0000000000000000000000000000000000000000 --- a/src/sakia/tests/functional/process_cfg_account/test_add_account.py +++ /dev/null @@ -1,95 +0,0 @@ -import asyncio -import logging -import sys -import unittest - -from PyQt5.QtCore import QLocale, Qt -from PyQt5.QtTest import QTest -from sakia.gui.process_cfg_account import ProcessConfigureAccount - -from sakia.app import Application -from sakia.core.account import Account -from sakia.core.registry.identities import IdentitiesRegistry -from sakia.gui.password_asker import PasswordAskerDialog -from sakia.tests import QuamashTest - - -class ProcessAddCommunity(unittest.TestCase, QuamashTest): - def setUp(self): - self.setUpQuamash() - QLocale.setDefault(QLocale("en_GB")) - self.identities_registry = IdentitiesRegistry({}) - - self.application = Application(self.qapplication, self.lp, self.identities_registry) - self.application.preferences['notifications'] = False - # Salt/password : "testsakia/testsakia" - # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ - self.account = Account("testsakia", "B7J4sopyfqzi3uh4Gzsdnp1XHc87NaxY7rqW2exgivCa", - "test", [], [], [], self.identities_registry) - self.password_asker = PasswordAskerDialog(self.account) - self.password_asker.password = "testsakia" - self.password_asker.remember = True - - def tearDown(self): - self.tearDownQuamash() - - def test_create_account(self): - process_account = ProcessConfigureAccount(self.application, - None) - - def close_dialog(): - if process_account.isVisible(): - process_account.close() - - async def exec_test(): - QTest.keyClicks(process_account.edit_account_name, "test") - self.assertEqual(process_account.stacked_pages.currentWidget(), - process_account.page_init, - msg="Current widget : {0}".format(process_account.stacked_pages.currentWidget().objectName())) - QTest.mouseClick(process_account.button_next, Qt.LeftButton) - await asyncio.sleep(1) - - self.assertEqual(process_account.stacked_pages.currentWidget(), - process_account.page_gpg, - msg="Current widget : {0}".format(process_account.stacked_pages.currentWidget().objectName())) - QTest.keyClicks(process_account.edit_salt, "testsakia") - self.assertFalse(process_account.button_next.isEnabled()) - self.assertFalse(process_account.button_generate.isEnabled()) - QTest.keyClicks(process_account.edit_password, "testsakia") - self.assertFalse(process_account.button_next.isEnabled()) - self.assertFalse(process_account.button_generate.isEnabled()) - QTest.keyClicks(process_account.edit_password_repeat, "wrongpassword") - self.assertFalse(process_account.button_next.isEnabled()) - self.assertFalse(process_account.button_generate.isEnabled()) - process_account.edit_password_repeat.setText("") - QTest.keyClicks(process_account.edit_password_repeat, "testsakia") - self.assertTrue(process_account.button_next.isEnabled()) - self.assertTrue(process_account.button_generate.isEnabled()) - QTest.mouseClick(process_account.button_generate, Qt.LeftButton) - self.assertEqual(process_account.label_info.text(), - "B7J4sopyfqzi3uh4Gzsdnp1XHc87NaxY7rqW2exgivCa") - QTest.mouseClick(process_account.button_next, Qt.LeftButton) - await asyncio.sleep(1) - - self.assertEqual(process_account.stacked_pages.currentWidget(), - process_account.page__communities, - msg="Current widget : {0}".format(process_account.stacked_pages.currentWidget().objectName())) - process_account.password_asker.password = "testsakia" - process_account.password_asker.remember = True - await asyncio.sleep(1) - QTest.mouseClick(process_account.button_next, Qt.LeftButton) - self.assertEqual(len(self.application.accounts), 1) - await asyncio.sleep(0.1) - self.assertEqual(self.application.current_account.name, "test") - self.assertEqual(self.application.preferences['account'], "test") - self.assertEqual(len(self.application.current_account.wallets), 1) - await asyncio.sleep(1) - - self.lp.call_later(10, close_dialog) - asyncio.ensure_future(exec_test()) - self.lp.run_until_complete(process_account.async_exec()) - -if __name__ == '__main__': - logging.basicConfig( stream=sys.stderr ) - logging.getLogger().setLevel( logging.DEBUG ) - unittest.main() diff --git a/src/sakia/tests/functional/test_connection_cfg_dialog.py b/src/sakia/tests/functional/test_connection_cfg_dialog.py new file mode 100644 index 0000000000000000000000000000000000000000..6ecb2f0fafa314e4b43965961d4ef17cb090bc67 --- /dev/null +++ b/src/sakia/tests/functional/test_connection_cfg_dialog.py @@ -0,0 +1,54 @@ +import asyncio +import logging +import sys +import pytest +from PyQt5.QtCore import QLocale, Qt +from PyQt5.QtTest import QTest +from sakia.data.processors import ConnectionsProcessor +from sakia.gui.dialogs.connection_cfg import ConnectionConfigController + + +@pytest.mark.asyncio +async def test_create_account(application, simple_fake_server, bob): + connection_config_dialog = ConnectionConfigController.create_connection(None, application) + + def close_dialog(): + if connection_config_dialog.view.isVisible(): + connection_config_dialog.view.close() + + async def exec_test(): + QTest.keyClicks(connection_config_dialog.view.lineedit_server, simple_fake_server.peer_doc().endpoints[0].ipv4) + connection_config_dialog.view.spinbox_port.setValue(simple_fake_server.peer_doc().endpoints[0].port) + assert connection_config_dialog.view.stacked_pages.currentWidget() == connection_config_dialog.view.page_node + QTest.mouseClick(connection_config_dialog.view.button_register, Qt.LeftButton) + await asyncio.sleep(1) + + assert connection_config_dialog.view.stacked_pages.currentWidget() == connection_config_dialog.view.page_connection + QTest.keyClicks(connection_config_dialog.view.edit_salt, bob.salt) + QTest.keyClicks(connection_config_dialog.view.edit_salt_bis, bob.salt) + assert connection_config_dialog.view.button_next.isEnabled() is False + assert connection_config_dialog.view.button_generate.isEnabled() is False + QTest.keyClicks(connection_config_dialog.view.edit_password, bob.password) + connection_config_dialog.view.button_next.isEnabled() is False + connection_config_dialog.view.button_generate.isEnabled() is False + QTest.keyClicks(connection_config_dialog.view.edit_password_repeat, bob.password + "wrong") + assert connection_config_dialog.view.button_next.isEnabled() is False + assert connection_config_dialog.view.button_generate.isEnabled() is False + connection_config_dialog.view.edit_password_repeat.setText("") + QTest.keyClicks(connection_config_dialog.view.edit_password_repeat, bob.password) + assert connection_config_dialog.view.button_next.isEnabled() is True + assert connection_config_dialog.view.button_generate.isEnabled() is True + QTest.mouseClick(connection_config_dialog.view.button_generate, Qt.LeftButton) + assert connection_config_dialog.view.label_info.text() == bob.key.pubkey + QTest.mouseClick(connection_config_dialog.view.button_next, Qt.LeftButton) + await asyncio.sleep(1) + + assert connection_config_dialog.view.stacked_pages.currentWidget() == connection_config_dialog.view.page__communities + await asyncio.sleep(1) + QTest.mouseClick(connection_config_dialog.view.button_next, Qt.LeftButton) + assert len(ConnectionsProcessor.instanciate(application).connections(simple_fake_server.currency)) == 1 + + application.loop.call_later(10, close_dialog) + asyncio.ensure_future(exec_test()) + await connection_config_dialog.async_exec() + diff --git a/src/sakia/tests/mocks/bma/__init__.py b/src/sakia/tests/mocks/bma/__init__.py deleted file mode 100644 index 7e4cdeb7cb59ef2876f24361d303fcc281ec4ef8..0000000000000000000000000000000000000000 --- a/src/sakia/tests/mocks/bma/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'ggoinvic' diff --git a/src/sakia/tests/mocks/bma/corrupted.py b/src/sakia/tests/mocks/bma/corrupted.py deleted file mode 100644 index a147e884635086bb3ded3ee2f3d76008c4939b9f..0000000000000000000000000000000000000000 --- a/src/sakia/tests/mocks/bma/corrupted.py +++ /dev/null @@ -1,29 +0,0 @@ -import json -from ..server import MockServer - -bma_memberships_empty_array = { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uid": "john", - "sigDate": 123456789, - "memberships": [ ] -} - - -bma_null_data = { - "certifications": [ - { - "written": { - }, - }, - { - "written": None, - } - ] -} - -def get_mock(loop): - mock = MockServer(loop) - - mock.add_route('GET', '/blockchain/memberships/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_memberships_empty_array) - - return mock diff --git a/src/sakia/tests/mocks/bma/init_new_community.py b/src/sakia/tests/mocks/bma/init_new_community.py deleted file mode 100644 index af732fd1caab4b2b26a35dc3714e35cd47ff1a52..0000000000000000000000000000000000000000 --- a/src/sakia/tests/mocks/bma/init_new_community.py +++ /dev/null @@ -1,121 +0,0 @@ -from ..server import MockServer -from duniterpy.api import errors - -bma_lookup_test_john = { - "partial": False, - "results": [ - { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uids": [ - { - "uid": "john", - "meta": { - "timestamp": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" - }, - "self": "ZrHK0cCqrxWReROK0ciiSb45+dRphJa68qFaSjdve8bBdnGAu7+DIu0d+u/fXrNRXuObihOKMBIawaIVPNHqDw==", - "others": [], - "revocation_sig": "CTmlh3tO4B8f8IbL8iDy5ZEr3jZDcxkPmDmRPQY74C39MRLXi0CKUP+oFzTZPYmyUC7fZrUXrb3LwRKWw1jEBQ==", - "revoked": False, - } - ], - "signed": [] - } - ] -} - -bma_lookup_test_doe = { - "partial": False, - "results": [ - { - "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "uids": [ - { - "uid": "doe", - "meta": { - "timestamp": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" - }, - "self": "cIkHPQQ5+xTb4cKWv85rcYcZT+E3GDtX8B2nCK9Vs12p2Yz4bVaZiMvBBwisAAy2WBOaqHS3ydpXGtADchOICw==", - "others": [], - "revocation_sig": "CTmlh3tO4B8f8IbL8iDy5ZEr3jZDcxkPmDmRPQY74C39MRLXi0CKUP+oFzTZPYmyUC7fZrUXrb3LwRKWw1jEBQ==", - "revoked": False, - } - ], - "signed": [] - } - ] -} - -bma_lookup_test_patrick = { - "partial": False, - "results": [ - { - "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "uids": [ - { - "uid": "patrick", - "meta": { - "timestamp": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" - }, - "self": "QNX2HDAxcHawc47TnMqb5/ou2lwa+zYOyeNk0a52dQDJX/NWmeTzGfTjdCtjpXmSCuPSg0F1mOnLQVd60xAzDA==", - "others": [], - "revocation_sig": "CTmlh3tO4B8f8IbL8iDy5ZEr3jZDcxkPmDmRPQY74C39MRLXi0CKUP+oFzTZPYmyUC7fZrUXrb3LwRKWw1jEBQ==", - "revoked": False, - } - ], - "signed": [] - } - ] -} - -bma_parameters = { - "currency": "test_currency", - "c": 0.1, - "dt": 86400, - "ud0": 100, - "sigPeriod": 600, - "sigValidity": 2629800, - "sigQty": 3, - "xpercent": 0.9, - "sigStock": 10, - "sigWindow": 1000, - "msValidity": 2629800, - "stepMax": 3, - "medianTimeBlocks": 11, - "avgGenTime": 600, - "dtDiffEval": 20, - "blocksRot": 144, - "percentRot": 0.67 -} - -def get_mock(loop): - mock = MockServer(loop) - - mock.add_route('GET', '/blockchain/parameters', bma_parameters, 200) - - mock.add_route('GET', '/blockchain/block/0', {'ucode': errors.BLOCK_NOT_FOUND, - "message": "Block not found"}, 404) - - mock.add_route('GET', '/blockchain/current', {'ucode': errors.NO_CURRENT_BLOCK, - 'message': "Block not found"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, - 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/lookup/john', bma_lookup_test_john, 200) - - mock.add_route('GET', '/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_lookup_test_john, 200) - - mock.add_route('GET', '/wot/lookup/doe', bma_lookup_test_doe, 200) - - mock.add_route('GET', '/wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn', bma_lookup_test_doe, 200) - - mock.add_route('GET', '/wot/lookup/patrick', bma_lookup_test_patrick, 200) - - mock.add_route('GET', '/wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn', bma_lookup_test_patrick, 200) - - mock.add_route('POST', '/wot/add', {}, 200) - - mock.add_route('POST', '/wot/certify', {}, 200) - - return mock diff --git a/src/sakia/tests/mocks/bma/new_blockchain.py b/src/sakia/tests/mocks/bma/new_blockchain.py deleted file mode 100644 index fc83d1241d29f383c27913c534ad744b758605a9..0000000000000000000000000000000000000000 --- a/src/sakia/tests/mocks/bma/new_blockchain.py +++ /dev/null @@ -1,77 +0,0 @@ -from ..server import MockServer -from duniterpy.api import errors - -bma_wot_add = { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uids": [ - { - "uid": "test", - "meta": { - "timestamp": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" - }, - "self": "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci", - "others": [ - ], - "revocation_sig": "CTmlh3tO4B8f8IbL8iDy5ZEr3jZDcxkPmDmRPQY74C39MRLXi0CKUP+oFzTZPYmyUC7fZrUXrb3LwRKWw1jEBQ==", - "revoked": False, - } - ] -} - -bma_parameters = { - "currency": "test_currency", - "c": 0.1, - "dt": 86400, - "ud0": 100, - "sigPeriod": 600, - "sigValidity": 2629800, - "sigQty": 3, - "xpercent": 0.9, - "sigStock": 10, - "sigWindow": 1000, - "msValidity": 2629800, - "stepMax": 3, - "medianTimeBlocks": 11, - "avgGenTime": 600, - "dtDiffEval": 20, - "blocksRot": 144, - "percentRot": 0.67 -} - -def get_mock(loop): - mock = MockServer(loop) - - mock.add_route('GET', '/blockchain/parameters', bma_parameters, 200) - - mock.add_route('GET', '/blockchain/block/0', {'ucode': errors.BLOCK_NOT_FOUND, - 'message': "Block not found"}, 404) - - mock.add_route('GET', '/blockchain/current', {'ucode': errors.NO_CURRENT_BLOCK, - 'message': "Block not found"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, - 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', - {'ucode': errors.NO_MATCHING_IDENTITY, - 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/lookup/john', - {'ucode': errors.NO_MATCHING_IDENTITY, - 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/john', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/lookup/doe', - {'ucode': errors.NO_MATCHING_IDENTITY, - 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/doe', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('POST', '/wot/add', bma_wot_add, 200) - - mock.add_route('POST', '/wot/certify', {}, 200) - return mock diff --git a/src/sakia/tests/mocks/bma/nice_blockchain.py b/src/sakia/tests/mocks/bma/nice_blockchain.py deleted file mode 100644 index b8ad5e293d29b5b3ddab20b05c942799ba4072f6..0000000000000000000000000000000000000000 --- a/src/sakia/tests/mocks/bma/nice_blockchain.py +++ /dev/null @@ -1,523 +0,0 @@ -from ..server import MockServer -from duniterpy.api import errors - -bma_lookup_john = { - "partial": False, - "results": [ - { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uids": [ - { - "uid": "john", - "meta": { - "timestamp": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" - }, - "revocation_sig": "CTmlh3tO4B8f8IbL8iDy5ZEr3jZDcxkPmDmRPQY74C39MRLXi0CKUP+oFzTZPYmyUC7fZrUXrb3LwRKWw1jEBQ==", - "revoked": False, - "self": "ZrHK0cCqrxWReROK0ciiSb45+dRphJa68qFaSjdve8bBdnGAu7+DIu0d+u/fXrNRXuObihOKMBIawaIVPNHqDw==", - "others": [ - { - "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "meta": { - "block_number": 15 - }, - "uids": [ - "doe" - ], - "isMember": True, - "wasMember": True, - "signature": "4ulycI2MtBu/8bZipy+OsXDCNm9EyUIdZ1HA7hbJ66phKRNvv70Oo2YOF/+VDRJb97z9TqWKgfIQ0NbXU15xDg==" - }, - ] - } - ], - "signed": [] - } - ] -} - -bma_membership_john = { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uid": "john", - "sigDate": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - "memberships": - [ - { - "version": 2, - "currency": "test_currency", - "membership": "IN", - "blockNumber": 0, - "blockHash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - "written": 10000 - } - ] -} - -bma_lookup_doe = { - "partial": False, - "results": [ - { - "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "uids": [ - { - "uid": "doe", - "meta": { - "timestamp": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" - }, - "revocation_sig": "CTmlh3tO4B8f8IbL8iDy5ZEr3jZDcxkPmDmRPQY74C39MRLXi0CKUP+oFzTZPYmyUC7fZrUXrb3LwRKWw1jEBQ==", - "revoked": False, - "self": "cIkHPQQ5+xTb4cKWv85rcYcZT+E3GDtX8B2nCK9Vs12p2Yz4bVaZiMvBBwisAAy2WBOaqHS3ydpXGtADchOICw==", - "others": [] - } - ], - "signed": [ - { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "meta": { - "block_number": 38580 - }, - "uids": [ - "john" - ], - "isMember": True, - "wasMember": True, - "signature": "4ulycI2MtBu/8bZipy+OsXDCNm9EyUIdZ1HA7hbJ66phKRNvv70Oo2YOF/+VDRJb97z9TqWKgfIQ0NbXU15xDg==" - }, - ] - } - ] -} - -bma_certifiers_of_john = { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uid": "john", - "isMember": True, - "certifications": [ - { - "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "uid": "doe", - "isMember": True, - "wasMember": True, - "cert_time": { - "block": 15, - "medianTime": 1500000000 - }, - "sigDate": "101-BAD49448A1AD73C978CEDCB8F137D20A5715EBAA739DAEF76B1E28EE67B2C00C", - "written": { - "number": 15, - "hash": "0000EC88BBBAA29D530D2B815DEE264DDC9F07F4" - }, - "signature": "oliiPDhniZAGHrIFL66oHR+cqD4aTgXX+20VFLMfNHwdYPeik76hy334zxhoDC4cPODMb9df2nF/EDfCefrNBg==" - }, - ] -} - -bma_certified_by_john = { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uid": "john", - "isMember": True, - "wasMember": False, - "certifications": [ - ] -} - -bma_certified_by_doe = { - "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "uid": "doe", - "isMember": True, - "certifications": [ - { - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "uid": "john", - "isMember": True, - "wasMember": True, - "cert_time": { - "block": 15, - "medianTime": 1500000000 - }, - "sigDate": "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "written": { - "number": 15, - "hash": "0000EC88BBBAA29D530D2B815DEE264DDC9F07F4" - }, - "signature": "oliiPDhniZAGHrIFL66oHR+cqD4aTgXX+20VFLMfNHwdYPeik76hy334zxhoDC4cPODMb9df2nF/EDfCefrNBg==" - }, - ] -} - -bma_parameters = { - "currency": "test_currency", - "c": 0.1, - "dt": 86400, - "ud0": 100, - "sigPeriod": 600, - "sigValidity": 2629800, - "sigQty": 3, - "xpercent": 0.9, - "sigStock": 10, - "sigWindow": 1000, - "msValidity": 2629800, - "stepMax": 3, - "medianTimeBlocks": 11, - "avgGenTime": 600, - "dtDiffEval": 20, - "blocksRot": 144, - "percentRot": 0.67 -} - -bma_blockchain_0 = { - "version": 2, - "nonce": 10144, - "number": 0, - "powMin": 3, - "time": 1421838980, - "medianTime": 1421838980, - "membersCount": 4, - "monetaryMass": 0, - "currency": "test_currency", - "issuer": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "signature": "+78w7251vvRdhoIJ6IWHEiEOLxNrmfQf45Y5sYvPdnAdXkVpO1unMV5YA/G5Vhphyz1dICrbeKCPM5qbFsoWAQ==", - "hash": "00063EB6E83F8717CEF1D25B3E2EE308374A14B1", - "inner_hash": "00063EB6E83F8717CEF1D25B3E2EE308374A14B1", - "parameters": "0.1:86400:100:604800:2629800:3:3:2629800:3:11:600:20:144:0.67", - "previousHash": None, - "previousIssuer": None, - "dividend": None, - "membersChanges": [], - "identities": [ - "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:Ot3zIp/nsHT3zgJy+2YcXPL6vaM5WFsD+F8w3qnJoBRuBG6lv761zoaExp2iyUnm8fDAyKPpMxRK2kf437QSCw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:inso", - "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:GZKLgaxJKL+GqxVLePMt8OVLJ6qTLrib5Mr/j2gjiNRY2k485YLB2OlzhBzZVnD3xLs0xi69JUfmLnM54j3aCA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cgeek", - "BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:th576H89dfymkG7/sH+DAIzjlmIqNEW6zY3ONrGeAml+k3f1ver399kYnEgG5YCaKXnnVM7P0oJHah80BV3mDw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:moul", - "37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:XRmbTYFkPeGVEU2mJzzN4h1oVNDsZ4yyNZlDAfBm9CWhBsZ82QqX9GPHye2hBxxiu4Nz1BHgQiME6B4JcAC8BA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:galuel" - ], - "joiners": [ - "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:ccJm3F44eLMhQtnQY/7+14SWCDqVTL3Miw65hBVpV+YiUSUknIGhBNN0C0Cf+Pf0/pa1tjucW8Us3z5IklFSDg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:inso", - "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:1lFIiaR0QX0jibr5zQpXVGzBvMGqcsTRlmHiwGz5HOAZT8PTdVUb5q6YGZ6qAUZjdMjPmhLaiMIpYc47wUnzBA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cgeek", - "BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:ctyAhpTRrAAOhFJukWI8RBr//nqYYdQibVzjOfaCdcWLb3TNFKrNBBothNsq/YrYHr7gKrpoftucf/oxLF8zAg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:moul", - "37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:uoiGaC5b7kWqtqdPxwatPk9QajZHCNT9rf8/8ud9Rli24z/igcOf0Zr4A6RTAIKWUq9foW39VqJe+Y9R3rhACw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:galuel" - ], - "actives": [], - "leavers": [], - "revoked": [], - "excluded": [], - "certifications": [ - "37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:3wmCVW8AbVxRFm2PuLXD9UTCIg93MhUblZJvlYrDldSV4xuA7mZCd8TV4vb/6Bkc0FMQgBdHtpXrQ7dpo20uBA==", - "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:7UMQsUjLvuiZKIzOH5rrZDdDi5rXUo69EuQulY1Zm42xpRx/Gt5CkoTcJ/Mu83oElQbcZZTz/lVJ6IS0jzMiCQ==", - "BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:twWSY9etI82FLEHzhdqIoHsC9ehWCA7DCPiGxDLCWGPO4TG77hwtn3RcC68qoKHCib577JCp+fcKyp2vyI6FDA==", - "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:7K5MHkO8ibf5SchmPkRrmsg9owEZZ23uEMJJSQYG7L3PUmAKmmV/0VSjivxXH8gJGQBGsXQoK79x1jsYnj2nAg==", - "BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:Jua4FcEJFptSE5OoG1/Mgzx4e9jgGnYu7t8g1sqqPujI9hRhLFNXbQXedPS1q1OD5vWivA045gKOq/gnj8opDg==", - "37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:R/DV4/wYjvBG09QSOGtnxd3bfPFhVjEE5Uy3BsBMVUvjLsgxjf8NgLhYVozcHTRWS43ArxlXKfS5m3+KIPhhAQ==", - "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:0:4hP+ahJK021akL4UxB6c5QLaGJXa9eapd3nfdFQe+Xy87f/XLhj8BCa22XbbOlyGdaZRT3AYzbCL2UD5tI8mCw==", - "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:0:sZTQJr0d/xQnxrIIdSePUJpSTOa8v6IYGXMF2fVDZxQU8vwfzPm2dUKTaF0nU6E9wOYszzkBHaXL85nir+WtCQ==", - "37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:0:hDuBkoFhWhR/FgOU1+9SbQGBMIr47xqUzw1ZMERaPQo4aWm0WFbZurG4lvuJZzTyG6RF/gSw4VPvYZFPxWmADg==", - "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:0:79ZVrBehElVZh82fJdR18IJx06GkEVZTbwdHH4zb0S6VaGwdtLh1rvomm4ukBvUc8r/suTweG/SScsJairXNAg==", - "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:0:e/ai9E4G5CFB9Qi329e0ffYpZMgxj8mM4rviqIr2+UESA0UG86OuAAyHO11hYeyolZRiU8I7WdtNE98B1uZuBg==", - "BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:0:q4PCneYkcPH8AHEqEvqTtYQWslhlYO2B87aReuOl1uPczn5Q3VkZFAsU48ZTYryeyWp2nxdQojdFYhlAUNchAw==" - ], - "transactions": [], - "raw": """Version: 2 -Type: Block -Currency: test_currency -Number: 0 -PoWMin: 3 -Time: 1421838980 -MedianTime: 1421838980 -Issuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk -Parameters: 0.1:86400:100:604800:15:604800:2629800:3:0.9:2629800:3:11:600:20:144:0.67 -MembersCount: 4 -Identities: -8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:Ot3zIp/nsHT3zgJy+2YcXPL6vaM5WFsD+F8w3qnJoBRuBG6lv761zoaExp2iyUnm8fDAyKPpMxRK2kf437QSCw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:inso -HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:GZKLgaxJKL+GqxVLePMt8OVLJ6qTLrib5Mr/j2gjiNRY2k485YLB2OlzhBzZVnD3xLs0xi69JUfmLnM54j3aCA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cgeek -BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:th576H89dfymkG7/sH+DAIzjlmIqNEW6zY3ONrGeAml+k3f1ver399kYnEgG5YCaKXnnVM7P0oJHah80BV3mDw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:moul -37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:XRmbTYFkPeGVEU2mJzzN4h1oVNDsZ4yyNZlDAfBm9CWhBsZ82QqX9GPHye2hBxxiu4Nz1BHgQiME6B4JcAC8BA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:galuel -Joiners: -8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:ccJm3F44eLMhQtnQY/7+14SWCDqVTL3Miw65hBVpV+YiUSUknIGhBNN0C0Cf+Pf0/pa1tjucW8Us3z5IklFSDg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:inso -HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:1lFIiaR0QX0jibr5zQpXVGzBvMGqcsTRlmHiwGz5HOAZT8PTdVUb5q6YGZ6qAUZjdMjPmhLaiMIpYc47wUnzBA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cgeek -BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:ctyAhpTRrAAOhFJukWI8RBr//nqYYdQibVzjOfaCdcWLb3TNFKrNBBothNsq/YrYHr7gKrpoftucf/oxLF8zAg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:moul -37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:uoiGaC5b7kWqtqdPxwatPk9QajZHCNT9rf8/8ud9Rli24z/igcOf0Zr4A6RTAIKWUq9foW39VqJe+Y9R3rhACw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:galuel -Actives: -Leavers: -Revoked: -Excluded: -Certifications: -37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:3wmCVW8AbVxRFm2PuLXD9UTCIg93MhUblZJvlYrDldSV4xuA7mZCd8TV4vb/6Bkc0FMQgBdHtpXrQ7dpo20uBA== -HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:7UMQsUjLvuiZKIzOH5rrZDdDi5rXUo69EuQulY1Zm42xpRx/Gt5CkoTcJ/Mu83oElQbcZZTz/lVJ6IS0jzMiCQ== -BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:twWSY9etI82FLEHzhdqIoHsC9ehWCA7DCPiGxDLCWGPO4TG77hwtn3RcC68qoKHCib577JCp+fcKyp2vyI6FDA== -8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:7K5MHkO8ibf5SchmPkRrmsg9owEZZ23uEMJJSQYG7L3PUmAKmmV/0VSjivxXH8gJGQBGsXQoK79x1jsYnj2nAg== -BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:Jua4FcEJFptSE5OoG1/Mgzx4e9jgGnYu7t8g1sqqPujI9hRhLFNXbQXedPS1q1OD5vWivA045gKOq/gnj8opDg== -37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:R/DV4/wYjvBG09QSOGtnxd3bfPFhVjEE5Uy3BsBMVUvjLsgxjf8NgLhYVozcHTRWS43ArxlXKfS5m3+KIPhhAQ== -8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:0:4hP+ahJK021akL4UxB6c5QLaGJXa9eapd3nfdFQe+Xy87f/XLhj8BCa22XbbOlyGdaZRT3AYzbCL2UD5tI8mCw== -HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:0:sZTQJr0d/xQnxrIIdSePUJpSTOa8v6IYGXMF2fVDZxQU8vwfzPm2dUKTaF0nU6E9wOYszzkBHaXL85nir+WtCQ== -37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:0:hDuBkoFhWhR/FgOU1+9SbQGBMIr47xqUzw1ZMERaPQo4aWm0WFbZurG4lvuJZzTyG6RF/gSw4VPvYZFPxWmADg== -8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:0:79ZVrBehElVZh82fJdR18IJx06GkEVZTbwdHH4zb0S6VaGwdtLh1rvomm4ukBvUc8r/suTweG/SScsJairXNAg== -HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:0:e/ai9E4G5CFB9Qi329e0ffYpZMgxj8mM4rviqIr2+UESA0UG86OuAAyHO11hYeyolZRiU8I7WdtNE98B1uZuBg== -BMAVuMDcGhYAV4wA27DL1VXX2ZARZGJYaMwpf7DJFMYH:37qBxM4hLV2jfyYo2bNzAjkeLngLr2r7G2HpdpKieVxw:0:q4PCneYkcPH8AHEqEvqTtYQWslhlYO2B87aReuOl1uPczn5Q3VkZFAsU48ZTYryeyWp2nxdQojdFYhlAUNchAw== -Transactions: -InnerHash: 09500111588846873CA0110602DDC17FB34AA9F4548B7CE322C845902FFC1429 -Nonce: 10144 -""" -} - -bma_blockchain_current = { - "version": 2, - "nonce": 6909, - "number": 15, - "powMin": 4, - "time": 1441618206, - "medianTime": 1441614759, - "membersCount": 20, - "monetaryMass": 11711349901120, - "currency": "test_currency", - "issuer": "EPs9qX7HmCDy6ptUoMLpTzbh9toHu4au488pBTU9DN6y", - "signature": "kz/34w1cG+8tYacuPXf3FPmsFwrvtWkwp1POLJuX1P0zYaB9Tuu7iyYJzMQS0Xa3vwuWRqfz+fgyoCGnBjBLBQ==", - "hash": "0000CB4E9CCDE6F579135331C97F13903E8B6E21", - "parameters": "", - "previousHash": "00003BDA844D77EEE7CF32A6C3C87F2ACBFCFCBB", - "previousIssuer": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", - "dividend": None, - "membersChanges": [], - "identities": [], - "joiners": [], - "actives": [], - "leavers": [], - "excluded": [], - "certifications": [], - "transactions": [], - "raw": """Version: 2 -Type: Block -Currency: meta_brouzouf -Number: 30898 -PoWMin: 4 -Time: 1441618206 -MedianTime: 1441614759 -Issuer: EPs9qX7HmCDy6ptUoMLpTzbh9toHu4au488pBTU9DN6y -PreviousHash: 00003BDA844D77EEE7CF32A6C3C87F2ACBFCFCBB -PreviousIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk -MembersCount: 20 -Identities: -Joiners: -Actives: -Leavers: -Revoked: -Excluded: -Certifications: -Transactions: -InnerHash: 6BB2E0BE18BEA428379336FB5F09DCE0EB594D09CDD705085CA91AA966C27CFA -Nonce: 6909 -""" -} - -# Sent 6, received 20 + 30 -bma_txhistory_john = { - "currency": "test_currency", - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "history": - { - "sent": - [ - { - "version": 2, - "issuers": - [ - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" - ], - "inputs": - [ - "D:7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ:8" - ], - "unlocks": - [ - "SIG(0)" - ], - "outputs": - [ - "2:1:SIG(7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ)", - "6:1:SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)" - ], - "comment": "", - "signatures": - [ - "1Mn8q3K7N+R4GZEpAUm+XSyty1Uu+BuOy5t7BIRqgZcKqiaxfhAUfDBOcuk2i4TJy1oA5Rntby8hDN+cUCpvDg==" - ], - "hash": "5FB3CB80A982E2BDFBB3EA94673A74763F58CB2A", - "block_number": 2, - "time": 1421932545 - }, - ], - "received": - [ - { - "version": 2, - "issuers": - [ - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" - ], - "inputs": - [ - "D:FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn:8" - ], - "unlocks": - [ - "SIG(0)" - ], - "outputs": - [ - "2:1:SIG(7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ)", - "6:1:SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)" - ], - "comment": "", - "signatures": - [ - "1Mn8q3K7N+R4GZEpAUm+XSyty1Uu+BuOy5t7BIRqgZcKqiaxfhAUfDBOcuk2i4TJy1oA5Rntby8hDN+cUCpvDg==" - ], - "hash": "5FB3CB80A982E2BDFBB3EA94673A74763F58CB2A", - "block_number": 2, - "time": 1421932545 - }, - { - "version": 2, - "issuers": - [ - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" - ], - "inputs": - [ - "D:FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn:8" - ], - "unlocks": - [ - "SIG(0)" - ], - "outputs": - [ - "5:1:SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)", - "40:1:SIG(7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ)" - ], - "comment": "", - "signatures": - [ - "1Mn8q3K7N+R4GZEpAUm+XSyty1Uu+BuOy5t7BIRqgZcKqiaxfhAUfDBOcuk2i4TJy1oA5Rntby8hDN+cUCpvDg==" - ], - "hash": "5FB3CB80A982E2BDFBB3EA94673A74763F58CB2A", - "block_number": 2, - "time": 1421932545 - }, - ], - "sending": [], - "receiving": [] - } -} - -bma_udhistory_john = { - "currency": "test_currency", - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "history": - { - "history": - [ - { - "block_number": 2, - "consumed": False, - "time": 1435749971, - "amount": 5, - "base": 1 - }, - { - "block_number": 10, - "consumed": False, - "time": 1435836032, - "amount": 10, - "base": 1 - } - ] - }} - -bma_txsources_john = { - "currency": "test_currency", - "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "sources": - [ - { - "type": "D", - "noffset": 2, - "identifier": "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", - "amount": 70, - "base": 0 - }, - { - "type": "D", - "noffset": 4, - "identifier": "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5", - "amount": 90, - "base": 0 - } - ]} - -bma_with_ud = { - "result": - { - "blocks": [] - } -} - - -def get_mock(loop): - mock = MockServer(loop) - - mock.add_route('GET', '/blockchain/parameters', bma_parameters, 200) - - mock.add_route('GET', '/blockchain/with/{topic}', bma_with_ud, 200) - - mock.add_route('GET', '/blockchain/current', bma_blockchain_current, 200) - - mock.add_route('GET', '/blockchain/block/0', bma_blockchain_0, 200) - - mock.add_route('GET', '/blockchain/block/15', bma_blockchain_current, 200) - - mock.add_route('GET', '/tx/history/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ/blocks/0/99', bma_txhistory_john, - 200) - - mock.add_route('GET', '/tx/sources/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_txsources_john, 200) - - mock.add_route('GET', '/ud/history/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_udhistory_john, 200) - - mock.add_route('GET', '/wot/certifiers-of/john', bma_certifiers_of_john, - 200) - - mock.add_route('GET', '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_certifiers_of_john, - 200) - - mock.add_route('GET', '/wot/certified-by/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_certified_by_john, 200) - - mock.add_route('GET', '/wot/lookup/john', bma_lookup_john, 200) - - mock.add_route('GET', '/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_lookup_john, 200) - - mock.add_route('GET', '/wot/lookup/doe', bma_lookup_doe, 200) - - mock.add_route('GET', '/wot/lookup/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn', bma_lookup_doe, 200) - - mock.add_route('GET', '/blockchain/memberships/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ', bma_membership_john, - 200) - - mock.add_route('GET', '/wot/lookup/wrong_pubkey', - {'ucode': errors.NO_MATCHING_IDENTITY, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/wrong_pubkey', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/lookup/wrong_uid', - {'ucode': errors.NO_MATCHING_IDENTITY, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/wrong_uid', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/wot/certifiers-of/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('GET', '/blockchain/memberships/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn', - {'ucode': errors.NO_MEMBER_MATCHING_PUB_OR_UID, 'message': "No member matching this pubkey or uid"}, 404) - - mock.add_route('POST', '/tx/process', {}, 200, ) - - return mock diff --git a/src/sakia/tests/mocks/server.py b/src/sakia/tests/mocks/server.py deleted file mode 100644 index 14bb1317acefbac9805c15e19ba08ba52b15e0c5..0000000000000000000000000000000000000000 --- a/src/sakia/tests/mocks/server.py +++ /dev/null @@ -1,102 +0,0 @@ -from aiohttp import web, log, errors -import json -import socket -from duniterpy.documents import Peer - - -def bma_peering_generator(port): - return { - "version": 2, - "currency": "test_currency", - "endpoints": [ - "BASIC_MERKLED_API 127.0.0.1 {port}".format(port=port) - ], - "status": "UP", - "block": "0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - "signature": "cXuqZuDfyHvxYAEUkPH1TQ1M+8YNDpj8kiHGYi3LIaMqEdVqwVc4yQYGivjxFMYyngRfxXkyvqBKZA6rKOulCA==", - "raw": "Version: 2\nType: Peer\nCurrency: meta_brouzouf\nPublicKey: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nBlock: 30152-00003E7F9234E7542FCF669B69B0F84FF79CCCD3\nEndpoints:\nBASIC_MERKLED_API 127.0.0.1 {port}\n".format(port=port), - "pubkey": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" - } - - -def peer_document_generator(port): - return Peer.from_signed_raw("""Version: 2 -Type: Peer -Currency: meta_brouzouf -PublicKey: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk -Block: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 -Endpoints: -BASIC_MERKLED_API 127.0.0.1 {port} -cXuqZuDfyHvxYAEUkPH1TQ1M+8YNDpj8kiHGYi3LIaMqEdVqwVc4yQYGivjxFMYyngRfxXkyvqBKZA6rKOulCA== -""".format(port=port)) - - -class Request(): - def __init__(self, method, url, content): - self.url = url - self.method = method - self.content = content - - -class MockServer(): - def __init__(self, loop): - self.lp = loop - self.requests = [] - self.app = web.Application(loop=self.lp, - middlewares=[self.middleware_factory]) - - self.handler = self.app.make_handler( - keep_alive_on=False, - access_log=log.access_logger, - ) - - self.port = self.find_unused_port() - - def get_request(self, i): - return self.requests[i] - - async def middleware_factory(self, app, handler): - async def middleware_handler(request): - try: - resp = await handler(request) - return resp - except web.HTTPNotFound: - return web.Response(status=404, body=bytes(json.dumps({"ucode":1001, - "message": "404 error"}), - "utf-8"), - headers={'Content-Type': 'application/json'}) - - return middleware_handler - - async def _handler(self, request, data_dict, http_code): - await request.read() - self.requests.append(Request(request.method, request.path, request.content)) - return web.Response(body=bytes(json.dumps(data_dict), "utf-8"), - headers={'Content-Type': 'application/json'}, - status=http_code) - - def add_route(self, req_type, url, data_dict, http_code=200): - self.app.router.add_route(req_type, url, - lambda request: self._handler(request, data_dict=data_dict, http_code=http_code)) - - def find_unused_port(self): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind(('127.0.0.1', 0)) - port = s.getsockname()[1] - s.close() - return port - - def peer(self): - return peer_document_generator(self.port) - - async def create_server(self, ssl_ctx=None): - srv = await self.lp.create_server(self.handler, '127.0.0.1', self.port) - protocol = "https" if ssl_ctx else "http" - url = "{}://127.0.0.1:{}".format(protocol, self.port) - - self.add_route('GET', '/network/peering', bma_peering_generator(self.port)) - - return srv, self.port, url - - async def close(self): - await self.handler.finish_connections() \ No newline at end of file diff --git a/src/sakia/tests/unit/data/test_blockchains_repo.py b/src/sakia/tests/unit/data/test_blockchains_repo.py index cdfd8662dc42dc392d58065d258c58be350d77a2..869683a6a33d9097bfec4bc26f4437c59becfaf2 100644 --- a/src/sakia/tests/unit/data/test_blockchains_repo.py +++ b/src/sakia/tests/unit/data/test_blockchains_repo.py @@ -1,202 +1,187 @@ -import sqlite3 -import unittest - from duniterpy.documents import BlockUID from sakia.data.entities import Blockchain, BlockchainParameters -from sakia.data.repositories import BlockchainsRepo, SakiaDatabase - - -class TestBlockchainsRepo(unittest.TestCase): - def setUp(self): - sqlite3.register_adapter(BlockUID, str) - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) - self.meta_repo.prepare() - self.meta_repo.upgrade_database() +from sakia.data.repositories import BlockchainsRepo - def tearDown(self): - pass - def test_add_get_drop_blockchain(self): - blockchains_repo = BlockchainsRepo(self.meta_repo.conn) - blockchains_repo.insert(Blockchain( - parameters=BlockchainParameters( - 0.1, - 86400, - 100000, - 10800, - 40, - 2629800, - 31557600, - 1, - 0.9, - 604800, - 5, - 12, - 300, - 25, - 10, - 0.66), - current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - current_members_count = 10, - current_mass = 1000000, - median_time = 86400, - last_members_count = 5, - last_ud = 100000, - last_ud_base = 0, - last_ud_time = 86400, - previous_mass = 999999, - previous_members_count = 10, - previous_ud = 6543, - previous_ud_base = 0, - previous_ud_time = 86400, - currency = "testcurrency" - )) - blockchain = blockchains_repo.get_one(currency="testcurrency") - self.assertEqual(blockchain.parameters, BlockchainParameters( - 0.1, - 86400, - 100000, - 10800, - 40, - 2629800, - 31557600, - 1, - 0.9, - 604800, - 5, - 12, - 300, - 25, - 10, - 0.66)) - self.assertEqual(blockchain.currency, "testcurrency") - self.assertEqual(blockchain.current_buid, BlockUID(20, - "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - ) - self.assertEqual(blockchain.current_members_count, 10) +def test_add_get_drop_blockchain(meta_repo): + blockchains_repo = BlockchainsRepo(meta_repo.conn) + blockchains_repo.insert(Blockchain( + parameters=BlockchainParameters( + 0.1, + 86400, + 100000, + 10800, + 40, + 2629800, + 31557600, + 1, + 0.9, + 604800, + 5, + 12, + 300, + 25, + 10, + 0.66), + current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + current_members_count = 10, + current_mass = 1000000, + median_time = 86400, + last_members_count = 5, + last_ud = 100000, + last_ud_base = 0, + last_ud_time = 86400, + previous_mass = 999999, + previous_members_count = 10, + previous_ud = 6543, + previous_ud_base = 0, + previous_ud_time = 86400, + currency = "testcurrency" + )) + blockchain = blockchains_repo.get_one(currency="testcurrency") + assert blockchain.parameters == BlockchainParameters( + 0.1, + 86400, + 100000, + 10800, + 40, + 2629800, + 31557600, + 1, + 0.9, + 604800, + 5, + 12, + 300, + 25, + 10, + 0.66) + assert blockchain.currency == "testcurrency" + assert blockchain.current_buid == BlockUID(20, "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + assert blockchain.current_members_count == 10 - blockchains_repo.drop(blockchain) - blockchain = blockchains_repo.get_one(currency="testcurrency") - self.assertIsNone(blockchain) + blockchains_repo.drop(blockchain) + blockchain = blockchains_repo.get_one(currency="testcurrency") + assert blockchain is None - def test_add_get_multiple_blockchain(self): - blockchains_repo = BlockchainsRepo(self.meta_repo.conn) - blockchains_repo.insert(Blockchain( - parameters=BlockchainParameters( - 0.1, - 86400, - 100000, - 10800, - 40, - 2629800, - 31557600, - 1, - 0.9, - 604800, - 5, - 12, - 300, - 25, - 10, - 0.66), +def test_add_get_multiple_blockchain(meta_repo): + blockchains_repo = BlockchainsRepo(meta_repo.conn) + blockchains_repo.insert(Blockchain( + parameters=BlockchainParameters( + 0.1, + 86400, + 100000, + 10800, + 40, + 2629800, + 31557600, + 1, + 0.9, + 604800, + 5, + 12, + 300, + 25, + 10, + 0.66), - current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - current_members_count = 10, - current_mass = 1000000, - median_time = 86400, - last_members_count = 5, - last_ud = 100000, - last_ud_base = 0, - last_ud_time = 86400, - previous_mass = 999999, - previous_members_count = 10, - previous_ud = 6543, - previous_ud_base = 0, - previous_ud_time = 86400, - currency = "testcurrency" - )) - blockchains_repo.insert(Blockchain( - BlockchainParameters( - 0.1, - 86400 * 365, - 100000, - 10800, - 40, - 2629800, - 31557600, - 1, - 0.9, - 604800, - 5, - 12, - 300, - 25, - 10, - 0.66), - current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - current_members_count = 20, - current_mass = 1000000, - median_time = 86400, - last_members_count = 5, - last_ud = 100000, - last_ud_base = 0, - last_ud_time = 86400, - previous_mass = 999999, - previous_members_count = 10, - previous_ud = 6543, - previous_ud_base = 0, - previous_ud_time = 86400, - currency = "testcurrency2" - )) + current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + current_members_count = 10, + current_mass = 1000000, + median_time = 86400, + last_members_count = 5, + last_ud = 100000, + last_ud_base = 0, + last_ud_time = 86400, + previous_mass = 999999, + previous_members_count = 10, + previous_ud = 6543, + previous_ud_base = 0, + previous_ud_time = 86400, + currency = "testcurrency" + )) + blockchains_repo.insert(Blockchain( + BlockchainParameters( + 0.1, + 86400 * 365, + 100000, + 10800, + 40, + 2629800, + 31557600, + 1, + 0.9, + 604800, + 5, + 12, + 300, + 25, + 10, + 0.66), + current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + current_members_count = 20, + current_mass = 1000000, + median_time = 86400, + last_members_count = 5, + last_ud = 100000, + last_ud_base = 0, + last_ud_time = 86400, + previous_mass = 999999, + previous_members_count = 10, + previous_ud = 6543, + previous_ud_base = 0, + previous_ud_time = 86400, + currency = "testcurrency2" + )) - blockchains = blockchains_repo.get_all() - # result sorted by currency name by default - self.assertEquals(86400, blockchains[0].parameters.dt) - self.assertEquals("testcurrency", blockchains[0].currency) - self.assertEquals(10, blockchains[0].current_members_count) + blockchains = blockchains_repo.get_all() + # result sorted by currency name by default + assert 86400 == blockchains[0].parameters.dt + assert "testcurrency" == blockchains[0].currency + assert 10 == blockchains[0].current_members_count - self.assertEquals(86400*365, blockchains[1].parameters.dt) - self.assertEquals("testcurrency2", blockchains[1].currency) - self.assertEquals(20, blockchains[1].current_members_count) + assert 86400*365 == blockchains[1].parameters.dt + assert "testcurrency2" == blockchains[1].currency + assert 20 == blockchains[1].current_members_count - def test_add_update_blockchain(self): - blockchains_repo = BlockchainsRepo(self.meta_repo.conn) - blockchain = Blockchain( - BlockchainParameters( - 0.1, - 86400, - 100000, - 10800, - 40, - 2629800, - 31557600, - 1, - 0.9, - 604800, - 5, - 12, - 300, - 25, - 10, - 0.66), - current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - current_members_count = 10, - current_mass = 1000000, - median_time = 86400, - last_members_count = 5, - last_ud = 100000, - last_ud_base = 0, - last_ud_time = 86400, - previous_mass = 999999, - previous_members_count = 10, - previous_ud = 6543, - previous_ud_base = 0, - previous_ud_time = 86400, - currency = "testcurrency" - ) - blockchains_repo.insert(blockchain) - blockchain.current_members_count = 30 - blockchains_repo.update(blockchain) - blockchain2 = blockchains_repo.get_one(currency="testcurrency") - self.assertEquals(30, blockchain2.current_members_count) +def test_add_update_blockchain(meta_repo): + blockchains_repo = BlockchainsRepo(meta_repo.conn) + blockchain = Blockchain( + BlockchainParameters( + 0.1, + 86400, + 100000, + 10800, + 40, + 2629800, + 31557600, + 1, + 0.9, + 604800, + 5, + 12, + 300, + 25, + 10, + 0.66), + current_buid="20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + current_members_count = 10, + current_mass = 1000000, + median_time = 86400, + last_members_count = 5, + last_ud = 100000, + last_ud_base = 0, + last_ud_time = 86400, + previous_mass = 999999, + previous_members_count = 10, + previous_ud = 6543, + previous_ud_base = 0, + previous_ud_time = 86400, + currency = "testcurrency" + ) + blockchains_repo.insert(blockchain) + blockchain.current_members_count = 30 + blockchains_repo.update(blockchain) + blockchain2 = blockchains_repo.get_one(currency="testcurrency") + assert 30 == blockchain2.current_members_count diff --git a/src/sakia/tests/unit/data/test_certifications_repo.py b/src/sakia/tests/unit/data/test_certifications_repo.py index 082d043ec6541c4ae26c48afb49ffb59ef6775d2..4126ade13bb3338c483e417f17874c52db1a20e2 100644 --- a/src/sakia/tests/unit/data/test_certifications_repo.py +++ b/src/sakia/tests/unit/data/test_certifications_repo.py @@ -1,83 +1,74 @@ -from sakia.data.repositories import CertificationsRepo, SakiaDatabase +from sakia.data.repositories import CertificationsRepo from sakia.data.entities import Certification from duniterpy.documents import BlockUID -import unittest -import sqlite3 -class TestCertificationsRepo(unittest.TestCase): - def setUp(self): - sqlite3.register_adapter(BlockUID, str) - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) - self.meta_repo.prepare() - self.meta_repo.upgrade_database() +def test_add_get_drop_blockchain(meta_repo): + certifications_repo = CertificationsRepo(meta_repo.conn) + certifications_repo.insert(Certification("testcurrency", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + 20, + 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + None)) + certification = certifications_repo.get_one(currency="testcurrency", + certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + block=20) + assert certification.currency == "testcurrency" + assert certification.certifier == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" + assert certification.certified == "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" + assert certification.block == 20 + assert certification.timestamp == 1473108382 + assert certification.signature == "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==" + assert certification.written_on == BlockUID.empty() + certifications_repo.drop(certification) + certification = certifications_repo.get_one(currency="testcurrency", + certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + block=20) + assert certification is None - def tearDown(self): - pass - def test_add_get_drop_blockchain(self): - certifications_repo = CertificationsRepo(self.meta_repo.conn) - certifications_repo.insert(Certification("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - 20, - 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - None)) - certification = certifications_repo.get_one(currency="testcurrency", - certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - block=20) - self.assertEqual(certification.currency, "testcurrency") - self.assertEqual(certification.certifier, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(certification.certified, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") - self.assertEqual(certification.block, 20) - self.assertEqual(certification.timestamp, 1473108382) - self.assertEqual(certification.signature, "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==") - self.assertEqual(certification.written_on, BlockUID.empty()) - certifications_repo.drop(certification) - certification = certifications_repo.get_one(currency="testcurrency", - certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - block=20) - self.assertIsNone(certification) +def test_add_get_multiple_certification(meta_repo): + certifications_repo = CertificationsRepo(meta_repo.conn) + certifications_repo.insert(Certification("testcurrency", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + 20, 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + "22-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) + certifications_repo.insert(Certification("testcurrency", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + 101, 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + "105-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) + certifications = certifications_repo.get_all(currency="testcurrency") + assert "testcurrency" in [i.currency for i in certifications] + assert "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" in [i.certifier for i in certifications] + assert "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in [i.certifier for i in certifications] + assert "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" in [i.certified for i in certifications] + assert "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in [i.certified for i in certifications] - def test_add_get_multiple_certification(self): - certifications_repo = CertificationsRepo(self.meta_repo.conn) - certifications_repo.insert(Certification("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - 20, 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - "22-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) - certifications_repo.insert(Certification("testcurrency", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - 101, 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - "105-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) - certifications = certifications_repo.get_all(currency="testcurrency") - self.assertIn("testcurrency", [i.currency for i in certifications]) - self.assertIn("FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", [i.certifier for i in certifications]) - self.assertIn("7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", [i.certifier for i in certifications]) - self.assertIn("FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", [i.certified for i in certifications]) - self.assertIn("7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", [i.certified for i in certifications]) - def test_add_update_certification(self): - certifications_repo = CertificationsRepo(self.meta_repo.conn) - certification = Certification("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - 20, - 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - None) +def test_add_update_certification(meta_repo): + certifications_repo = CertificationsRepo(meta_repo.conn) + certification = Certification("testcurrency", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + 20, + 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + None) + + certifications_repo.insert(certification) + certification.written_on = BlockUID(22, "148C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + certifications_repo.update(certification) + cert2 = certifications_repo.get_one(currency="testcurrency", + certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + block=20) + assert cert2.written_on == BlockUID(22, "148C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - certifications_repo.insert(certification) - certification.written_on = BlockUID(22, "148C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - certifications_repo.update(certification) - cert2 = certifications_repo.get_one(currency="testcurrency", - certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - block=20) - self.assertTrue(cert2.written_on) diff --git a/src/sakia/tests/unit/data/test_connections_repo.py b/src/sakia/tests/unit/data/test_connections_repo.py index 44994532d2d484c7d4cf7a44f159ed815cf78b6d..0f4911312a22f0519e3038e45d8652d9340b64b9 100644 --- a/src/sakia/tests/unit/data/test_connections_repo.py +++ b/src/sakia/tests/unit/data/test_connections_repo.py @@ -1,33 +1,19 @@ -from sakia.data.repositories import ConnectionsRepo, SakiaDatabase +from sakia.data.repositories import ConnectionsRepo from sakia.data.entities import Connection -from duniterpy.documents import BlockUID -import unittest -import sqlite3 - -class TestConnectionsRepo(unittest.TestCase): - def setUp(self): - sqlite3.register_adapter(BlockUID, str) - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) - self.meta_repo.prepare() - self.meta_repo.upgrade_database() - - def tearDown(self): - pass - - def test_add_get_drop_connection(self): - connections_repo = ConnectionsRepo(self.meta_repo.conn) - connections_repo.insert(Connection("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "somesalt")) - connection = connections_repo.get_one(currency="testcurrency", - pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - salt="somesalt") - self.assertEqual(connection.currency, "testcurrency") - self.assertEqual(connection.pubkey, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(connection.salt, "somesalt") - connections_repo.drop(connection) - connection = connections_repo.get_one(currency="testcurrency", - pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - salt="somesalt") - self.assertIsNone(connection) +def test_add_get_drop_connection(meta_repo): + connections_repo = ConnectionsRepo(meta_repo.conn) + connections_repo.insert(Connection("testcurrency", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "somesalt")) + connection = connections_repo.get_one(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + salt="somesalt") + assert connection.currency == "testcurrency" + assert connection.pubkey == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" + assert connection.salt == "somesalt" + connections_repo.drop(connection) + connection = connections_repo.get_one(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + salt="somesalt") + assert connection is None diff --git a/src/sakia/tests/unit/data/test_identies_repo.py b/src/sakia/tests/unit/data/test_identies_repo.py index c0616f13a1a4064e2d4bcdfd5c7524f85d2d9638..bb76e172b5ed5ce82203ec02c466cf322bbd5492 100644 --- a/src/sakia/tests/unit/data/test_identies_repo.py +++ b/src/sakia/tests/unit/data/test_identies_repo.py @@ -1,111 +1,97 @@ -from sakia.data.repositories import IdentitiesRepo, SakiaDatabase +from sakia.data.repositories import IdentitiesRepo from sakia.data.entities import Identity from duniterpy.documents import BlockUID -import unittest -import sqlite3 -class TestIdentitiesRepo(unittest.TestCase): - def setUp(self): - sqlite3.register_adapter(BlockUID, str) - sqlite3.register_adapter(bool, int) - sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v))) - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) - self.meta_repo.prepare() - self.meta_repo.upgrade_database() +def test_add_get_drop_identity(meta_repo): + identities_repo = IdentitiesRepo(meta_repo.conn) + identities_repo.insert(Identity("testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "john", + "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + 1473108382, + None, + None, + False, + None, + 0, + '', + None)) + identity = identities_repo.get_one(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + uid="john", + blockstamp=BlockUID(20, + "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + ) + assert identity.currency == "testcurrency" + assert identity.pubkey == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" + assert identity.uid == "john" + assert identity.blockstamp.number == 20 + assert identity.blockstamp.sha_hash == "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67" + assert identity.timestamp == 1473108382 + assert identity.signature == "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==" + assert identity.member == False + assert identity.membership_buid == BlockUID.empty() + assert identity.membership_timestamp == 0 + assert identity.membership_written_on == BlockUID.empty() + identities_repo.drop(identity) + identity = identities_repo.get_one(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + uid="john", + blockstamp=BlockUID(20, + "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + ) + assert identity is None - def tearDown(self): - pass +def test_add_get_multiple_identity(meta_repo): + identities_repo = IdentitiesRepo(meta_repo.conn) + identities_repo.insert(Identity("testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "john", + "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + 1473108382, + None, + None, + False, + None, + 0, + '', + None)) + identities_repo.insert(Identity("testcurrency", "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "doe", + "101-BAD49448A1AD73C978CEDCB8F137D20A5715EBAA739DAEF76B1E28EE67B2C00C", + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + 1455433535, + None, + None, + False, + None, + 0, + '', + None)) + identities = identities_repo.get_all(currency="testcurrency") + assert "testcurrency" in [i.currency for i in identities] + assert "john" in [i.uid for i in identities] + assert "doe" in [i.uid for i in identities] - def test_add_get_drop_identity(self): - identities_repo = IdentitiesRepo(self.meta_repo.conn) - identities_repo.insert(Identity("testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "john", - "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - 1473108382, - None, - None, - False, - None, - 0, - '', - None)) - identity = identities_repo.get_one(currency="testcurrency", - pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - uid="john", - blockstamp=BlockUID(20, - "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - ) - self.assertEqual(identity.currency, "testcurrency") - self.assertEqual(identity.pubkey, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(identity.uid, "john") - self.assertEqual(identity.blockstamp.number, 20) - self.assertEqual(identity.blockstamp.sha_hash, "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - self.assertEqual(identity.timestamp, 1473108382) - self.assertEqual(identity.signature, "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==") - self.assertEqual(identity.member, False) - self.assertEqual(identity.membership_buid, BlockUID.empty()) - self.assertEqual(identity.membership_timestamp, 0) - self.assertEqual(identity.membership_written_on, BlockUID.empty()) - identities_repo.drop(identity) - identity = identities_repo.get_one(currency="testcurrency", - pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - uid="john", - blockstamp=BlockUID(20, - "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - ) - self.assertIsNone(identity) - - def test_add_get_multiple_identity(self): - identities_repo = IdentitiesRepo(self.meta_repo.conn) - identities_repo.insert(Identity("testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "john", - "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - 1473108382, - None, - None, - False, - None, - 0, - '', - None)) - identities_repo.insert(Identity("testcurrency", "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "doe", - "101-BAD49448A1AD73C978CEDCB8F137D20A5715EBAA739DAEF76B1E28EE67B2C00C", - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - 1455433535, - None, - None, - False, - None, - 0, - '', - None)) - identities = identities_repo.get_all(currency="testcurrency") - self.assertIn("testcurrency", [i.currency for i in identities]) - self.assertIn("john", [i.uid for i in identities]) - self.assertIn("doe", [i.uid for i in identities]) - - def test_add_update_identity(self): - identities_repo = IdentitiesRepo(self.meta_repo.conn) - identity = Identity("testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "john", - "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - 1473108382, - None, - None, - False, - None, - 0, - '', - None) - identities_repo.insert(identity) - identity.member = True - identities_repo.update(identity) - identity2 = identities_repo.get_one(currency="testcurrency", - pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertTrue(identity2.member) +def test_add_update_identity(meta_repo): + identities_repo = IdentitiesRepo(meta_repo.conn) + identity = Identity("testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "john", + "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + 1473108382, + None, + None, + False, + None, + 0, + '', + None) + identities_repo.insert(identity) + identity.member = True + identities_repo.update(identity) + identity2 = identities_repo.get_one(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") + assert identity2.member is True diff --git a/src/sakia/tests/unit/data/test_node_connector.py b/src/sakia/tests/unit/data/test_node_connector.py index de9b3574c0815d0c3ddbbad59c64bca9f4cf3152..01f48e1cc7078c0e984228d28cf077bed308836b 100644 --- a/src/sakia/tests/unit/data/test_node_connector.py +++ b/src/sakia/tests/unit/data/test_node_connector.py @@ -1,21 +1,10 @@ -import unittest from unittest.mock import Mock from duniterpy.documents import Peer -from PyQt5.QtCore import QLocale from sakia.data.connectors import NodeConnector -from sakia.tests import QuamashTest -class TestNodeConnector(unittest.TestCase, QuamashTest): - def setUp(self): - self.setUpQuamash() - QLocale.setDefault(QLocale("en_GB")) - - def tearDown(self): - self.tearDownQuamash() - - def test_from_peer(self): - peer = Peer.from_signed_raw("""Version: 2 +def test_from_peer(): + peer = Peer.from_signed_raw("""Version: 2 Type: Peer Currency: meta_brouzouf PublicKey: 8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU @@ -24,7 +13,7 @@ Endpoints: BASIC_MERKLED_API duniter.inso.ovh 80 82o1sNCh1bLpUXU6nacbK48HBcA9Eu2sPkL1/3c2GtDPxBUZd2U2sb7DxwJ54n6ce9G0Oy7nd1hCxN3fS0oADw== """) - connector = NodeConnector.from_peer('meta_brouzouf', peer, Mock("aiohttp.ClientSession")) - self.assertEqual(connector.node.pubkey, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU") - self.assertEqual(connector.node.endpoints[0].inline(), "BASIC_MERKLED_API duniter.inso.ovh 80") - self.assertEqual(connector.node.currency, "meta_brouzouf") + connector = NodeConnector.from_peer('meta_brouzouf', peer, Mock("aiohttp.ClientSession")) + assert connector.node.pubkey == "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" + assert connector.node.endpoints[0].inline() == "BASIC_MERKLED_API duniter.inso.ovh 80" + assert connector.node.currency == "meta_brouzouf" diff --git a/src/sakia/tests/unit/data/test_nodes_repo.py b/src/sakia/tests/unit/data/test_nodes_repo.py index dabc0f71fc859bf652a4d13a01ea3849cbc8dd48..ac83284f2442f52db2fd4be24cf4ff86fc36f85d 100644 --- a/src/sakia/tests/unit/data/test_nodes_repo.py +++ b/src/sakia/tests/unit/data/test_nodes_repo.py @@ -1,99 +1,94 @@ -from sakia.data.repositories import NodesRepo, SakiaDatabase +from sakia.data.repositories import NodesRepo from sakia.data.entities import Node from duniterpy.documents import BlockUID, BMAEndpoint, UnknownEndpoint, block_uid -import unittest -import sqlite3 -class TestNodesRepo(unittest.TestCase): - def setUp(self): - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) - self.meta_repo.prepare() - self.meta_repo.upgrade_database() - - def tearDown(self): - pass - - def test_add_get_drop_node(self): - nodes_repo = NodesRepo(self.meta_repo.conn) - inserted = Node("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - """BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 +def test_add_get_drop_node(meta_repo): + nodes_repo = NodesRepo(meta_repo.conn) + inserted = Node(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + endpoints="""BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 BASIC_MERKLED_API testnet.duniter.org 80 UNKNOWNAPI some useless information""", - BlockUID.empty(), - "doe", - "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - Node.ONLINE, - "duniter", - "0.30.17") - nodes_repo.insert(inserted) - node = nodes_repo.get_one(currency="testcurrency", - pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(node.currency, "testcurrency") - self.assertEqual(node.pubkey, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(node.endpoints[0], BMAEndpoint("test-net.duniter.fr", "13.222.11.22", None, 9201)) - self.assertEqual(node.endpoints[1], BMAEndpoint("testnet.duniter.org", None, None, 80)) - self.assertEqual(node.endpoints[2], UnknownEndpoint("UNKNOWNAPI", ["some", "useless", "information"])) - self.assertEqual(node.previous_buid, block_uid("14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) - self.assertEqual(node.current_buid, block_uid("15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) - self.assertEqual(node.state, Node.ONLINE) - self.assertEqual(node.software, "duniter") - self.assertEqual(node.version, "0.30.17") - self.assertEqual(node.merkle_peers_root, Node.MERKLE_EMPTY_ROOT) - self.assertEqual(node.merkle_peers_leaves, tuple()) + peer_blockstamp=BlockUID.empty(), + uid="doe", + current_buid="15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + current_ts=12376543345, + previous_buid="14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + state=Node.ONLINE, + software="duniter", + version="0.30.17") + nodes_repo.insert(inserted) + node = nodes_repo.get_one(currency="testcurrency", + pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") + assert node.currency == "testcurrency" + assert node.pubkey == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" + assert node.endpoints[0] == BMAEndpoint("test-net.duniter.fr", "13.222.11.22", None, 9201) + assert node.endpoints[1] == BMAEndpoint("testnet.duniter.org", None, None, 80) + assert node.endpoints[2] == UnknownEndpoint("UNKNOWNAPI", ["some", "useless", "information"]) + assert node.previous_buid == block_uid("14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + assert node.current_buid == block_uid("15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + assert node.state == Node.ONLINE + assert node.software == "duniter" + assert node.version == "0.30.17" + assert node.merkle_peers_root == Node.MERKLE_EMPTY_ROOT + assert node.merkle_peers_leaves == tuple() - nodes_repo.drop(node) - node = nodes_repo.get_one(pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertIsNone(node) + nodes_repo.drop(node) + node = nodes_repo.get_one(pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") + assert node is None - def test_add_get_multiple_node(self): - nodes_repo = NodesRepo(self.meta_repo.conn) - nodes_repo.insert(Node("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - """BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 + +def test_add_get_multiple_node(meta_repo): + nodes_repo = NodesRepo(meta_repo.conn) + nodes_repo.insert(Node("testcurrency", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + """BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 BASIC_MERKLED_API testnet.duniter.org 80 UNKNOWNAPI some useless information""", - BlockUID.empty(), - "doe", - "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - Node.ONLINE, - "duniter", - "0.30.17")) - nodes_repo.insert(Node("testcurrency", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "BASIC_MERKLED_API test-net.duniter.org 22.22.22.22 9201", - BlockUID.empty(), - "doe", - "18-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "12-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - Node.ONLINE, - "duniter", - "0.30.2a5")) - nodes = nodes_repo.get_all(currency="testcurrency") - self.assertIn("testcurrency", [t.currency for t in nodes]) - self.assertIn("7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", [n.pubkey for n in nodes]) - self.assertIn("FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", [n.pubkey for n in nodes]) + BlockUID.empty(), + "doe", + "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 12376543345, + "14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + Node.ONLINE, + "duniter", + "0.30.17")) + nodes_repo.insert(Node("testcurrency", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "BASIC_MERKLED_API test-net.duniter.org 22.22.22.22 9201", + BlockUID.empty(), + "doe", + "18-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 12376543345, + "12-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + Node.ONLINE, + "duniter", + "0.30.2a5")) + nodes = nodes_repo.get_all(currency="testcurrency") + assert "testcurrency" in [t.currency for t in nodes] + assert "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in [n.pubkey for n in nodes] + assert "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" in [n.pubkey for n in nodes] + - def test_add_update_node(self): - nodes_repo = NodesRepo(self.meta_repo.conn) - node = Node("testcurrency", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - """BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 +def test_add_update_node(meta_repo): + nodes_repo = NodesRepo(meta_repo.conn) + node = Node("testcurrency", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + """BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 BASIC_MERKLED_API testnet.duniter.org 80 UNKNOWNAPI some useless information""", - BlockUID.empty(), - "doe", - "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - Node.ONLINE, - "duniter") - nodes_repo.insert(node) - node.previous_buid = node.current_buid - node.current_buid = "16-77543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67" - nodes_repo.update(node) - node2 = nodes_repo.get_one(pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(node2.current_buid, block_uid("16-77543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) - self.assertEqual(node2.previous_buid, block_uid("15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")) + BlockUID.empty(), + "doe", + "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 12376543345, + "14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + Node.ONLINE, + "duniter") + nodes_repo.insert(node) + node.previous_buid = node.current_buid + node.current_buid = "16-77543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67" + nodes_repo.update(node) + node2 = nodes_repo.get_one(pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") + assert node2.current_buid == block_uid("16-77543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") + assert node2.previous_buid == block_uid("15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") diff --git a/src/sakia/tests/unit/data/test_sources_repo.py b/src/sakia/tests/unit/data/test_sources_repo.py index 27cbdbaad399691c97db132d6a50c222672eac85..89fadbfb6e2268396a2edab7562ca2a9af29953f 100644 --- a/src/sakia/tests/unit/data/test_sources_repo.py +++ b/src/sakia/tests/unit/data/test_sources_repo.py @@ -1,62 +1,51 @@ -from sakia.data.repositories import SourcesRepo, SakiaDatabase +from sakia.data.repositories import SourcesRepo from sakia.data.entities import Source -from duniterpy.documents import BlockUID -import unittest -import sqlite3 -class TestSourcesRepo(unittest.TestCase): - def setUp(self): - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) - self.meta_repo.prepare() - self.meta_repo.upgrade_database() +def test_add_get_drop_source( meta_repo): + sources_repo = SourcesRepo(meta_repo.conn) + sources_repo.insert(Source("testcurrency", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843", + 3, + "T", + 1565, + 1)) + source = sources_repo.get_one(identifier="0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843") + assert source.currency == "testcurrency" + assert source.pubkey == "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" + assert source.type == "T" + assert source.amount == 1565 + assert source.base == 1 + assert source.noffset == 3 - def tearDown(self): - pass + sources_repo.drop(source) + source = sources_repo.get_one(identifier="0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843") + assert source is None - def test_add_get_drop_source(self): - sources_repo = SourcesRepo(self.meta_repo.conn) - sources_repo.insert(Source("testcurrency", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843", - 3, - "T", - 1565, - 1)) - source = sources_repo.get_one(identifier="0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843") - self.assertEqual(source.currency, "testcurrency") - self.assertEqual(source.pubkey, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") - self.assertEqual(source.type, "T") - self.assertEqual(source.amount, 1565) - self.assertEqual(source.base, 1) - self.assertEqual(source.noffset, 3) - sources_repo.drop(source) - source = sources_repo.get_one(identifier="0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843") - self.assertIsNone(source) - - def test_add_get_multiple_source(self): - sources_repo = SourcesRepo(self.meta_repo.conn) - sources_repo.insert(Source("testcurrency", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843", - 3, - "T", - 1565, - 1)) - sources_repo.insert(Source("testcurrency", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "2pyPsXM8UCB88jP2NRM4rUHxb63qm89JMEWbpoRrhyDK", - 22635, - "D", - 726946, - 1)) - sources = sources_repo.get_all(currency="testcurrency", pubkey="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") - self.assertIn("testcurrency", [s.currency for s in sources]) - self.assertIn("FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", [s.pubkey for s in sources]) - self.assertIn("2pyPsXM8UCB88jP2NRM4rUHxb63qm89JMEWbpoRrhyDK", [s.identifier for s in sources]) - self.assertIn("T", [s.type for s in sources]) - self.assertIn("D", [s.type for s in sources]) - self.assertIn(726946, [s.amount for s in sources]) - self.assertIn(1565, [s.amount for s in sources]) - self.assertIn("0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843", [s.identifier for s in sources]) +def test_add_get_multiple_source(meta_repo): + sources_repo = SourcesRepo(meta_repo.conn) + sources_repo.insert(Source("testcurrency", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843", + 3, + "T", + 1565, + 1)) + sources_repo.insert(Source("testcurrency", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "2pyPsXM8UCB88jP2NRM4rUHxb63qm89JMEWbpoRrhyDK", + 22635, + "D", + 726946, + 1)) + sources = sources_repo.get_all(currency="testcurrency", pubkey="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") + assert "testcurrency" in [s.currency for s in sources] + assert "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" in [s.pubkey for s in sources] + assert "2pyPsXM8UCB88jP2NRM4rUHxb63qm89JMEWbpoRrhyDK" in [s.identifier for s in sources] + assert "T" in [s.type for s in sources] + assert "D" in [s.type for s in sources] + assert 726946 in [s.amount for s in sources] + assert 1565 in [s.amount for s in sources] + assert "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843" in [s.identifier for s in sources] diff --git a/src/sakia/tests/unit/data/test_transactions_repo.py b/src/sakia/tests/unit/data/test_transactions_repo.py index cc481ffe35608f3f038b65f5d323f6cee7a4465d..8582943e037b747984ef9e944ac00366d39bf472 100644 --- a/src/sakia/tests/unit/data/test_transactions_repo.py +++ b/src/sakia/tests/unit/data/test_transactions_repo.py @@ -1,110 +1,93 @@ -from sakia.data.repositories import TransactionsRepo, SakiaDatabase +from sakia.data.repositories import TransactionsRepo from sakia.data.entities import Transaction from duniterpy.documents import BlockUID -import unittest -import sqlite3 -class TestTransactionsRepo(unittest.TestCase): - def setUp(self): - sqlite3.register_adapter(BlockUID, str) - sqlite3.register_adapter(bool, int) - sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v))) - self.meta_repo = SakiaDatabase(sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)) +def test_add_get_drop_transaction(meta_repo): + transactions_repo = TransactionsRepo(meta_repo.conn) + transactions_repo.insert(Transaction("testcurrency", + "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", + 20, + "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + 1565, + 1, + "", + 0, + Transaction.LOCAL)) + transaction = transactions_repo.get_one(sha_hash="FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") + assert transaction.currency == "testcurrency" + assert transaction.sha_hash == "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365" + assert transaction.written_block == 20 + assert transaction.blockstamp.number == 15 + assert transaction.blockstamp.sha_hash == "76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67" + assert transaction.timestamp == 1473108382 + assert transaction.signature == "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==" + assert transaction.amount == 1565 + assert transaction.amount_base == 1 + assert transaction.issuer == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" + assert transaction.receiver == "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" + assert transaction.comment == "" + assert transaction.txid == 0 + transactions_repo.drop(transaction) + transaction = transactions_repo.get_one(sha_hash="FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") + assert transaction is None - def tearDown(self): - self.con.close() - def test_add_get_drop_transaction(self): - meta_repo = SakiaDatabase(self.con) - meta_repo.prepare() - meta_repo.upgrade_database() - transactions_repo = TransactionsRepo(self.con) - transactions_repo.insert(Transaction("testcurrency", - "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", - "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - 1565, - 1, - "", - 0)) - transaction = transactions_repo.get_one(sha_hash="FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") - self.assertEqual(transaction.currency, "testcurrency") - self.assertEqual(transaction.sha_hash, "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") - self.assertEqual(transaction.written_on.number, 20) - self.assertEqual(transaction.written_on.sha_hash, "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - self.assertEqual(transaction.blockstamp.number, 15) - self.assertEqual(transaction.blockstamp.sha_hash, "76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") - self.assertEqual(transaction.timestamp, 1473108382) - self.assertEqual(transaction.signature, "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==") - self.assertEqual(transaction.amount, 1565) - self.assertEqual(transaction.amount_base, 1) - self.assertEqual(transaction.issuer, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") - self.assertEqual(transaction.receiver, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn") - self.assertEqual(transaction.comment, "") - self.assertEqual(transaction.txid, 0) +def test_add_get_multiple_transaction(meta_repo): + transactions_repo = TransactionsRepo(meta_repo.conn) + transactions_repo.insert(Transaction("testcurrency", + "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5", + 12, + "543-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + 14, + 2, + "Test", + 2, + Transaction.LOCAL)) + transactions_repo.insert(Transaction("testcurrency", + "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", + 20, + "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + 1565, + 1, + "", + 0, + Transaction.LOCAL)) + transactions = transactions_repo.get_all(currency="testcurrency") + assert "testcurrency" in [t.currency for t in transactions] + assert "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in [t.receiver for t in transactions] + assert "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" in [t.issuer for t in transactions] - transactions_repo.drop(transaction) - transaction = transactions_repo.get_one(sha_hash="FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") - self.assertIsNone(transaction) - def test_add_get_multiple_transaction(self): - meta_repo = SakiaDatabase(self.con) - meta_repo.prepare() - meta_repo.upgrade_database() - transactions_repo = TransactionsRepo(self.con) - transactions_repo.insert(Transaction("testcurrency", - "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5", - "12-AAEFCCE0E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "543-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - 14, - 2, - "Test", - 2)) - transactions_repo.insert(Transaction("testcurrency", - "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", - "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - 1565, - 1, - "", - 0)) - transactions = transactions_repo.get_all(currency="testcurrency") - self.assertIn("testcurrency", [t.currency for t in transactions]) - self.assertIn("7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", [t.receiver for t in transactions]) - self.assertIn("FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", [t.issuer for t in transactions]) - - def test_add_update_transaction(self): - meta_repo = SakiaDatabase(self.con) - meta_repo.prepare() - meta_repo.upgrade_database() - transactions_repo = TransactionsRepo(self.con) - transaction = Transaction("testcurrency", - "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", - "20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", - 1473108382, - "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", - "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", - "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", - 1565, - 1, - "", - 0) - transactions_repo.insert(transaction) - transaction.written_on = None - transactions_repo.update(transaction) - transaction2 = transactions_repo.get_one(sha_hash="FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") - self.assertEqual(transaction2.written_on, BlockUID.empty()) +def test_add_update_transaction(meta_repo): + transactions_repo = TransactionsRepo(meta_repo.conn) + transaction = Transaction("testcurrency", + "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365", + 20, + "15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", + 1473108382, + "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==", + "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", + "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", + 1565, + 1, + "", + 0, + Transaction.LOCAL) + transactions_repo.insert(transaction) + transaction.written_on = None + transactions_repo.update(transaction) + transaction2 = transactions_repo.get_one(sha_hash="FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365") + assert transaction2.written_block == 20 diff --git a/src/sakia/tests/unit/data/test_user_parameters_file.py b/src/sakia/tests/unit/data/test_user_parameters_file.py index 1013a6d74f652cd64b77f3601b42230bda8cddd7..a001f1998c106de489924fa1e9e786436673bba7 100644 --- a/src/sakia/tests/unit/data/test_user_parameters_file.py +++ b/src/sakia/tests/unit/data/test_user_parameters_file.py @@ -1,16 +1,14 @@ from sakia.data.entities import UserParameters from sakia.data.files import UserParametersFile import tempfile -import unittest import os -class TestUserParametersFile(unittest.TestCase): - def test_init_save_load(self): - file = os.path.join(tempfile.mkdtemp(), "params.json") - user_parameters = UserParameters() - user_parameters_file = UserParametersFile(file) - user_parameters.proxy_address = "test.fr" - user_parameters_file.save(user_parameters) - user_parameters_2 = user_parameters_file.load_or_init() - self.assertEqual(user_parameters, user_parameters_2) +def test_init_save_load(): + file = os.path.join(tempfile.mkdtemp(), "params.json") + user_parameters = UserParameters() + user_parameters_file = UserParametersFile(file) + user_parameters.proxy_address = "test.fr" + user_parameters_file.save(user_parameters) + user_parameters_2 = user_parameters_file.load_or_init() + assert user_parameters == user_parameters_2