Пример #1
0
    def test_relayMessageTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=qrl_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.GetOTS = Mock(
                return_value=qrl_pb2.GetOTSResp(next_unused_ots_index=0,
                                                unused_ots_index_found=True))

            resp = service.RelayMessageTxn(qrlwallet_pb2.RelayMessageTxnReq(message=b'Hello QRL!',
                                                                            fee=100000000,
                                                                            master_address=None,
                                                                            signer_address=qaddress,
                                                                            ots_index=0), context=None)

            self.assertEqual(0, resp.code)
            self.assertIsNotNone(resp.tx)
Пример #2
0
    def test_relay_transfer_token_txn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            qaddress = walletd.add_new_address(height=4)
            walletd.encrypt_wallet(self.passphrase)
            walletd.unlock_wallet(self.passphrase)

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses_to = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]
            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))
            tx = walletd.relay_transfer_token_txn(qaddresses_to=qaddresses_to,
                                                  amounts=amounts,
                                                  token_txhash='',
                                                  fee=100000000,
                                                  master_qaddress=None,
                                                  signer_address=qaddress,
                                                  ots_index=0)
            self.assertIsNotNone(tx)

            walletd.lock_wallet()
            with self.assertRaises(ValueError):
                walletd.relay_transfer_token_txn(qaddresses_to=qaddresses_to,
                                                 amounts=amounts,
                                                 token_txhash='',
                                                 fee=100000000,
                                                 master_qaddress=None,
                                                 signer_address=qaddress,
                                                 ots_index=0)
Пример #3
0
    def test_relaySlaveTxnBySlave(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

            resp = service.AddNewAddressWithSlaves(qrlwallet_pb2.AddNewAddressWithSlavesReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            slaves = walletd.get_slave_list(qaddress)

            addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][0].pk)), 0)
            walletd._public_stub.GetAddressState = Mock(
                return_value=qrl_pb2.GetAddressStateResp(state=addr_state.pbdata))

            alice_xmss = get_alice_xmss(4)
            slave_pks = [alice_xmss.pk]
            access_types = [0]

            resp = service.RelaySlaveTxnBySlave(
                qrlwallet_pb2.RelaySlaveTxnBySlaveReq(slave_pks=slave_pks,
                                                      access_types=access_types,
                                                      fee=100000000,
                                                      master_address=qaddress), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #4
0
    def test_relayTokenTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(),
                                         context=None)
            qaddress = resp.address

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelayTokenTxn(qrlwallet_pb2.RelayTokenTxnReq(
                symbol=b'QRL',
                name=b'Quantum Resistant Ledger',
                owner=alice_xmss.qaddress,
                decimals=5,
                addresses=qaddresses,
                amounts=amounts,
                fee=100000000,
                master_address=None,
                signer_address=qaddress,
                ots_index=0),
                                         context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #5
0
    def test_relayTokenTxnBySlave(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

            resp = service.AddNewAddressWithSlaves(qrlwallet_pb2.AddNewAddressWithSlavesReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            slaves = walletd.get_slave_list(qaddress)

            addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][0].pk)), 0)
            walletd._public_stub.GetAddressState = Mock(
                return_value=qrl_pb2.GetAddressStateResp(state=addr_state.pbdata))

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]

            resp = service.RelayTokenTxnBySlave(
                qrlwallet_pb2.RelayTokenTxnBySlaveReq(symbol=b'QRL',
                                                      name=b'Quantum Resistant Ledger',
                                                      owner=alice_xmss.qaddress,
                                                      decimals=5,
                                                      addresses=qaddresses,
                                                      amounts=amounts,
                                                      fee=100000000,
                                                      master_address=qaddress), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #6
0
    def PushTransaction(self, request: qrl_pb2.PushTransactionReq,
                        context) -> qrl_pb2.PushTransactionResp:
        logger.debug("[PublicAPI] PushTransaction")
        answer = qrl_pb2.PushTransactionResp()

        try:
            tx = Transaction.from_pbdata(request.transaction_signed)
            tx.update_txhash()

            # FIXME: Full validation takes too much time. At least verify there is a signature
            # the validation happens later in the tx pool
            if len(tx.signature) > 1000:
                self.qrlnode.submit_send_tx(tx)
                answer.error_code = qrl_pb2.PushTransactionResp.SUBMITTED
                answer.tx_hash = tx.txhash
            else:
                answer.error_description = 'Signature too short'
                answer.error_code = qrl_pb2.PushTransactionResp.VALIDATION_FAILED

        except Exception as e:
            error_str = traceback.format_exception(None, e, e.__traceback__)
            answer.error_description = str(''.join(error_str))
            answer.error_code = qrl_pb2.PushTransactionResp.ERROR

        return answer
Пример #7
0
    def test_relaySlaveTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=qrl_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.IsSlave = Mock(
                return_value=qrl_pb2.IsSlaveResp(result=True))
            walletd._public_stub.GetOTS = Mock(
                return_value=qrl_pb2.GetOTSResp(next_unused_ots_index=0,
                                                unused_ots_index_found=True))

            alice_xmss = get_alice_xmss(4)
            slave_pks = [alice_xmss.pk]
            access_types = [0]

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelaySlaveTxn(qrlwallet_pb2.RelaySlaveTxnReq(slave_pks=slave_pks,
                                                                        access_types=access_types,
                                                                        fee=100000000,
                                                                        master_address=None,
                                                                        signer_address=qaddress,
                                                                        ots_index=0), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #8
0
    def test_relayTransferTokenTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(),
                                         context=None)
            qaddress = resp.address

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses_to = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelayTransferTokenTxn(
                qrlwallet_pb2.RelayTransferTokenTxnReq(
                    addresses_to=qaddresses_to,
                    amounts=amounts,
                    token_txhash='',
                    fee=100000000,
                    master_address=None,
                    signer_address=qaddress,
                    ots_index=0),
                context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #9
0
    def test_relay_slave_txn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            qaddress = walletd.add_new_address(height=4)
            walletd.encrypt_wallet(self.passphrase)
            walletd.unlock_wallet(self.passphrase)

            alice_xmss = get_alice_xmss(4)
            slave_pks = [alice_xmss.pk]
            access_types = [0]
            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))
            tx = walletd.relay_slave_txn(slave_pks=slave_pks,
                                         access_types=access_types,
                                         fee=100000000,
                                         master_qaddress=None,
                                         signer_address=qaddress,
                                         ots_index=0)
            self.assertIsNotNone(tx)

            walletd.lock_wallet()
            with self.assertRaises(ValueError):
                walletd.relay_slave_txn(slave_pks=slave_pks,
                                        access_types=access_types,
                                        fee=100000000,
                                        master_qaddress=None,
                                        signer_address=qaddress,
                                        ots_index=0)
