Example #1
0
def w3(signing_account):
    """
    Web3 object connected to the ethereum tester chain
    """
    chain = eth_tester.EthereumTester(eth_tester.PyEVMBackend())
    chain.send_transaction({
        "from": chain.get_accounts()[0],
        "to": signing_account.address,
        "gas": 21000,
        "value": 10_000_000,
    })
    w3 = Web3(EthereumTesterProvider(chain))
    w3.middleware_onion.add(parity_next_nonce)
    signing_middleware.install_signing_middleware(w3, signing_account)
    return w3
def chain(pytestconfig):
    """
    The running ethereum tester chain
    Can be used as to manipulate the chain, e.g. chain.mine_block()
    see https://github.com/ethereum/eth-tester for more
    """
    expose_port = pytestconfig.getoption(EXPOSE_RPC_OPTION)
    if expose_port:
        if is_port_in_use(expose_port):
            raise EnvironmentError(
                f"The port {expose_port} is already in use on the machine.")
        # redirect stdout because otherwise the application prints every request and result
        # Get the eth-tester-rpc application
        application = get_application()
        rpc = application.rpc_methods

        # Remove the printing of every rpc replies to avoid flooding the tests outputs
        application = silent_stdout(application)
        application.rpc_methods = rpc

        # Start the server so that we can use rpc on http://localhost:expose_port
        # Silence the logging of every request from the handler to avoid flooding tests outputs
        class NoLoggingRequestHandler(WSGIRequestHandler):
            def log_request(self, code="-", size="-"):
                pass

        server = make_server(
            "localhost",
            int(expose_port),
            application,
            handler_class=NoLoggingRequestHandler,
        )
        spawn(server.serve_forever)

        # yield the eth_tester chain
        yield application.rpc_methods.client
    else:
        yield eth_tester.EthereumTester(eth_tester.PyEVMBackend())

    if pytestconfig.getoption(EXPOSE_RPC_OPTION):
        try:
            server.stop()
        except AttributeError:
            server.shutdown()
Example #3
0
def ethereum_tester():
    """Returns an instance of an Ethereum tester"""
    tester = eth_tester.EthereumTester(eth_tester.PyEVMBackend())
    return tester
Example #4
0
def tester():
    return eth_tester.EthereumTester(eth_tester.PyEVMBackend())
Example #5
0
def chain():
    """
    The running ethereum tester chain
    """
    return eth_tester.EthereumTester(eth_tester.PyEVMBackend())