Ejemplo n.º 1
0
def disabled_test_format_parse_amount(attrs, number, expected_formatted):
    '''Round-trips formatting and parsing of amounts'''
    contract_stream = make_contract("../test-data/sample-contracts/btc.xml",
                                    attrs)
    myasset = asset.Asset().issue(nym.Nym().register(), contract_stream)
    actual_formatted = opentxs.OTAPI_Wrap_FormatAmount(myasset._id, number)
    assert actual_formatted == expected_formatted
    actual_number = opentxs.OTAPI_Wrap_StringToAmount(myasset._id,
                                                      actual_formatted)
    assert actual_number == number
Ejemplo n.º 2
0
def setup(contract_stream):
    '''
    Helps create a clean config dir starting from scratch.
    '''
    pyopentxs.init()
    server_nym = nym.Nym().create()
    with closing(contract_stream):
        server_contract = server.add(server_nym._id, contract_stream.read())
    walletxml = decode(open(config_dir + "client_data/wallet.xml"))
    cached_key = BeautifulSoup(walletxml).wallet.cachedkey.string.strip()
    signed_contract_file = config_dir + "client_data/contracts/" + server_contract
    with closing(open(signed_contract_file)) as f:
        signed_contract = f.read()
    decoded_signed_contract = decode(io.StringIO(signed_contract))

    # copy the credentials to the server
    server_data_dir = config_dir + "server_data/"
    if not os.path.exists(server_data_dir):
        os.mkdir(server_data_dir)
    shutil.copytree(config_dir + "client_data/credentials",
                    server_data_dir + "credentials")
    # remove the client-side data
    shutil.rmtree(config_dir + "client_data")

    # reread the client data (empty)
    pyopentxs.init()

    # since we still don't have programmatic access, just print the info
    # for easy copying
    print(server_contract)
    print(server_nym._id)
    print(cached_key + "\n~")
    print("\n~")
    print(decoded_signed_contract + "\n~")

    # next line crashes the process
    # opentxs.MainFile(None).CreateMainFile(signed_contract, server_contract, "", server_nym,
    # cached_key)
    # add the server contract on the client side
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)

    return decoded_signed_contract
Ejemplo n.º 3
0
def setup(contract_stream, total_servers=1):
    '''
    Helps create a clean config dir starting from scratch.
    contract_stream is an input stream pointing to a template contract file.
    total_servers is an integer, of how many servers the client should have on file.
    Only the first server will actually exist, the rest will appear as offline.
    '''
    pyopentxs.init()
    server_nym = nym.Nym().create()

    contract = contract_stream.read()
    contract_stream.close()

    server_contract_id, cached_key, decoded_signed_contract \
        = make_server_contract(contract, server_nym)

    walletxml = decode(open(config_dir + "client_data/wallet.xml"))
    cached_key = BeautifulSoup(walletxml).wallet.cachedkey.string.strip()
    signed_contract_file = config_dir + "client_data/contracts/" + server_contract_id
    with closing(open(signed_contract_file)) as f:
        signed_contract = f.read()
    decoded_signed_contract = decode(io.StringIO(signed_contract))

    # copy the credentials to the server
    server_data_dir = config_dir + "server_data/"
    if not os.path.exists(server_data_dir):
        os.mkdir(server_data_dir)
    shutil.copytree(config_dir + "client_data/credentials",
                    server_data_dir + "credentials")
    # remove the client-side data
    shutil.rmtree(config_dir + "client_data")

    # reread the client data (empty)
    pyopentxs.init()
    print("reread client data")
    # since we still don't have programmatic access, just write the info
    # to use later to pipe to the notary process
    output = io.BytesIO()
    writeit = lambda s: output.write(s.encode("utf-8"))
    writeit(server_contract_id + "\n")
    writeit(server_nym._id + "\n")
    writeit(cached_key + "\n~\n~\n")
    writeit(decoded_signed_contract + "\n~\n")

    # the following crashes the process, so we pipe the info manually
    # opentxs.MainFile(None).CreateMainFile(signed_contract, server_contract_id, "", server_nym,
    # cached_key)

    # add the server contract on the client side
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)

    # should be just one known active server now
    server.active = [server_contract_id]

    # create any extra fake servers
    for _ in range(total_servers - 1):
        opentxs.OTAPI_Wrap_AddServerContract(
            make_server_contract(contract,
                                 nym.Nym().create())[2])

    return output
Ejemplo n.º 4
0
def test_create_nym():
    nym_id = nym.Nym().create()._id
    nym_ids = [n._id for n in nym.get_all()]

    assert (nym_id in nym_ids), "nym_id=%r" % nym_id
Ejemplo n.º 5
0
def test_format_amount(attrs, number, expected_formatted):
    contract_stream = make_contract("../test-data/sample-contracts/btc.xml",
                                    attrs)
    myasset = asset.Asset().issue(nym.Nym().register(), contract_stream)
    actual_formatted = opentxs.OTAPI_Wrap_FormatAmount(myasset._id, number)
    assert actual_formatted == expected_formatted