Beispiel #1
0
    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.endpoint = BMAEndpoint("", "127.0.0.1", "", 50005)
        self.node = Node("test_currency", [self.endpoint],
                         "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
                         nice_blockchain.bma_blockchain_current, Node.ONLINE,
                         time.time(), {}, "duniter", "0.14.0", 0)
        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)
        self.wallet.init_cache(self.application, self.community)

        # Salt/password : "******"
        # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ
        self.account = Account("testsakia", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                               "john", [self.community], [self.wallet], [], self.identities_registry)
Beispiel #2
0
    def test_load_save_wallet(self):
        wallet = Wallet(0, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                             "Wallet 1", self.identities_registry)

        json_data = wallet.jsonify()
        wallet_from_json = Wallet.load(json_data, self.identities_registry)
        self.assertEqual(wallet.walletid, wallet_from_json.walletid)
        self.assertEqual(wallet.pubkey, wallet_from_json.pubkey)
        self.assertEqual(wallet.name, wallet_from_json.name)
        self.assertEqual(wallet._identities_registry, wallet_from_json._identities_registry)
Beispiel #3
0
    def test_load_save_wallet(self):
        wallet = Wallet(0, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                        "Wallet 1", self.identities_registry)

        json_data = wallet.jsonify()
        wallet_from_json = Wallet.load(json_data, self.identities_registry)
        self.assertEqual(wallet.walletid, wallet_from_json.walletid)
        self.assertEqual(wallet.pubkey, wallet_from_json.pubkey)
        self.assertEqual(wallet.name, wallet_from_json.name)
        self.assertEqual(wallet._identities_registry,
                         wallet_from_json._identities_registry)
Beispiel #4
0
    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.endpoint = BMAEndpoint("", "127.0.0.1", "", 50000)
        self.node = Node("test_currency", [self.endpoint],
                         "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
                         None, Node.ONLINE,
                         time.time(), {}, "ucoin", "0.14.0", 0)
        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 : "******"
        # 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 = "******"
        self.password_asker.remember = True
class TestTxHistory(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.endpoint = BMAEndpoint(PyBMAEndpoint("", "127.0.0.1", "", 50000))
        self.node = Node("test_currency", [self.endpoint],
                         "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
                         nice_blockchain.bma_blockchain_current, Node.ONLINE,
                         time.time(), {}, "ucoin", "0.14.0", 0)
        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)
        self.wallet.init_cache(self.application, self.community)

        # Salt/password : "******"
        # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ
        self.account = Account("testsakia", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                               "john", [self.community], [self.wallet], [], self.identities_registry)

    def tearDown(self):
        self.tearDownQuamash()

    # this test fails with old algorithm
    def notest_txhistory_reload(self):
        mock = nice_blockchain.get_mock()
        time.sleep(2)
        logging.debug(mock.pretend_url)

        received_list = []
        self.lp.run_until_complete(self.wallet.caches[self.community.currency].
                                   refresh(self.community, received_list))
        self.assertEquals(len(received_list), 2)
        received_value = sum([r.metadata['amount'] for r in received_list])
        self.assertEqual(received_value, 60)
        self.assertEqual(len(self.wallet.dividends(self.community)), 2)
        dividends_value = sum([ud['amount'] for ud in self.wallet.dividends(self.community)])
        self.assertEqual(dividends_value, 15)
        mock.delete_mock()
Beispiel #6
0
class TestTxHistory(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.endpoint = BMAEndpoint("", "127.0.0.1", "", 50005)
        self.node = Node("test_currency", [self.endpoint],
                         "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
                         nice_blockchain.bma_blockchain_current, Node.ONLINE,
                         time.time(), {}, "duniter", "0.14.0", 0)
        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)
        self.wallet.init_cache(self.application, self.community)

        # Salt/password : "******"
        # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ
        self.account = Account("testsakia", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                               "john", [self.community], [self.wallet], [], self.identities_registry)

    def tearDown(self):
        self.tearDownQuamash()

    # this test fails with old algorithm
    def notest_txhistory_reload(self):
        mock = nice_blockchain.get_mock()
        time.sleep(2)
        logging.debug(mock.pretend_url)

        received_list = []
        self.lp.run_until_complete(self.wallet.caches[self.community.currency].
                                   refresh(self.community, received_list))
        self.assertEquals(len(received_list), 2)
        received_value = sum([r.metadata['amount'] for r in received_list])
        self.assertEqual(received_value, 60)
        self.assertEqual(len(self.wallet.dividends(self.community)), 2)
        dividends_value = sum([ud['amount'] for ud in self.wallet.dividends(self.community)])
        self.assertEqual(dividends_value, 15)
        mock.delete_mock()
