Beispiel #1
0
 def test_deleted_account_dir(self):
     """
     The deleted_account_dir() helper method should be working
     with and without trailing slash.
     """
     expected_deleted_keystore_dir = '/tmp/keystore-deleted'
     keystore_dirs = [
         # without trailing slash
         '/tmp/keystore',
         # with one trailing slash
         '/tmp/keystore/',
         # with two trailing slashes
         '/tmp/keystore//',
     ]
     for keystore_dir in keystore_dirs:
         self.assertEqual(PyWalib.deleted_account_dir(keystore_dir),
                          expected_deleted_keystore_dir)
Beispiel #2
0
 def test_delete_account(self):
     """
     Creates a new account and delete it.
     Then verify we can load the account from the backup/trash location.
     """
     pywalib = self.pywalib
     account = self.helper_new_account()
     address = account.address
     self.assertEqual(len(pywalib.get_account_list()), 1)
     # deletes the account and verifies it's not loaded anymore
     pywalib.delete_account(account)
     self.assertEqual(len(pywalib.get_account_list()), 0)
     # even recreating the PyWalib object
     pywalib = PyWalib(self.keystore_dir)
     self.assertEqual(len(pywalib.get_account_list()), 0)
     # tries to reload it from the backup/trash location
     deleted_keystore_dir = PyWalib.deleted_account_dir(self.keystore_dir)
     pywalib = PyWalib(deleted_keystore_dir)
     self.assertEqual(len(pywalib.get_account_list()), 1)
     self.assertEqual(pywalib.get_account_list()[0].address, address)
Beispiel #3
0
 def test_delete_account_already_exists(self):
     """
     If the destination (backup/trash) directory where the account is moved
     already exists, it should be handled gracefully.
     This could happens if the account gets deleted, then reimported and
     deleted again, refs:
     https://github.com/AndreMiras/PyWallet/issues/88
     """
     pywalib = self.pywalib
     account = self.helper_new_account()
     # creates a file in the backup/trash folder that would conflict
     # with the deleted account
     deleted_keystore_dir = PyWalib.deleted_account_dir(self.keystore_dir)
     os.makedirs(deleted_keystore_dir)
     account_filename = os.path.basename(account.path)
     deleted_account_path = os.path.join(deleted_keystore_dir,
                                         account_filename)
     # create that file
     open(deleted_account_path, 'a').close()
     # then deletes the account and verifies it worked
     self.assertEqual(len(pywalib.get_account_list()), 1)
     pywalib.delete_account(account)
     self.assertEqual(len(pywalib.get_account_list()), 0)