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_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 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_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_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_timelocked_output_signing(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') ensure_bip65_activated() storage = VolatileStorage() SegwitWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitWalletFidelityBonds(storage) timenumber = 0 script = wallet.get_script_and_update_map( FidelityBondMixin.FIDELITY_BOND_MIXDEPTH, FidelityBondMixin.BIP32_TIMELOCK_ID, 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 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_watchonly_wallet(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() SegwitWalletFidelityBonds.initialize(storage, get_network()) wallet = SegwitWalletFidelityBonds(storage) paths = [ "m/84'/1'/0'/0/0", "m/84'/1'/0'/1/0", "m/84'/1'/0'/2/0:1577836800", "m/84'/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