Beispiel #1
0
class TestNewWallet(WalletTestCase):

    seed_text = "travel nowhere air position hill peace suffer parent beautiful rise blood power home crumble teach"
    password = "******"

    # mnemonic_to_seed should be this
    actual_root_privkey = 'xprv9s21ZrQH143K3cU1yF5gBUQqHw8QBnH5Cgym3XqSRZmfSJ3J2NYzjd7UcdHwjwBjKXD3ZvwoMLo88F4oaVhYgZZ5SdmZ9RA9Wdf93U8iZB3'

    def setUp(self):
        super(TestNewWallet, self).setUp()
        self.storage = WalletStorage(self.fake_config)
        self.wallet = NewWallet(self.storage)
        # This cannot be constructed by electrum 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(self.password)

    def _switch_chain(self, chaincode):
        self.wallet.set_chain(chaincode)
        action = self.wallet.get_action()
        while action is not None:
            if action == 'add_chain':
                self.wallet.create_master_keys(self.password)
            elif action == 'create_accounts':
                self.wallet.create_main_account(self.password)
            action = self.wallet.get_action()

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

    def test_wallet_root_derivation(self):
        self.wallet.set_chain('BTC')
        self.assertEqual(
            bip32_root(self.wallet.mnemonic_to_seed(self.seed_text, ''))[0],
            self.actual_root_privkey)

    def test_wallet_key_derivation(self):
        self._switch_chain('BTC')
        # master key for Bitcoin (m/44'/0')
        self.assertEqual(
            'xprv9wrjoAEFgZU867r47BZXNvdM6y3w4DHnRnWiRq95DHV2u6SQ19LJ3NVe3vjhz5BQdPrZTTdQo7iGhVXLsVz1ysDBa9K94tXJFkNif39ESue',
            self.wallet.get_master_private_key("x/", self.password))

        # key for Bitcoin account 0 (m/44'/0'/0')
        self.assertEqual(
            'xprv9yARpU9jbs62FabfqwhqH4ZhsaMEeyuzvNc97nBDk54TTxbkuwqkiEYy8wrYFQcwZUDzKD3RaFdbJYVYWLBiXyELgiWBRw4cdvGQ2CPK3FD',
            self.wallet.get_master_private_key("x/0'", self.password))

        self._switch_chain('MZC')
        # master key for Mazacoin (m/44'/13')
        self.assertEqual(
            'xprv9wrjoAEFgZU8dr6gc32HuUXAGwfULLtaFHZGy5L5MQfXSRK3cGyUKhnDtejWKxyPk15PWt3SRR68v6TBZog6jj1yvJTssVb7NyM1zZrPBsp',
            self.wallet.get_master_private_key("x/", self.password))

        # key for Mazacoin account 0 (m/44'/13'/0')
        self.assertEqual(
            'xprv9zT9DPHrjeZS4gUXt9dwZfrTzWAyBsBAHatw3vthKUbqAMo8Z15NQq7zBU6tWrEp6Wk6Tk4o9NNaRz9dNbSRHkP1TcrKotKRk2TcZF1647w',
            self.wallet.get_master_private_key("x/0'", self.password))

    def test_update_password(self):
        # Switch to Mazacoin and verify that the other chain is also updated with a new password
        new_password = "******"
        self._switch_chain('BTC')
        self._switch_chain('MZC')
        self.wallet.update_password(self.password, new_password)

        # master key for Mazacoin (m/44'/13')
        self.assertEqual(
            'xprv9wrjoAEFgZU8dr6gc32HuUXAGwfULLtaFHZGy5L5MQfXSRK3cGyUKhnDtejWKxyPk15PWt3SRR68v6TBZog6jj1yvJTssVb7NyM1zZrPBsp',
            self.wallet.get_master_private_key("x/", new_password))

        self._switch_chain('BTC')
        # master key for Bitcoin (m/44'/0')
        self.assertEqual(
            'xprv9wrjoAEFgZU867r47BZXNvdM6y3w4DHnRnWiRq95DHV2u6SQ19LJ3NVe3vjhz5BQdPrZTTdQo7iGhVXLsVz1ysDBa9K94tXJFkNif39ESue',
            self.wallet.get_master_private_key("x/", new_password))
