# Path: hydrachain/app.py
# def app():
#     pyethapp_app.app()


import logging
import time
import pytest
import random
import gevent
            import traceback
from threading import Thread
from click.testing import CliRunner
from hydrachain import app
from pyethapp.rpc_client import JSONRPCClient
from requests.exceptions import ConnectionError
from ethereum import slogging
            traceback.print_exc()
            self.log.exception("Exception in test thread")
        finally:
            self.evt.set()
            self.finished = True


@pytest.mark.parametrize('gasprice', (0, 1))
@pytest.mark.xfail(reason="the test result is non-deterministic. fixme!")  # FIXME
def test_example(gasprice, caplog):
    rand_port = random.randint(4000, 5000)
    if caplog:
        caplog.set_level(logging.DEBUG)
    # Start thread that will communicate to the app ran by CliRunner
    evt = gevent.event.Event()
    t = TestDriverThread(gasprice=gasprice, evt=evt, port=rand_port)
    t.setDaemon(True)
    t.start()

    # Stop app after testdriverthread is completed
    def mock_serve_until_stopped(*apps):
        evt.wait()
        for app_ in apps:
            app_.stop()

    app.serve_until_stopped = mock_serve_until_stopped

    runner = CliRunner()
    with runner.isolated_filesystem():
        datadir = 'datadir{}'.format(gasprice)

# Path: hydrachain/app.py
# def app():
#     pyethapp_app.app()


# Path: hydrachain/tests/test_working_app.py
import logging
import time
import pytest
import random
import gevent
            import traceback
from threading import Thread
from click.testing import CliRunner
from hydrachain import app
from pyethapp.rpc_client import JSONRPCClient
from requests.exceptions import ConnectionError
from ethereum import slogging

            traceback.print_exc()
            self.log.exception("Exception in test thread")
        finally:
            self.evt.set()
            self.finished = True


@pytest.mark.parametrize('gasprice', (0, 1))
@pytest.mark.xfail(reason="the test result is non-deterministic. fixme!")  # FIXME
def test_example(gasprice, caplog):
    rand_port = random.randint(4000, 5000)
    if caplog:
        caplog.set_level(logging.DEBUG)
    # Start thread that will communicate to the app ran by CliRunner
    evt = gevent.event.Event()
    t = TestDriverThread(gasprice=gasprice, evt=evt, port=rand_port)
    t.setDaemon(True)
    t.start()

    # Stop app after testdriverthread is completed
    def mock_serve_until_stopped(*apps):
        evt.wait()
        for app_ in apps:
            app_.stop()

    app.serve_until_stopped = mock_serve_until_stopped

    runner = CliRunner()
    with runner.isolated_filesystem():
        datadir = 'datadir{}'.format(gasprice)

        runner.invoke(app.pyethapp_app.app, ['-d', datadir,