def test_unlockWallet(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

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

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

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

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

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

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

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

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

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

            resp = service.UnlockWallet(qrlwallet_pb2.UnlockWalletReq(passphrase="wrong"), context=None)
            self.assertEqual(resp.code, 1)
Exemple #2
0
    def test_changePassphrase(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

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

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

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

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

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

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

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

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

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

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