Пример #10
0
    def test_relaySlaveTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(),
                                         context=None)
            qaddress = resp.address

            alice_xmss = get_alice_xmss(4)
            slave_pks = [alice_xmss.pk]
            access_types = [0]

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelaySlaveTxn(qrlwallet_pb2.RelaySlaveTxnReq(
                slave_pks=slave_pks,
                access_types=access_types,
                fee=100000000,
                master_address=None,
                signer_address=qaddress,
                ots_index=0),
                                         context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #11
0
    def PushTransaction(self, request: qrl_pb2.PushTransactionReq, context) -> qrl_pb2.PushTransactionResp:
        logger.debug("[PublicAPI] PushTransaction")
        tx = Transaction.from_pbdata(request.transaction_signed)
        submitted = self.qrlnode.submit_send_tx(tx)

        # FIXME: Improve response type
        # Prepare response
        answer = qrl_pb2.PushTransactionResp()
        answer.some_response = str(submitted)
        return answer
Пример #12
0
    def test_addNewAddressWithSlaves(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)
            resp = service.AddNewAddressWithSlaves(qrlwallet_pb2.AddNewAddressWithSlavesReq(), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.address[0], 'Q')
Пример #13
0
 def test_relay_message_txn(self):
     with set_qrl_dir("wallet_ver1"):
         walletd = WalletD()
         qaddress = walletd.add_new_address(height=4)
         walletd._public_stub.PushTransaction = Mock(
             return_value=qrl_pb2.PushTransactionResp(
                 error_code=qrl_pb2.PushTransactionResp.SUBMITTED))
         tx = walletd.relay_message_txn(message='Hello QRL!',
                                        fee=100000000,
                                        master_qaddress=None,
                                        signer_address=qaddress,
                                        ots_index=0)
         self.assertIsNotNone(tx)
Пример #14
0
    def test_push_transaction(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            alice_xmss = get_alice_xmss()
            bob_xmss = get_bob_xmss()
            tx = TransferTransaction.create(addrs_to=[bob_xmss.address],
                                            amounts=[1],
                                            fee=1,
                                            xmss_pk=alice_xmss.pk)

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            walletd._push_transaction(tx, alice_xmss)

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.UNKNOWN))

            with self.assertRaises(Exception):
                walletd._push_transaction(tx, alice_xmss)
