Skip to content
Snippets Groups Projects
Commit b529f4e3 authored by inso's avatar inso
Browse files

Fix diverse errors

parent f0b49b61
No related branches found
No related tags found
No related merge requests found
......@@ -82,7 +82,7 @@ class Application(QObject):
:param profile_name:
:return:
"""
self._parameters = UserParametersFile.in_config_path(self.options.config_path, profile_name).load_or_init()
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()
......
......@@ -13,8 +13,8 @@ class Identity:
signature = attr.ib(convert=str, default="", cmp=False, hash=False)
# Mediantime of the block referenced by blockstamp
timestamp = attr.ib(convert=int, default=0, cmp=False, hash=False)
written_on = attr.ib(convert=block_uid, default=BlockUID.empty(), cmp=False, hash=False)
revoked_on = attr.ib(convert=block_uid, default=BlockUID.empty(), cmp=False, hash=False)
written_on = attr.ib(convert=int, default=0, cmp=False, hash=False)
revoked_on = attr.ib(convert=int, default=0, cmp=False, hash=False)
member = attr.ib(validator=attr.validators.instance_of(bool), default=False, cmp=False, hash=False)
membership_buid = attr.ib(convert=block_uid, default=BlockUID.empty(), cmp=False, hash=False)
membership_timestamp = attr.ib(convert=int, default=0, cmp=False, hash=False)
......
......@@ -109,8 +109,7 @@ class CertificationsProcessor:
blockstamp=certifier_data['sigDate'],
member=certifier_data['isMember'])
if certifier_data['written']:
certification.written_on = BlockUID(certifier_data['written']['number'],
certifier_data['written']['hash'])
certification.written_on = certifier_data['written']['number']
certifiers.append(certification)
identities.append(other_identity)
......@@ -139,8 +138,7 @@ class CertificationsProcessor:
blockstamp=certified_data['sigDate'],
member=certified_data['isMember'])
if certified_data['written']:
certification.written_on = BlockUID(certified_data['written']['number'],
certified_data['written']['hash'])
certification.written_on = certified_data['written']['number']
certified.append(certification)
identities.append(other_identity)
......
......@@ -180,11 +180,10 @@ class ConnectionConfigController(QObject):
self._logger.debug("Validate changes")
self.model.app.db.commit()
except (NoPeerAvailable, DuniterError) as e:
raise
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_node.set_result(mode)
self.step_key = asyncio.Future()
asyncio.ensure_future(self.process())
return
......@@ -275,3 +274,6 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2])))
self.view.finished.connect(lambda r: future.set_result(r))
self.view.open()
return future
def exec(self):
return self.view.exec()
\ No newline at end of file
......@@ -136,37 +136,6 @@ The process to join back the community later will have to be done again.""")
await QAsyncMessageBox.critical(self, self.tr("UID"),
result[1])
async def refresh_quality_buttons(self):
try:
account_identity = self.app.identity(self.community)
published_uid = await account_identity.published_uid(self.community)
uid_is_revokable = await account_identity.uid_is_revokable(self.community)
if published_uid:
logging.debug("UID Published")
self.action_revoke_uid.setEnabled(uid_is_revokable)
is_member = await account_identity.is_member(self.community)
if is_member:
self.button_membership.setText(self.tr("Renew membership"))
self.button_membership.setEnabled(True)
self.button_certification.setEnabled(True)
self.action_publish_uid.setEnabled(False)
else:
logging.debug("Not a member")
self.button_membership.setText(self.tr("Send membership demand"))
self.button_membership.setEnabled(True)
self.action_publish_uid.setEnabled(False)
if await self.community.get_block(0) is not None:
self.button_certification.setEnabled(False)
else:
logging.debug("UID not published")
self.button_membership.setEnabled(False)
self.button_certification.setEnabled(False)
self.action_publish_uid.setEnabled(True)
except LookupFailureError:
self.button_membership.setEnabled(False)
self.button_certification.setEnabled(False)
self.action_publish_uid.setEnabled(False)
def set_account(self, account):
"""
Set current account
......@@ -196,6 +165,8 @@ The process to join back the community later will have to be done again.""")
def open_create_account_dialog(self):
ConnectionConfigController.create_connection(self, self.model.app).exec()
self.model.app.instanciate_services()
self.model.app.start_coroutines()
def retranslateUi(self, widget):
"""
......
......@@ -252,11 +252,11 @@ class HistoryTableModel(QAbstractTableModel):
except NoPeerAvailable:
deposit = "Could not compute"
identity = self.identities_service.get_identity(transfer.receiver)
identity = self.identities_service.get_identity(transfer.issuer)
if identity:
sender = identity.uid
else:
sender = "pub:{0}".format(transfer.receiver[:5])
sender = "pub:{0}".format(transfer.issuer[:5])
date_ts = transfer.timestamp
txid = transfer.txid
......
......@@ -107,8 +107,7 @@ class IdentitiesService(QObject):
timestamp=certifier_data["cert_time"]["medianTime"],
signature=certifier_data['signature'])
if certifier_data['written']:
cert.written_on = BlockUID(certifier_data['written']['number'],
certifier_data['written']['hash'])
cert.written_on = certifier_data['written']['number']
certifications.append(cert)
# We save connections pubkeys
if identity.pubkey in self._connections_processor.pubkeys():
......@@ -139,8 +138,7 @@ class IdentitiesService(QObject):
timestamp=certified_data["cert_time"]["medianTime"],
signature=certified_data['signature'])
if certified_data['written']:
cert.written_on = BlockUID(certified_data['written']['number'],
certified_data['written']['hash'])
cert.written_on = certified_data['written']['number']
certifications.append(cert)
# We save connections pubkeys
if identity.pubkey in self._connections_processor.pubkeys():
......@@ -185,7 +183,7 @@ class IdentitiesService(QObject):
# we update every written identities known locally
for identity in connections_identities:
if ms.issuer == identity:
identity.membership_written_on = block.blockUID
identity.membership_written_on = block.number
identity.membership_type = "IN"
identity.membership_buid = ms.membership_ts
self._identities_processor.insert_or_update_identity(identity)
......@@ -197,7 +195,7 @@ class IdentitiesService(QObject):
for ms in block.leavers:
# we update every written identities known locally
for identity in connections_identities:
identity.membership_written_on = block.blockUID
identity.membership_written_on = block.number
identity.membership_type = "OUT"
identity.membership_buid = ms.membership_ts
self._identities_processor.insert_or_update_identity(identity)
......
......@@ -84,7 +84,8 @@ class NetworkService(QObject):
Start network nodes crawling
:return:
"""
self._discovery_loop_task = asyncio.ensure_future(self.discover_network())
if not self._discovery_loop_task:
self._discovery_loop_task = asyncio.ensure_future(self.discover_network())
def nodes(self):
"""
......
__author__ = 'inso'
import asyncio
import logging
import sys
import time
import unittest
import aiohttp
from PyQt5.QtCore import QLocale
from sakia.core.net import Network, Node
from sakia.core.net.api.bma.access import BmaAccess
from sakia.gui.graphs.wot_tab import WotTabWidget
from sakia.app import Application
from sakia.core import Account, Community, Wallet
from sakia.core.registry.identities import IdentitiesRegistry
from sakia.gui.password_asker import PasswordAskerDialog
from sakia.tests import QuamashTest
from sakia.tests.mocks.bma import nice_blockchain
class TestWotTab(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
self.mock_nice_blockchain = nice_blockchain.get_mock(self.lp)
self.node = Node(self.mock_nice_blockchain.peer(),
"", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
None, Node.ONLINE,
time.time(), {}, "duniter", "0.14.0", 0, session=aiohttp.ClientSession())
self.network = Network.create(self.node)
self.bma_access = BmaAccess.create(self.network)
self.community = Community("test_currency", self.network, self.bma_access)
self.wallet = Wallet(0, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
"Wallet 1", self.identities_registry)
# Salt/password : "testsakia/testsakia"
# Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ
self.account = Account("testsakia", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
"john", [self.community], [self.wallet], [], 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_empty_wot_tab(self):
wot_tab = WotTabWidget(self.application)
future = asyncio.Future()
def open_widget():
wot_tab.widget.show()
return future
async def async_open_widget():
srv, port, url = await self.mock_nice_blockchain.create_server()
self.addCleanup(srv.close)
await open_widget()
await self.mock_nice_blockchain.close()
def close_dialog():
if wot_tab.widget.isVisible():
wot_tab.widget.close()
future.set_result(True)
async def exec_test():
await asyncio.sleep(1)
self.assertTrue(wot_tab.widget.isVisible())
self.lp.call_soon(close_dialog)
asyncio.ensure_future(exec_test())
self.lp.call_later(15, close_dialog)
self.lp.run_until_complete(async_open_widget())
if __name__ == '__main__':
logging.basicConfig( stream=sys.stderr )
logging.getLogger().setLevel( logging.DEBUG )
unittest.main()
......@@ -11,7 +11,7 @@ def test_add_get_drop_blockchain(meta_repo):
20,
1473108382,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
None))
0))
certification = certifications_repo.get_one(currency="testcurrency",
certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
......@@ -22,7 +22,7 @@ def test_add_get_drop_blockchain(meta_repo):
assert certification.block == 20
assert certification.timestamp == 1473108382
assert certification.signature == "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw=="
assert certification.written_on == BlockUID.empty()
assert certification.written_on == 0
certifications_repo.drop(certification)
certification = certifications_repo.get_one(currency="testcurrency",
certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
......@@ -38,13 +38,13 @@ def test_add_get_multiple_certification(meta_repo):
"FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
20, 1473108382,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
"22-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67"))
22))
certifications_repo.insert(Certification("testcurrency",
"FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
"7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
101, 1473108382,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
"105-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67"))
105))
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]
......@@ -61,14 +61,14 @@ def test_add_update_certification(meta_repo):
20,
1473108382,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
None)
0)
certifications_repo.insert(certification)
certification.written_on = BlockUID(22, "148C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")
certification.written_on = 22
certifications_repo.update(certification)
cert2 = certifications_repo.get_one(currency="testcurrency",
certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
block=20)
assert cert2.written_on == BlockUID(22, "148C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67")
assert cert2.written_on == 22
......@@ -9,14 +9,7 @@ def test_add_get_drop_identity(meta_repo):
"john",
"20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
1473108382,
None,
None,
False,
None,
0,
'',
None))
1473108382))
identity = identities_repo.get_one(currency="testcurrency",
pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
uid="john",
......@@ -33,7 +26,7 @@ def test_add_get_drop_identity(meta_repo):
assert identity.member == False
assert identity.membership_buid == BlockUID.empty()
assert identity.membership_timestamp == 0
assert identity.membership_written_on == BlockUID.empty()
assert identity.membership_written_on == 0
identities_repo.drop(identity)
identity = identities_repo.get_one(currency="testcurrency",
pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
......@@ -43,32 +36,19 @@ def test_add_get_drop_identity(meta_repo):
)
assert identity is None
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))
1473108382))
identities_repo.insert(Identity("testcurrency", "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
"doe",
"101-BAD49448A1AD73C978CEDCB8F137D20A5715EBAA739DAEF76B1E28EE67B2C00C",
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
1455433535,
None,
None,
False,
None,
0,
'',
None))
1455433535))
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]
......@@ -81,14 +61,7 @@ def test_add_update_identity(meta_repo):
"john",
"20-7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
1473108382,
None,
None,
False,
None,
0,
'',
None)
1473108382)
identities_repo.insert(identity)
identity.member = True
identities_repo.update(identity)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment