Пример #1
0
def main():
    factory = Factory(read_config_file("solitude.yaml"))
    server = factory.create_server()
    server.start()
    endpoint = server.endpoint
    compiled_contracts = factory.get_objectlist()

    try:
        client1 = factory.create_client(endpoint=server.endpoint)
        client1.update_contracts(compiled_contracts)
        shop_address = deploy(client1)
        thread_rescue = threading.Thread(target=rescue_cats,
                                         args=(client1, shop_address))
        thread_rescue.start()

        client2 = factory.create_client(endpoint=server.endpoint)
        client2.update_contracts(compiled_contracts)
        thread_adopt = threading.Thread(target=adopt_cats,
                                        args=(client2, shop_address))
        thread_adopt.start()

        thread_rescue.join()
        thread_adopt.join()
    finally:
        server.stop()
Пример #2
0
def SOL_new(
        cfg: Union[dict, str]="solitude.yaml",
        relative_to: Optional[str]=None) -> TestingContext:
    """Create a new testing context

    :param cfg: configuration dictionary or path. If `cfg` is a string, it is interpreted
        as a path to the yaml or json file containing the configuration dictionary.
    :param relative_to: a path, or None; if `cfg` is a path and `relative_to` is not None,
        make the path of the configuration file `cfg` relative to the parent directory of
        `relative_to`. This can be used with `__file__` to make the configuration file
        location relative to the test script.
    """
    with RaiseForParam("cfg"):
        type_assert(cfg, (dict, str))

    if isinstance(cfg, str):
        path = cfg
        if relative_to is not None:
            rel_dir = os.path.dirname(
                os.path.abspath(relative_to))
            path = os.path.join(rel_dir, path)
        cfg_dict = read_config_file(path)
    else:
        cfg_dict = cfg

    try:
        return TestingContext(cfg_dict)
    except Exception:
        kill_all_servers()
        raise
Пример #3
0
def main(args):
    Color.enable()

    factory = Factory(read_config_file(args.config))
    client = factory.create_client()
    client.update_contracts(factory.get_objectlist())
    debugger = EvmDebugCore(client, args.txhash)
    printer = TablePrinter([
        ("INDEX", 6),
        ("PC", 6),
        ("JU", 2),
        ("OP", 8),
        ("GAS", 8),
        ("FILE", -30),
        ("SOURCE", 0)
    ])
    printer.write_header()

    while True:
        debugger.step()
        s = debugger.get_step()
        if not s.valid:
            break
        frames = debugger.get_frames()

        line = Color.wrap(InteractiveDebuggerOI.get_source_lines(s.step, color="green"))
        printer.write([
            s.step.index,
            s.step.pc,
            s.step.jumptype,
            s.step.op,
            s.step.gas,
            "%s:%d" % (str(s.step.code.unitname).split(os.path.sep)[-1], s.step.code.line_index),
            line])

        if args.variables:
            for var in debugger.get_values().values():
                print(var)
        if args.frames:
            PRE = (printer.width * " ")
            for f in frames:
                if f.prev is not None and f.cur is not None:
                    prev_line = Color.wrap(InteractiveDebuggerOI.get_source_lines(f.prev, strip=True, color="blue"))
                    cur_line = Color.wrap(InteractiveDebuggerOI.get_source_lines(f.cur, strip=True, color="blue"))
                    if f.function is not None:
                        print(PRE + str(f.function))
                    else:
                        print((printer.width * " ") + prev_line + " => " + cur_line)
        if args.stack:
            print(s.step.stack)
        if args.memory:
            print(s.step.memory)
        if args.storage:
            print(s.step.storage)
Пример #4
0
def main(args):
    Color.enable()
    factory = Factory(read_config_file(args.config))
    client = factory.create_client()
    client.update_contracts(factory.get_objectlist())

    idbg = InteractiveDebuggerCLI(InteractiveDebuggerOI(args.txhash, client))
    if args.ex:
        for command in args.ex:
            for c in command.split(";"):
                print(idbg.prompt + c)
                result = idbg.onecmd(c.strip())
                if result:
                    return
    idbg.cmdloop()
Пример #5
0
def main():
    factory = Factory(read_config_file("solitude.yaml"))
    server = factory.create_server()
    server.start()
    endpoint = server.endpoint
    try:
        client1 = factory.create_client(endpoint=server.endpoint)
        client1.update_contracts(factory.get_objectlist())
        app.shelter = deploy(client1)
        shelter_address = app.shelter.address
        thread_rescue = threading.Thread(target=rescue_cats, args=(client1, shelter_address))
        thread_rescue.start()

        app.run(port=HTTP_SERVER_PORT)
    except KeyboardInterrupt:
        thread_rescue.join()
        server.stop()
        print("Quit")
Пример #6
0
def main():
    factory = Factory(read_config_file("solitude.yaml"))
    server = factory.create_server()
    server.start()
    try:
        client = factory.create_client()
        client.update_contracts(factory.get_objectlist())
        owner = client.address(0)
        george = client.address(1)

        with client.account(owner):
            token = client.deploy("MyToken", args=("Token", "TKN", 0))
            txinfo = token.transact_sync("mint", owner, 1000)
            print_txinfo(txinfo)
            txinfo = token.transact_sync("transfer", george, 100)
            print_txinfo(txinfo)
        print("Ctrl-C to quit")
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("")
    finally:
        server.stop()