Beispiel #7
0
    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_new_community = init_new_community.get_mock(self.lp)

        self.endpoint = BMAEndpoint("", "127.0.0.1", "", 50010)
        self.node = Node(self.mock_new_community.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 : "******"
        # Pubkey : 7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ
        self.account = Account("testsakia",
                               "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                               "john", [self.community], [self.wallet], [],
                               self.identities_registry)
        self.account.notifications['warning_certifying_first_time'] = False
        self.password_asker = PasswordAskerDialog(self.account)
        self.password_asker.password = "******"
        self.password_asker.remember = True
Beispiel #8
0
class TestTransferDialog(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.endpoint = BMAEndpoint("", "127.0.0.1", "", 50000)
        self.node = Node("test_currency", [self.endpoint],
                         "", "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
                         None, Node.ONLINE,
                         time.time(), {}, "ucoin", "0.14.0", 0)
        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 : "******"
        # 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 = "******"
        self.password_asker.remember = True

    def tearDown(self):
        self.tearDownQuamash()

    def test_transfer_nice_community(self):
        mock = nice_blockchain.get_mock()
        time.sleep(2)
        logging.debug(mock.pretend_url)
        API.reverse_url = pretender_reversed(mock.pretend_url)
        transfer_dialog = TransferMoneyDialog(self.application,
                                              self.account,
                                              self.password_asker,
                                              self.community,
                                              None)
        self.account.wallets[0].init_cache(self.application, self.community)

        @asyncio.coroutine
        def open_dialog(certification_dialog):
            result = yield from certification_dialog.async_exec()
            self.assertEqual(result, QDialog.Accepted)

        def close_dialog():
            if transfer_dialog.isVisible():
                transfer_dialog.close()

        @asyncio.coroutine
        def exec_test():
            yield from asyncio.sleep(1)
            self.account.wallets[0].caches[self.community.currency].available_sources = yield from self.wallet.sources(self.community)
            QTest.mouseClick(transfer_dialog.radio_pubkey, Qt.LeftButton)
            QTest.keyClicks(transfer_dialog.edit_pubkey, "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn")
            transfer_dialog.spinbox_amount.setValue(10)
            QTest.mouseClick(transfer_dialog.button_box.button(QDialogButtonBox.Ok), Qt.LeftButton)
            yield from asyncio.sleep(1)
            topWidgets = QApplication.topLevelWidgets()
            for w in topWidgets:
                if type(w) is QMessageBox:
                    QTest.keyClick(w, Qt.Key_Enter)

        self.lp.call_later(15, close_dialog)
        asyncio.async(exec_test())
        self.lp.run_until_complete(open_dialog(transfer_dialog))
        mock.delete_mock()
Beispiel #9
0
    def test_prepare_tx_base_0(self):
        community = MagicMock("sakia.core.Community")
        community.currency = "test_currency"
        cache = MagicMock("sakia.core.txhistory.TxHistory")
        cache.available_sources = [{
            "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
            "type": "D",
            "noffset": 2,
            "identifier": "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365",
            "amount": 15,
            "base": 0
        },
            {
                "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                "type": "D",
                "noffset": 4,
                "identifier": "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5",
                "amount": 85,
                "base": 0
            },
            {
                "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
                "type": "T",
                "noffset": 4,
                "identifier": "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
                "amount": 11,
                "base": 1
            }]
        wallet = Wallet(0, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                        "Wallet 1", self.identities_registry)
        wallet.caches["test_currency"] = cache
        tx = wallet.prepare_tx("FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
                               99, "", community)
        self.assertEqual(len(tx.issuers), 1)
        self.assertEqual(tx.issuers[0], "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ")
        self.assertEqual(len(tx.inputs), 2)
        self.assertEqual(tx.inputs[0].origin_id, "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365")
        self.assertEqual(tx.inputs[0].source, "D")
        self.assertEqual(tx.inputs[0].index, 2)
        self.assertEqual(tx.inputs[1].origin_id, "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5")
        self.assertEqual(tx.inputs[1].source, "D")
        self.assertEqual(tx.inputs[1].index, 4)
        self.assertEqual(len(tx.outputs), 2)
        self.assertEqual(tx.outputs[0].amount, 99)
        self.assertEqual(tx.outputs[0].base, 0)
        self.assertEqual(pypeg2.compose(tx.outputs[0].conditions, output.Condition),
                         "SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)")
        self.assertEqual(tx.outputs[1].amount, 1)
        self.assertEqual(tx.outputs[1].base, 0)
        self.assertEqual(pypeg2.compose(tx.outputs[1].conditions, output.Condition),
                         "SIG(7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ)")
        self.assertEqual(len(tx.unlocks), 2)
        self.assertEqual(tx.unlocks[0].index, 0)
        self.assertEqual(tx.unlocks[0].parameters[0].index, 0)
        self.assertEqual(tx.unlocks[1].index, 1)
        self.assertEqual(tx.unlocks[0].parameters[0].index, 0)
        self.assertEqual(tx.raw(), """Version: 2
Type: Transaction
Currency: test_currency
Locktime: 0
Issuers:
7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ
Inputs:
D:FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365:2
D:A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5:4
Unlocks:
0:SIG(0)
1:SIG(0)
Outputs:
99:0:SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)
1:0:SIG(7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ)
Comment:""" + " \n")
Beispiel #10
0
 def test_prepare_tx_base_0(self):
     community = MagicMock("sakia.core.Community")
     community.currency = "test_currency"
     cache = MagicMock("sakia.core.txhistory.TxHistory")
     cache.available_sources = [{
         "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
         "type": "D",
         "noffset": 2,
         "identifier":
         "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365",
         "amount": 15,
         "base": 0
     }, {
         "pubkey": "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
         "type": "D",
         "noffset": 4,
         "identifier":
         "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5",
         "amount": 85,
         "base": 0
     }, {
         "pubkey": "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
         "type": "T",
         "noffset": 4,
         "identifier":
         "7518C700E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
         "amount": 11,
         "base": 1
     }]
     wallet = Wallet(0, "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
                     "Wallet 1", self.identities_registry)
     wallet.caches["test_currency"] = cache
     tx = wallet.prepare_tx(
         "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
         BlockUID(32, "000005E0F228038E4DDD4F6CA4ACB01EC88FBAF8"), 99, "",
         community)
     self.assertEqual(tx.version, 3)
     self.assertEqual(tx.blockstamp.number, 32)
     self.assertEqual(tx.blockstamp.sha_hash,
                      "000005E0F228038E4DDD4F6CA4ACB01EC88FBAF8")
     self.assertEqual(len(tx.issuers), 1)
     self.assertEqual(tx.issuers[0],
                      "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ")
     self.assertEqual(len(tx.inputs), 2)
     self.assertEqual(
         tx.inputs[0].origin_id,
         "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365")
     self.assertEqual(tx.inputs[0].source, "D")
     self.assertEqual(tx.inputs[0].index, 2)
     self.assertEqual(
         tx.inputs[1].origin_id,
         "A0AC57E2E4B24D66F2D25E66D8501D8E881D9E6453D1789ED753D7D426537ED5")
     self.assertEqual(tx.inputs[1].source, "D")
     self.assertEqual(tx.inputs[1].index, 4)
     self.assertEqual(len(tx.outputs), 2)
     self.assertEqual(tx.outputs[0].amount, 99)
     self.assertEqual(tx.outputs[0].base, 0)
     self.assertEqual(
         pypeg2.compose(tx.outputs[0].conditions, output.Condition),
         "SIG(FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn)")
     self.assertEqual(tx.outputs[1].amount, 1)
     self.assertEqual(tx.outputs[1].base, 0)
     self.assertEqual(
         pypeg2.compose(tx.outputs[1].conditions, output.Condition),
         "SIG(7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ)")
     self.assertEqual(len(tx.unlocks), 2)
     self.assertEqual(tx.unlocks[0].index, 0)
     self.assertEqual(tx.unlocks[0].parameters[0].index, 0)
     self.assertEqual(tx.unlocks[1].index, 1)
     self.assertEqual(tx.unlocks[0].parameters[0].index, 0)