Exemple #1
0
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
Exemple #2
0
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()
    SegwitLegacyWalletFidelityBonds.initialize(
        storage, get_network(), entropy=entropy, max_mixdepth=1)
    wallet = SegwitLegacyWalletFidelityBonds(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_bip32_timelocked_addresses(setup_wallet, index, timenumber, address, wif):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')

    entropy = unhexlify('2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817')
    storage = VolatileStorage()
    SegwitLegacyWalletFidelityBonds.initialize(
        storage, get_network(), entropy=entropy, max_mixdepth=1)
    wallet = SegwitLegacyWalletFidelityBonds(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, index, timenumber)

    assert address == wallet.get_addr(mixdepth, address_type, index, timenumber)
    assert wif == wallet.get_wif_path(wallet.get_path(mixdepth, address_type, index, timenumber))
Exemple #5
0
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
Exemple #6
0
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.deserialize(btc.mktx(['{}:{}'.format(
        hexlify(utxo[0]).decode('ascii'), utxo[1])],
        [btc.p2sh_scriptaddr(b"\x00",magicbyte=196) + ':' + str(10**8 - 9000)],
        locktime=timestamp+1))
    tx = wallet.sign_tx(tx, {0: (script, 10**8)})
    txout = jm_single().bc_interface.pushtx(btc.serialize(tx))
    assert txout