def test_signing_imported(setup_wallet, wif, type_check): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network()) wallet = SegwitLegacyWallet(storage) MIXDEPTH = 0 path = wallet.import_private_key(MIXDEPTH, wif) utxo = fund_wallet_addr(wallet, wallet.get_address_from_path(path)) # The dummy output is constructed as an unspendable p2sh: tx = btc.mktx([utxo], [{ "address": str( btc.CCoinAddress.from_scriptPubKey( btc.CScript(b"\x00").to_p2sh_scriptPubKey())), "value": 10**8 - 9000 }]) script = wallet.get_script_from_path(path) success, msg = wallet.sign_tx(tx, {0: (script, 10**8)}) assert success, msg type_check(tx) txout = jm_single().bc_interface.pushtx(tx.serialize()) assert txout
def test_wallet_save(setup_wallet): wallet = get_populated_wallet() script = wallet.get_external_script(1) wallet.save() storage = wallet._storage data = storage.file_data del wallet del storage storage = VolatileStorage(data=data) wallet = SegwitLegacyWallet(storage) assert wallet.get_next_unused_index(0, BaseWallet.ADDRESS_TYPE_INTERNAL) == 3 assert wallet.get_next_unused_index(0, BaseWallet.ADDRESS_TYPE_EXTERNAL) == 0 assert wallet.get_next_unused_index(1, BaseWallet.ADDRESS_TYPE_INTERNAL) == 0 assert wallet.get_next_unused_index(1, BaseWallet.ADDRESS_TYPE_EXTERNAL) == 1 assert wallet.is_known_script(script)
def test_bip49_seed(monkeypatch, setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' master_xpriv = 'tprv8ZgxMBicQKsPe5YMU9gHen4Ez3ApihUfykaqUorj9t6FDqy3nP6eoXiAo2ssvpAjoLroQxHqr3R5nE3a5dU3DHTjTgJDd7zrbniJr6nrCzd' account0_xpriv = 'tprv8gRrNu65W2Msef2BdBSUgFdRTGzC8EwVXnV7UGS3faeXtuMVtGfEdidVeGbThs4ELEoayCAzZQ4uUji9DUiAs7erdVskqju7hrBcDvDsdbY' addr0_script_hash = '336caa13e08b96080a32b5d818d59b4ab3b36742' entropy = SegwitLegacyWallet.entropy_from_mnemonic(mnemonic) storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network(), entropy=entropy, max_mixdepth=0) wallet = SegwitLegacyWallet(storage) assert (mnemonic, None) == wallet.get_mnemonic_words() assert account0_xpriv == wallet.get_bip32_priv_export(0) assert addr0_script_hash == hexlify( wallet.get_external_script(0)[2:-1]).decode('ascii') # FIXME: is this desired behaviour? BIP49 wallet will not return xpriv for # the root key but only for key after base path monkeypatch.setattr(SegwitLegacyWallet, '_get_bip32_base_path', BIP32Wallet._get_bip32_base_path) assert master_xpriv == wallet.get_bip32_priv_export()