Beispiel #2
0
class TestNewWallet(WalletTestCase):

    seed_text = "travel nowhere air position hill peace suffer parent beautiful rise blood power home crumble teach"
    password = "******"

    # mnemonic_to_seed should be this
    actual_root_privkey = "xprv9s21ZrQH143K3cU1yF5gBUQqHw8QBnH5Cgym3XqSRZmfSJ3J2NYzjd7UcdHwjwBjKXD3ZvwoMLo88F4oaVhYgZZ5SdmZ9RA9Wdf93U8iZB3"

    def setUp(self):
        super(TestNewWallet, self).setUp()
        self.storage = WalletStorage(self.fake_config)
        self.wallet = NewWallet(self.storage)
        # This cannot be constructed by electrum 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(self.password)

    def _switch_chain(self, chaincode):
        self.wallet.set_chain(chaincode)
        action = self.wallet.get_action()
        while action is not None:
            if action == "add_chain":
                self.wallet.create_master_keys(self.password)
            elif action == "create_accounts":
                self.wallet.create_main_account(self.password)
            action = self.wallet.get_action()

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

    def test_wallet_root_derivation(self):
        self.wallet.set_chain("BTC")
        self.assertEqual(bip32_root(self.wallet.mnemonic_to_seed(self.seed_text, ""))[0], self.actual_root_privkey)

    def test_wallet_key_derivation(self):
        self._switch_chain("BTC")
        # master key for Bitcoin (m/44'/0')
        self.assertEqual(
            "xprv9wrjoAEFgZU867r47BZXNvdM6y3w4DHnRnWiRq95DHV2u6SQ19LJ3NVe3vjhz5BQdPrZTTdQo7iGhVXLsVz1ysDBa9K94tXJFkNif39ESue",
            self.wallet.get_master_private_key("x/", self.password),
        )

        # key for Bitcoin account 0 (m/44'/0'/0')
        self.assertEqual(
            "xprv9yARpU9jbs62FabfqwhqH4ZhsaMEeyuzvNc97nBDk54TTxbkuwqkiEYy8wrYFQcwZUDzKD3RaFdbJYVYWLBiXyELgiWBRw4cdvGQ2CPK3FD",
            self.wallet.get_master_private_key("x/0'", self.password),
        )

        self._switch_chain("MZC")
        # master key for Mazacoin (m/44'/13')
        self.assertEqual(
            "xprv9wrjoAEFgZU8dr6gc32HuUXAGwfULLtaFHZGy5L5MQfXSRK3cGyUKhnDtejWKxyPk15PWt3SRR68v6TBZog6jj1yvJTssVb7NyM1zZrPBsp",
            self.wallet.get_master_private_key("x/", self.password),
        )

        # key for Mazacoin account 0 (m/44'/13'/0')
        self.assertEqual(
            "xprv9zT9DPHrjeZS4gUXt9dwZfrTzWAyBsBAHatw3vthKUbqAMo8Z15NQq7zBU6tWrEp6Wk6Tk4o9NNaRz9dNbSRHkP1TcrKotKRk2TcZF1647w",
            self.wallet.get_master_private_key("x/0'", self.password),
        )

    def test_update_password(self):
        # Switch to Mazacoin and verify that the other chain is also updated with a new password
        new_password = "******"
        self._switch_chain("BTC")
        self._switch_chain("MZC")
        self.wallet.update_password(self.password, new_password)

        # master key for Mazacoin (m/44'/13')
        self.assertEqual(
            "xprv9wrjoAEFgZU8dr6gc32HuUXAGwfULLtaFHZGy5L5MQfXSRK3cGyUKhnDtejWKxyPk15PWt3SRR68v6TBZog6jj1yvJTssVb7NyM1zZrPBsp",
            self.wallet.get_master_private_key("x/", new_password),
        )

        self._switch_chain("BTC")
        # master key for Bitcoin (m/44'/0')
        self.assertEqual(
            "xprv9wrjoAEFgZU867r47BZXNvdM6y3w4DHnRnWiRq95DHV2u6SQ19LJ3NVe3vjhz5BQdPrZTTdQo7iGhVXLsVz1ysDBa9K94tXJFkNif39ESue",
            self.wallet.get_master_private_key("x/", new_password),
        )