Esempio n. 1
0
    def test_write_dictionnary_to_file(self):
        storage = WalletStorage(self.wallet_path)

        some_dict = {"a": "b", "c": "d"}

        for key, value in some_dict.items():
            storage.put(key, value)
        storage.write()

        contents = ""
        with open(self.wallet_path, "r") as f:
            contents = f.read()
        self.assertEqual(some_dict, json.loads(contents))
Esempio n. 2
0
    def test_write_dictionary_to_file(self):
        storage = WalletStorage(self.wallet_path)

        some_dict = {"a": "b", "c": "d"}

        for key, value in some_dict.items():
            storage.put(key, value)
        storage.write()

        contents = ""
        with open(self.wallet_path, "r") as f:
            contents = f.read()
        self.assertEqual(some_dict, json.loads(contents))
Esempio n. 3
0
class TestNewWallet(WalletTestCase):
    seed_text = "travel nowhere air position hill peace suffer parent beautiful rise blood power home crumble teach"
    xprv_text = "xprv9s21ZrQH143K2RNUGjxcwJXKSzQeSoCp1GwLFBF8YVQ92TJUX7LXvwoCLVVyrHcPAbAaGQwnFydd8hftzAuTMRCzHue31ftg9wiGkkoVAaT"
    password = "******"

    first_account_name = "account1"

    import_private_key = "L52XzL2cMkHxqxBXRyEpnPQZGUs3uKiL3R11XbAdHigRzDozKZeW"
    import_key_address = "15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma"

    def setUp(self):
        super(TestNewWallet, self).setUp()
        self.storage = WalletStorage(self.wallet_path)
        self.wallet = NewWallet(self.storage)
        # This cannot be constructed by lbryum at random, it should be safe
        # from eventual collisions.
        self.wallet.add_seed(self.seed_text, self.password)
        self.wallet.create_master_keys(self.password)
        self.wallet.create_main_account()

    def test_wallet_with_seed_is_not_watching_only(self):
        self.assertFalse(self.wallet.is_watching_only())

    def test_wallet_without_seed_is_watching_only(self):
        # We need a new storage , since the default storage was already seeded
        # in setUp()
        new_dir = tempfile.mkdtemp()
        storage = WalletStorage(os.path.join(new_dir, "somewallet"))
        wallet = NewWallet(storage)
        self.assertTrue(wallet.is_watching_only())
        shutil.rmtree(new_dir)  # Don't leave useless stuff in /tmp

    def test_new_wallet_is_deterministic(self):
        self.assertTrue(self.wallet.is_deterministic())

    def test_get_seed_returns_correct_seed(self):
        self.assertEqual(self.wallet.get_seed(self.password), self.seed_text)

    def test_update_password(self):
        new_password = "******"
        self.wallet.update_password(self.password, new_password)
        self.wallet.get_seed(new_password)

    def test_encryption(self):
        self.storage.write()
        wallet_data = json.load(open(self.wallet_path, "r"))
        self.assertTrue(wallet_data['use_encryption'])

        # retrieve the encrypted values from wallet storage
        enc_xprv_key = wallet_data['master_private_keys']['x/']
        enc_seed = wallet_data['seed']

        # the xprv key and seed should not be in plain text in the wallet storage
        self.assertNotEqual(self.seed_text, enc_seed)
        self.assertNotEqual(self.xprv_text, enc_xprv_key)

        # decoding the encrypted xprv key and seed should return the original values
        self.assertEqual(self.seed_text, pw_decode(enc_seed, self.password))
        self.assertEqual(self.xprv_text, pw_decode(enc_xprv_key, self.password))
        self.assertEqual(self.xprv_text, self.wallet.get_master_private_key('x/', self.password))

    def test_check_password(self):
        # no errors should occur if the password is valid
        self.wallet.check_password(self.password)

    def test_check_invalid_password(self):
        with self.assertRaises(InvalidPassword):
            self.wallet.check_password('invalid')
Esempio n. 4
0
class TestNewWallet(WalletTestCase):
    seed_text = "travel nowhere air position hill peace suffer parent beautiful rise blood power home crumble teach"
    xprv_text = "xprv9s21ZrQH143K2RNUGjxcwJXKSzQeSoCp1GwLFBF8YVQ92TJUX7LXvwoCLVVyrHcPAbAaGQwnFydd8hftzAuTMRCzHue31ftg9wiGkkoVAaT"
    password = "******"

    first_account_name = "account1"

    import_private_key = "L52XzL2cMkHxqxBXRyEpnPQZGUs3uKiL3R11XbAdHigRzDozKZeW"
    import_key_address = "15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma"

    def setUp(self):
        super(TestNewWallet, self).setUp()
        self.storage = WalletStorage(self.wallet_path)
        self.wallet = NewWallet(self.storage)
        # This cannot be constructed by lbryum at random, it should be safe
        # from eventual collisions.
        self.wallet.add_seed(self.seed_text, self.password)
        self.wallet.create_master_keys(self.password)
        self.wallet.create_main_account()

    def test_wallet_with_seed_is_not_watching_only(self):
        self.assertFalse(self.wallet.is_watching_only())

    def test_wallet_without_seed_is_watching_only(self):
        # We need a new storage , since the default storage was already seeded
        # in setUp()
        new_dir = tempfile.mkdtemp()
        storage = WalletStorage(os.path.join(new_dir, "somewallet"))
        wallet = NewWallet(storage)
        self.assertTrue(wallet.is_watching_only())
        shutil.rmtree(new_dir)  # Don't leave useless stuff in /tmp

    def test_new_wallet_is_deterministic(self):
        self.assertTrue(self.wallet.is_deterministic())

    def test_get_seed_returns_correct_seed(self):
        self.assertEqual(self.wallet.get_seed(self.password), self.seed_text)

    def test_update_password(self):
        new_password = "******"
        self.wallet.update_password(self.password, new_password)
        self.wallet.get_seed(new_password)

    def test_encryption(self):
        self.storage.write()
        wallet_data = json.load(open(self.wallet_path, "r"))
        self.assertTrue(wallet_data['use_encryption'])

        # retrieve the encrypted values from wallet storage
        enc_xprv_key = wallet_data['master_private_keys']['x/']
        enc_seed = wallet_data['seed']

        # the xprv key and seed should not be in plain text in the wallet storage
        self.assertNotEqual(self.seed_text, enc_seed)
        self.assertNotEqual(self.xprv_text, enc_xprv_key)

        # decoding the encrypted xprv key and seed should return the original values
        self.assertEqual(self.seed_text, pw_decode(enc_seed, self.password))
        self.assertEqual(self.xprv_text, pw_decode(enc_xprv_key,
                                                   self.password))
        self.assertEqual(
            self.xprv_text,
            self.wallet.get_master_private_key('x/', self.password))

    def test_check_password(self):
        # no errors should occur if the password is valid
        self.wallet.check_password(self.password)

    def test_check_invalid_password(self):
        with self.assertRaises(InvalidPassword):
            self.wallet.check_password('invalid')