コード例 #1
0
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_address_from_path(
        imported_paths_md0[0]) == '2MzY5yyonUY7zpHspg7jB7WQs1uJxKafQe4'
    assert wallet.get_address_from_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)
コード例 #2
0
def test_signing_imported(setup_wallet, wif, keytype, 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, keytype)
    utxo = fund_wallet_addr(wallet, wallet.get_address_from_path(path))
    # 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_from_path(path)
    tx = wallet.sign_tx(tx, {0: (script, 10**8)})
    type_check(tx)
    txout = jm_single().bc_interface.pushtx(btc.serialize(tx))
    assert txout
コード例 #3
0
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