From 47aff6c79d8bf3bb89fb8b71b59c7503c230a711 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Wed, 9 Sep 2015 19:01:19 +0200 Subject: [PATCH] Fix bug with no wallet initialized --- src/cutecoin/core/account.py | 29 ++++++++----------- src/cutecoin/core/wallet.py | 2 +- src/cutecoin/gui/process_cfg_account.py | 3 +- .../tests/certification/test_certification.py | 1 + .../identities_tab/test_identities_table.py | 1 + .../process_cfg_account/test_add_account.py | 1 + 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index ac3c6ac9..5786b85e 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -196,6 +196,18 @@ class Account(QObject): def set_display_referential(self, index): self._current_ref = index + def set_scrypt_infos(self, salt, password): + """ + Change the size of the wallet pool + :param int size: The new size of the wallet pool + :param str password: The password of the account, same for all wallets + """ + self.salt = salt + self.pubkey = SigningKey(self.salt, password).pubkey + wallet = Wallet.create(0, self.salt, password, + "Wallet", self._identities_registry) + self.wallets.append(wallet) + def identity(self, community): """ Get the account identity in the specified community @@ -212,23 +224,6 @@ class Account(QObject): def current_ref(self): return money.Referentials[self._current_ref] - def set_walletpool_size(self, size, password): - """ - Change the size of the wallet pool - - :param int size: The new size of the wallet pool - :param str password: The password of the account, same for all wallets - """ - logging.debug("Defining wallet pool size") - if len(self.wallets) < size: - for i in range(len(self.wallets), size): - wallet = Wallet.create(i, self.salt, password, - "Wallet {0}".format(i), self._identities_registry) - self.wallets.append(wallet) - else: - self.wallets = self.wallets[:size] - self.wallets_changed.emit() - def transfers(self, community): """ Get all transfers done in a community by all the wallets diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index f7ea800b..0b3a2c8b 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -60,7 +60,7 @@ class Wallet(QObject): if walletid == 0: key = SigningKey(salt, password) else: - key = SigningKey("{0}{1}".format(salt, walletid), password) + key = SigningKey(b"{0}{1}".format(salt, walletid), password) return cls(walletid, key.pubkey, name, identities_registry) @classmethod diff --git a/src/cutecoin/gui/process_cfg_account.py b/src/cutecoin/gui/process_cfg_account.py index 9a5a6ec3..d9a63e4d 100644 --- a/src/cutecoin/gui/process_cfg_account.py +++ b/src/cutecoin/gui/process_cfg_account.py @@ -94,8 +94,7 @@ class StepPageKey(Step): def process_next(self): salt = self.config_dialog.edit_salt.text() password = self.config_dialog.edit_password.text() - self.config_dialog.account.salt = salt - self.config_dialog.account.pubkey = SigningKey(salt, password).pubkey + self.config_dialog.account.set_scrypt_infos(salt, password) self.config_dialog.password_asker = PasswordAskerDialog(self.config_dialog.account) model = CommunitiesListModel(self.config_dialog.account) self.config_dialog.list_communities.setModel(model) diff --git a/src/cutecoin/tests/certification/test_certification.py b/src/cutecoin/tests/certification/test_certification.py index 33c81b87..71c634b0 100644 --- a/src/cutecoin/tests/certification/test_certification.py +++ b/src/cutecoin/tests/certification/test_certification.py @@ -90,6 +90,7 @@ class TestCertificationDialog(unittest.TestCase): self.lp.call_later(15, close_dialog) asyncio.async(exec_test()) self.lp.run_until_complete(open_dialog(certification_dialog)) + mock.delete_mock() if __name__ == '__main__': diff --git a/src/cutecoin/tests/identities_tab/test_identities_table.py b/src/cutecoin/tests/identities_tab/test_identities_table.py index 9bafb74a..fc1c093b 100644 --- a/src/cutecoin/tests/identities_tab/test_identities_table.py +++ b/src/cutecoin/tests/identities_tab/test_identities_table.py @@ -105,6 +105,7 @@ class TestIdentitiesTable(unittest.TestCase): asyncio.async(exec_test()) self.lp.run_until_complete(async_open_widget()) + mock.delete_mock() if __name__ == '__main__': logging.basicConfig( stream=sys.stderr ) diff --git a/src/cutecoin/tests/process_cfg_account/test_add_account.py b/src/cutecoin/tests/process_cfg_account/test_add_account.py index cc8f6593..cd6808c1 100644 --- a/src/cutecoin/tests/process_cfg_account/test_add_account.py +++ b/src/cutecoin/tests/process_cfg_account/test_add_account.py @@ -94,6 +94,7 @@ class ProcessAddCommunity(unittest.TestCase): self.assertEqual(len(self.application.accounts), 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) self.lp.call_later(10, close_dialog) asyncio.async(exec_test()) -- GitLab