Пример #15
0
    def PushEphemeralMessage(self, request: qrl_pb2.PushEphemeralMessageReq,
                             context) -> qrl_pb2.PushTransactionResp:
        logger.debug("[PublicAPI] PushEphemeralMessageReq")
        submitted = False

        if config.user.accept_ephemeral:
            encrypted_ephemeral_message = EncryptedEphemeralMessage(
                request.ephemeral_message)
            submitted = self.qrlnode.broadcast_ephemeral_message(
                encrypted_ephemeral_message)

        answer = qrl_pb2.PushTransactionResp()
        answer.some_response = str(submitted)
        return answer
Пример #16
0
    def PushEphemeralMessage(self, request: qrl_pb2.PushEphemeralMessageReq,
                             context) -> qrl_pb2.PushTransactionResp:
        logger.debug("[PublicAPI] PushEphemeralMessageReq")
        submitted = False

        if config.user.accept_ephemeral:
            encrypted_ephemeral_message = EncryptedEphemeralMessage(
                request.ephemeral_message)
            submitted = self.qrlnode.broadcast_ephemeral_message(
                encrypted_ephemeral_message)

        answer = qrl_pb2.PushTransactionResp()
        answer.error_code = qrl_pb2.PushTransactionResp.ERROR
        if submitted:
            answer.error_code = qrl_pb2.PushTransactionResp.SUBMITTED

        return answer
Пример #17
0
 def test_relay_token_txn(self):
     with set_qrl_dir("wallet_ver1"):
         walletd = WalletD()
         qaddress = walletd.add_new_address(height=4)
         alice_xmss = get_alice_xmss(4)
         bob_xmss = get_bob_xmss(4)
         qaddresses = [alice_xmss.qaddress, bob_xmss.qaddress]
         amounts = [1000000000, 1000000000]
         walletd._public_stub.PushTransaction = Mock(
             return_value=qrl_pb2.PushTransactionResp(
                 error_code=qrl_pb2.PushTransactionResp.SUBMITTED))
         tx = walletd.relay_token_txn(symbol='QRL',
                                      name='Quantum Resistant Ledger',
                                      owner_qaddress=alice_xmss.qaddress,
                                      decimals=5,
                                      qaddresses=qaddresses,
                                      amounts=amounts,
                                      fee=100000000,
                                      master_qaddress=None,
                                      signer_address=qaddress,
                                      ots_index=0)
         self.assertIsNotNone(tx)
Пример #18
0
    def test_relayMessageTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(),
                                         context=None)
            qaddress = resp.address

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(
                    error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelayMessageTxn(qrlwallet_pb2.RelayMessageTxnReq(
                message=b'Hello QRL!',
                fee=100000000,
                master_address=None,
                signer_address=qaddress,
                ots_index=0),
                                           context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
Пример #19
0
    def test_relayTokenTxn(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(qrlwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=qrl_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.IsSlave = Mock(
                return_value=qrl_pb2.IsSlaveResp(result=True))
            walletd._public_stub.GetOTS = Mock(
                return_value=qrl_pb2.GetOTSResp(next_unused_ots_index=0,
                                                unused_ots_index_found=True))

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelayTokenTxn(qrlwallet_pb2.RelayTokenTxnReq(symbol=b'QRL',
                                                                        name=b'Quantum Resistant Ledger',
                                                                        owner=alice_xmss.qaddress,
                                                                        decimals=5,
                                                                        addresses=qaddresses,
                                                                        amounts=amounts,
                                                                        fee=100000000,
                                                                        master_address=None,
                                                                        signer_address=qaddress,
                                                                        ots_index=0), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)