Ejemplo n.º 1
0
    def test_unlockWallet(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(len(resp.addresses), 1)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.LockWallet(xrdwallet_pb2.LockWalletReq(), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase="wrong"), context=None)
            self.assertEqual(resp.code, 1)
Ejemplo n.º 2
0
    def test_relaySlaveTxn(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.IsSlave = Mock(
                return_value=xrd_pb2.IsSlaveResp(result=True))
            walletd._public_stub.GetOTS = Mock(
                return_value=xrd_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=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelaySlaveTxn(xrdwallet_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)
Ejemplo n.º 3
0
 def test_addNewAddress(self):
     with set_xrd_dir("wallet_ver1"):
         walletd = WalletD()
         service = WalletAPIService(walletd)
         resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
         self.assertEqual(resp.code, 0)
         self.assertEqual(resp.address[0], 'Q')
Ejemplo n.º 4
0
    def test_relayMessageTxn(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

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

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

            self.assertEqual(0, resp.code)
            self.assertIsNotNone(resp.tx)
Ejemplo n.º 5
0
    def test_listAddresses(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

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

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.addresses[0], address)
Ejemplo n.º 6
0
    def test_encryptWallet(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 1)
Ejemplo n.º 7
0
    def test_removeAddress(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

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

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(len(resp.addresses), 1)

            resp = service.RemoveAddress(xrdwallet_pb2.RemoveAddressReq(address=address), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(len(resp.addresses), 0)
Ejemplo n.º 8
0
    def test_changePassphrase(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(len(resp.addresses), 1)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.LockWallet(xrdwallet_pb2.LockWalletReq(), context=None)
            self.assertEqual(resp.code, 0)

            new_passphrase = "Hello World"
            resp = service.ChangePassphrase(
                xrdwallet_pb2.ChangePassphraseReq(oldPassphrase=self.passphrase,
                                                  newPassphrase=new_passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=new_passphrase), context=None)
            self.assertEqual(resp.code, 0)
Ejemplo n.º 9
0
    def test_relayTokenTxn(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.IsSlave = Mock(
                return_value=xrd_pb2.IsSlaveResp(result=True))
            walletd._public_stub.GetOTS = Mock(
                return_value=xrd_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=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            resp = service.RelayTokenTxn(xrdwallet_pb2.RelayTokenTxnReq(symbol=b'xrd',
                                                                        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)