def create_volatile_wallet(seedphrase, wallet_cls=SegwitWallet): storage = VolatileStorage() wallet_cls.initialize(storage, get_network(), max_mixdepth=4, entropy=wallet_cls.entropy_from_mnemonic(seedphrase)) storage.save() return wallet_cls(storage)
def test_wrong_wallet_cls(setup_wallet): storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network()) wallet = SegwitLegacyWallet(storage) wallet.save() data = storage.file_data del wallet del storage storage = VolatileStorage(data=data) with pytest.raises(Exception): LegacyWallet(storage)
def test_wallet_mixdepth_decrease(setup_wallet): wallet = get_populated_wallet(num=1) # setup max_mixdepth = wallet.max_mixdepth assert max_mixdepth >= 1, "bad default value for mixdepth for this test" utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(max_mixdepth), 1) assert wallet.get_balance_by_mixdepth()[max_mixdepth] == 10**8 wallet.close() storage_data = wallet._storage.file_data # actual test new_mixdepth = max_mixdepth - 1 new_wallet = type(wallet)(VolatileStorage(data=storage_data), mixdepth=new_mixdepth) assert new_wallet.max_mixdepth == max_mixdepth assert new_wallet.mixdepth == new_mixdepth sync_test_wallet(True, new_wallet) assert max_mixdepth not in new_wallet.get_balance_by_mixdepth() assert max_mixdepth not in new_wallet.get_utxos_by_mixdepth() # wallet.select_utxos will still return utxos from higher mixdepths # because we explicitly ask for a specific mixdepth assert utxo in new_wallet.select_utxos_(max_mixdepth, 10**7)
def test_wallet_mixdepth_decrease(setup_wallet): wallet = get_populated_wallet(num=1) # setup max_mixdepth = wallet.max_mixdepth assert max_mixdepth >= 1, "bad default value for mixdepth for this test" utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(max_mixdepth), 1) bci = jm_single().bc_interface unspent_list = bci.listunspent(0) # filter on label, but note (a) in certain circumstances (in- # wallet transfer) it is possible for the utxo to be labeled # with the external label, and (b) the wallet will know if it # belongs or not anyway (is_known_addr): our_unspent_list = [x for x in unspent_list if ( bci.is_address_labeled(x, wallet.get_wallet_name()))] assert wallet.get_balance_by_mixdepth()[max_mixdepth] == 10**8 wallet.close() storage_data = wallet._storage.file_data # actual test new_mixdepth = max_mixdepth - 1 new_wallet = type(wallet)( VolatileStorage(data=storage_data), mixdepth=new_mixdepth) assert new_wallet.max_mixdepth == max_mixdepth assert new_wallet.mixdepth == new_mixdepth sync_test_wallet(True, WalletService(new_wallet)) assert max_mixdepth not in new_wallet.get_balance_by_mixdepth() assert max_mixdepth not in new_wallet.get_utxos_by_mixdepth() # wallet.select_utxos will still return utxos from higher mixdepths # because we explicitly ask for a specific mixdepth assert utxo in new_wallet.select_utxos(max_mixdepth, 10**7)
def test_bip32_test_vector_2(monkeypatch, setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet') entropy = unhexlify( 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542' ) storage = VolatileStorage() LegacyWallet.initialize(storage, get_network(), entropy=entropy, max_mixdepth=0) monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path', BIP32Wallet._get_bip32_base_path) monkeypatch.setattr(LegacyWallet, '_create_master_key', BIP32Wallet._create_master_key) wallet = LegacyWallet(storage) assert wallet.get_bip32_priv_export( ) == 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U' assert wallet.get_bip32_pub_export( ) == 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB' assert wallet.get_bip32_priv_export( 0 ) == 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt' assert wallet.get_bip32_pub_export( 0 ) == 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
def test_timelocked_output_signing(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') ensure_bip65_activated() storage = VolatileStorage() SegwitLegacyWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitLegacyWalletFidelityBonds(storage) index = 0 timenumber = 0 script = wallet.get_script_and_update_map( FidelityBondMixin.FIDELITY_BOND_MIXDEPTH, FidelityBondMixin.BIP32_TIMELOCK_ID, index, timenumber) utxo = fund_wallet_addr(wallet, wallet.script_to_addr(script)) timestamp = wallet._time_number_to_timestamp(timenumber) tx = btc.mktx([utxo], [{ "address": str( btc.CCoinAddress.from_scriptPubKey( btc.standard_scripthash_scriptpubkey(btc.Hash160(b"\x00")))), "value": 10**8 - 9000 }], locktime=timestamp + 1) success, msg = wallet.sign_tx(tx, {0: (script, 10**8)}) assert success, msg txout = jm_single().bc_interface.pushtx(tx.serialize()) assert txout
def __init__(self): storage = VolatileStorage() super(DummyWallet, self).initialize(storage, get_network(), max_mixdepth=5) super(DummyWallet, self).__init__(storage) self._add_utxos() self.inject_addr_get_failure = False
def test_bip32_test_vector_3(monkeypatch, setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet') entropy = unhexlify( '4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be' ) storage = VolatileStorage() LegacyWallet.initialize(storage, get_network(), entropy=entropy, max_mixdepth=0) # test vector 3 is using hardened derivation for the account/mixdepth level monkeypatch.setattr(LegacyWallet, '_get_mixdepth_from_path', BIP49Wallet._get_mixdepth_from_path) monkeypatch.setattr(LegacyWallet, '_get_bip32_mixdepth_path_level', BIP49Wallet._get_bip32_mixdepth_path_level) monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path', BIP32Wallet._get_bip32_base_path) monkeypatch.setattr(LegacyWallet, '_create_master_key', BIP32Wallet._create_master_key) wallet = LegacyWallet(storage) assert wallet.get_bip32_priv_export( ) == 'xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6' assert wallet.get_bip32_pub_export( ) == 'xpub661MyMwAqRbcEZVB4dScxMAdx6d4nFc9nvyvH3v4gJL378CSRZiYmhRoP7mBy6gSPSCYk6SzXPTf3ND1cZAceL7SfJ1Z3GC8vBgp2epUt13' assert wallet.get_bip32_priv_export( 0 ) == 'xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L' assert wallet.get_bip32_pub_export( 0 ) == 'xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y'
def test_bip32_addresses_p2pkh(monkeypatch, setup_wallet, mixdepth, internal, index, address, wif): """ Test with a random but fixed entropy """ jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') entropy = unhexlify( '2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817') storage = VolatileStorage() LegacyWallet.initialize(storage, get_network(), entropy=entropy, max_mixdepth=3) monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path', BIP32Wallet._get_bip32_base_path) monkeypatch.setattr(LegacyWallet, '_create_master_key', BIP32Wallet._create_master_key) wallet = LegacyWallet(storage) # wallet needs to know about all intermediate keys for i in range(index + 1): wallet.get_new_script(mixdepth, internal) assert wif == wallet.get_wif(mixdepth, internal, index) assert address == wallet.get_addr(mixdepth, internal, index)
def test_bip32_test_vector_1(monkeypatch, setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet') entropy = unhexlify('000102030405060708090a0b0c0d0e0f') storage = VolatileStorage() LegacyWallet.initialize( storage, get_network(), entropy=entropy, max_mixdepth=0) # test vector 1 is using hardened derivation for the account/mixdepth level monkeypatch.setattr(LegacyWallet, '_get_mixdepth_from_path', BIP49Wallet._get_mixdepth_from_path) monkeypatch.setattr(LegacyWallet, '_get_bip32_mixdepth_path_level', BIP49Wallet._get_bip32_mixdepth_path_level) monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path', BIP32Wallet._get_bip32_base_path) monkeypatch.setattr(LegacyWallet, '_create_master_key', BIP32Wallet._create_master_key) wallet = LegacyWallet(storage) assert wallet.get_bip32_priv_export() == 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi' assert wallet.get_bip32_pub_export() == 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' assert wallet.get_bip32_priv_export(0) == 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7' assert wallet.get_bip32_pub_export(0) == 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw' assert wallet.get_bip32_priv_export(0, 1) == 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs' assert wallet.get_bip32_pub_export(0, 1) == 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
def test_wallet_id(setup_wallet): storage1 = VolatileStorage() SegwitLegacyWallet.initialize(storage1, get_network()) wallet1 = SegwitLegacyWallet(storage1) storage2 = VolatileStorage() LegacyWallet.initialize(storage2, get_network(), entropy=wallet1._entropy) wallet2 = LegacyWallet(storage2) assert wallet1.get_wallet_id() != wallet2.get_wallet_id() storage2 = VolatileStorage() SegwitLegacyWallet.initialize(storage2, get_network(), entropy=wallet1._entropy) wallet2 = SegwitLegacyWallet(storage2) assert wallet1.get_wallet_id() == wallet2.get_wallet_id()
def test_gettimelockaddress_in_past(setup_wallet): jm_single().config.set("BLOCKCHAIN", "network", "mainnet") storage = VolatileStorage() SegwitWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitWalletFidelityBonds(storage) assert wallet_gettimelockaddress(wallet, "2020-01") == "" assert wallet_gettimelockaddress(wallet, "2021-01") == "" assert wallet_gettimelockaddress(wallet, "2021-02") != ""
def test_is_standard_wallet_script(setup_wallet, wallet_cls): storage = VolatileStorage() wallet_cls.initialize( storage, get_network(), max_mixdepth=0) wallet = wallet_cls(storage) script = wallet.get_new_script(0, 1) assert wallet.is_known_script(script) path = wallet.script_to_path(script) assert wallet.is_standard_wallet_script(path)
def test_import_key(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network()) wallet = SegwitLegacyWallet(storage) wallet.import_private_key( 0, 'cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM', cryptoengine.TYPE_P2SH_P2WPKH) wallet.import_private_key( 1, 'cVqtSSoVxFyPqTRGfeESi31uCYfgTF4tGWRtGeVs84fzybiX5TPk', cryptoengine.TYPE_P2PKH) with pytest.raises(WalletError): wallet.import_private_key( 1, 'cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM', cryptoengine.TYPE_P2SH_P2WPKH) # test persist imported keys wallet.save() data = storage.file_data del wallet del storage storage = VolatileStorage(data=data) wallet = SegwitLegacyWallet(storage) imported_paths_md0 = list(wallet.yield_imported_paths(0)) imported_paths_md1 = list(wallet.yield_imported_paths(1)) assert len(imported_paths_md0) == 1 assert len(imported_paths_md1) == 1 # verify imported addresses assert wallet.get_addr_path( imported_paths_md0[0]) == '2MzY5yyonUY7zpHspg7jB7WQs1uJxKafQe4' assert wallet.get_addr_path( imported_paths_md1[0]) == 'mpCX9EbdXpcrKMtjEe1fqFhvzctkfzMYTX' # test remove key wallet.remove_imported_key(path=imported_paths_md0[0]) assert not list(wallet.yield_imported_paths(0)) assert wallet.get_details(imported_paths_md1[0]) == (1, 'imported', 0)
def get_populated_wallet(amount=10**8, num=3): storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network()) wallet = SegwitLegacyWallet(storage) # fund three wallet addresses at mixdepth 0 for i in range(num): fund_wallet_addr(wallet, wallet.get_internal_addr(0), amount / 10**8) return wallet
def test_wallet_mixdepth_simple(setup_wallet): wallet = get_populated_wallet(num=0) mixdepth = wallet.mixdepth assert wallet.max_mixdepth == mixdepth wallet.close() storage_data = wallet._storage.file_data new_wallet = type(wallet)(VolatileStorage(data=storage_data)) assert new_wallet.mixdepth == mixdepth assert new_wallet.max_mixdepth == mixdepth
def test_watchonly_wallet(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() SegwitLegacyWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitLegacyWalletFidelityBonds(storage) paths = [ "m/49'/1'/0'/0/0", "m/49'/1'/0'/1/0", "m/49'/1'/0'/2/0:1577836800", "m/49'/1'/0'/2/0:2314051200" ] burn_path = "m/49'/1'/0'/3/0" scripts = [ wallet.get_script_from_path(wallet.path_repr_to_path(path)) for path in paths ] privkey, engine = wallet._get_key_from_path( wallet.path_repr_to_path(burn_path)) burn_pubkey = engine.privkey_to_pubkey(privkey) master_pub_key = wallet.get_bip32_pub_export( FidelityBondMixin.FIDELITY_BOND_MIXDEPTH) watchonly_storage = VolatileStorage() entropy = FidelityBondMixin.get_xpub_from_fidelity_bond_master_pub_key( master_pub_key).encode() FidelityBondWatchonlyWallet.initialize(watchonly_storage, get_network(), entropy=entropy) watchonly_wallet = FidelityBondWatchonlyWallet(watchonly_storage) watchonly_scripts = [ watchonly_wallet.get_script_from_path( watchonly_wallet.path_repr_to_path(path)) for path in paths ] privkey, engine = wallet._get_key_from_path( wallet.path_repr_to_path(burn_path)) watchonly_burn_pubkey = engine.privkey_to_pubkey(privkey) for script, watchonly_script in zip(scripts, watchonly_scripts): assert script == watchonly_script assert burn_pubkey == watchonly_burn_pubkey
def test_is_standard_wallet_script_nonstandard(setup_wallet): storage = VolatileStorage() SegwitWalletFidelityBonds.initialize( storage, get_network(), max_mixdepth=0) wallet = SegwitWalletFidelityBonds(storage) import_path = wallet.import_private_key( 0, 'cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM') assert wallet.is_standard_wallet_script(import_path) ts = wallet.datetime_to_time_number( datetime.datetime.strptime("2021-07", "%Y-%m")) tl_path = wallet.get_path(0, wallet.BIP32_TIMELOCK_ID, ts) assert not wallet.is_standard_wallet_script(tl_path)
def __init__(self, balances): """Creates the wallet, setting the balances of the mixdepths as given by the array. (And the number of mixdepths from the array elements.""" load_test_config() storage = VolatileStorage() super().initialize(storage, get_network(), max_mixdepth=len(balances)-1) super().__init__(storage) for m, b in enumerate(balances): self.add_utxo_at_mixdepth(m, b)
def test_signmessage(seed, hdpath, walletcls, message, sig, addr): load_test_config() jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet') select_chain_params("bitcoin/mainnet") storage = VolatileStorage() walletcls.initialize( storage, get_network(), entropy=seed, max_mixdepth=3) wallet = walletcls(storage) s, m, a = wallet_signmessage(wallet, hdpath, message, out_str=False) assert (s, m, a) == (sig, message, addr) jm_single().config.set("BLOCKCHAIN", "network", "testnet") select_chain_params("bitcoin/regtest")
def test_signing_simple(setup_wallet, wallet_cls, type_check): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() wallet_cls.initialize(storage, get_network()) wallet = wallet_cls(storage) utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(0)) tx = btc.deserialize(btc.mktx(['{}:{}'.format(hexlify(utxo[0]).decode('ascii'), utxo[1])], ['00'*17 + ':' + str(10**8 - 9000)])) binarize_tx(tx) script = wallet.get_script(0, 1, 0) wallet.sign_tx(tx, {0: (script, 10**8)}) type_check(tx) txout = jm_single().bc_interface.pushtx(hexlify(btc.serialize(tx)).decode('ascii')) assert txout
def test_gettimelockaddress_method(setup_wallet, timenumber, locktime_string): jm_single().config.set("BLOCKCHAIN", "network", "mainnet") storage = VolatileStorage() SegwitWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitWalletFidelityBonds(storage) m = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH address_type = FidelityBondMixin.BIP32_TIMELOCK_ID script = wallet.get_script_and_update_map(m, address_type, timenumber) addr = wallet.script_to_addr(script) addr_from_method = wallet_gettimelockaddress(wallet, locktime_string) assert addr == addr_from_method
def test_gettimelockaddress_method(setup_wallet, timenumber, locktime_string): storage = VolatileStorage() SegwitLegacyWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitLegacyWalletFidelityBonds(storage) m = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH address_type = FidelityBondMixin.BIP32_TIMELOCK_ID index = wallet.get_next_unused_index(m, address_type) script = wallet.get_script_and_update_map(m, address_type, index, timenumber) addr = wallet.script_to_addr(script) addr_from_method = wallet_gettimelockaddress(wallet, locktime_string) assert addr == addr_from_method
def test_bip32_burn_keys(setup_wallet, index, wif): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') entropy = unhexlify('2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817') storage = VolatileStorage() SegwitWalletFidelityBonds.initialize( storage, get_network(), entropy=entropy, max_mixdepth=1) wallet = SegwitWalletFidelityBonds(storage) mixdepth = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH address_type = FidelityBondMixin.BIP32_BURN_ID #advance index_cache enough wallet.set_next_index(mixdepth, address_type, index, force=True) assert wif == wallet.get_wif_path(wallet.get_path(mixdepth, address_type, index))
def test_signing_simple(setup_wallet, wallet_cls, type_check): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() wallet_cls.initialize(storage, get_network()) wallet = wallet_cls(storage) utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(0)) # The dummy output is constructed as an unspendable p2sh: tx = btc.deserialize(btc.mktx(['{}:{}'.format( hexlify(utxo[0]).decode('ascii'), utxo[1])], [btc.p2sh_scriptaddr(b"\x00",magicbyte=196) + ':' + str(10**8 - 9000)])) script = wallet.get_script(0, 1, 0) tx = wallet.sign_tx(tx, {0: (script, 10**8)}) type_check(tx) txout = jm_single().bc_interface.pushtx(btc.serialize(tx)) assert txout
def open_test_wallet_maybe(path, seed, max_mixdepth, test_wallet_cls=SegwitLegacyWallet, **kwargs): """ Create a volatile test wallet if path is a hex-encoded string of length 64, otherwise run open_wallet(). params: path: path to wallet file, ignored for test wallets seed: hex-encoded test seed max_mixdepth: maximum mixdepth to use kwargs: see open_wallet() returns: wallet object """ # If the native flag is set in the config, it overrides the argument # test_wallet_cls if jm_single().config.get("POLICY", "native") == "true": test_wallet_cls = SegwitWallet if len(seed) == test_wallet_cls.ENTROPY_BYTES * 2: try: seed = binascii.unhexlify(seed) except binascii.Error: pass else: if max_mixdepth is None: max_mixdepth = DEFAULT_MIXDEPTH storage = VolatileStorage() test_wallet_cls.initialize(storage, get_network(), max_mixdepth=max_mixdepth, entropy=seed) #wallet instantiation insists on no unexpected kwargs, #but Qt caller opens both test and mainnet with same args, #hence these checks/deletes of unwanted args for tests. if 'ask_for_password' in kwargs: del kwargs['ask_for_password'] if 'password' in kwargs: del kwargs['password'] if 'read_only' in kwargs: del kwargs['read_only'] return test_wallet_cls(storage, **kwargs) return open_wallet(path, mixdepth=max_mixdepth, **kwargs)
def test_freeze_timelocked_utxos(setup_env_nodeps): storage = VolatileStorage() SegwitWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitWalletFidelityBonds(storage) ts = wallet.datetime_to_time_number( datetime.datetime.strptime("2021-07", "%Y-%m")) tl_path = wallet.get_path(wallet.FIDELITY_BOND_MIXDEPTH, wallet.BIP32_TIMELOCK_ID, ts) tl_script = wallet.get_script_from_path(tl_path) utxo = (b'a' * 32, 0) wallet.add_utxo(utxo[0], utxo[1], tl_script, 100000000) assert not wallet._utxos.is_disabled(*utxo) maker = OfflineMaker(WalletService(wallet)) maker.freeze_timelocked_utxos() assert wallet._utxos.is_disabled(*utxo)
def test_bip39_seeds(monkeypatch, setup_wallet, entropy, mnemonic, key, xpriv): jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet') created_entropy = SegwitLegacyWallet.entropy_from_mnemonic(mnemonic) assert entropy == hexlify(created_entropy).decode('ascii') storage = VolatileStorage() SegwitLegacyWallet.initialize( storage, get_network(), entropy=created_entropy, entropy_extension='TREZOR', max_mixdepth=4) wallet = SegwitLegacyWallet(storage) assert (mnemonic, b'TREZOR') == wallet.get_mnemonic_words() assert key == hexlify(wallet._create_master_key()).decode('ascii') # need to monkeypatch this, else we'll default to the BIP-49 path monkeypatch.setattr(SegwitLegacyWallet, '_get_bip32_base_path', BIP32Wallet._get_bip32_base_path) assert xpriv == wallet.get_bip32_priv_export()
def test_bip32_timelocked_addresses(setup_wallet, timenumber, address, wif): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') entropy = unhexlify('2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817') storage = VolatileStorage() SegwitWalletFidelityBonds.initialize( storage, get_network(), entropy=entropy, max_mixdepth=1) wallet = SegwitWalletFidelityBonds(storage) mixdepth = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH address_type = FidelityBondMixin.BIP32_TIMELOCK_ID #wallet needs to know about the script beforehand wallet.get_script_and_update_map(mixdepth, address_type, timenumber) assert address == wallet.get_addr(mixdepth, address_type, timenumber) assert wif == wallet.get_wif_path(wallet.get_path(mixdepth, address_type, timenumber))
def test_imported_key_removed(setup_wallet): wif = 'cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM' storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network()) wallet = SegwitLegacyWallet(storage) path = wallet.import_private_key(1, wif) script = wallet.get_script_from_path(path) assert wallet.is_known_script(script) wallet.remove_imported_key(path=path) assert not wallet.is_known_script(script) with pytest.raises(WalletError): wallet.get_script_from_path(path)