Example #1
0
def server(tool_ganache):
    server = ETHTestServer(port=8545,
                           executable=tool_ganache.get("ganache-cli"))
    server.start()
    yield server
    server.stop()
    kill_all_servers()
Example #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
Example #3
0
def sol():
    """pytest fixture for a testing context configured with the default
    configuration file, solitude.yaml.
    """
    try:
        ctx = SOL_new()
        yield ctx
        ctx.teardown()
    finally:
        kill_all_servers()
Example #4
0
def main(args):
    cfg = read_config_file(args.config)
    if args.port > 0:
        cfg["Server.Port"] = args.port
    factory = Factory(cfg)
    server = factory.create_server()
    try:
        server.start()
        print("Server started at: %s" % server.endpoint)
        print("Ctrl-C to quit")
        try:
            while True:
                time.sleep(0.1)
        except KeyboardInterrupt:
            pass
        print("Shutdown...")
        server.stop()
    finally:
        kill_all_servers()
Example #5
0
def sol(request, tooldir):
    solc = Solc(tooldir=tooldir, version=SOLIDITY_VERSION)
    if not solc.have():
        solc.add()
    ganache = GanacheCli(tooldir=tooldir, version=GANACHE_VERSION)
    if not ganache.have():
        ganache.add()
    cfg = make_default_config()
    cfg["Tools.Directory"] = tooldir
    cfg["Tools.Solc.Version"] = SOLIDITY_VERSION
    cfg["Tools.GanacheCli.Version"] = GANACHE_VERSION
    cfg["Project.SourceDir"] = None
    cfg["Project.ObjectDir"] = None
    cfg["Server.Port"] = 8700
    cfg["Testing.RunServer"] = True
    try:
        ctx = SOL_new(cfg)
        yield ctx
        ctx.teardown()
    finally:
        kill_all_servers()