Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
added syncing enpoint to graphql
Browse files Browse the repository at this point in the history
make lint happy

fix tests

fix tests

fix tests

fix tests

make lint happy
  • Loading branch information
voith committed Nov 9, 2019
1 parent a5670ab commit 2690082
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 148 deletions.
2 changes: 1 addition & 1 deletion tests/components/eth2/apis/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def test_http_server(aiohttp_raw_server, aiohttp_client, event_bus, base_d
chaindb.persist_block(genesis_block, genesis_block.__class__, fork_choice_scoring)
try:
rpc = JsonRPCServer(initialize_beacon_modules(chaindb, event_bus), chaindb, event_bus)
raw_server = await aiohttp_raw_server(handler(rpc.execute))
raw_server = await aiohttp_raw_server(handler(rpc))
client = await aiohttp_client(raw_server)

request_id = 1
Expand Down
37 changes: 19 additions & 18 deletions tests/core/graphql-rpc/test_grqphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from trinity.rpc.graph_ql.server import (
GraphQlServer,
)
from trinity.rpc.json_rpc.modules import Eth1ChainRPCModule

SIMPLE_CONTRACT_ADDRESS = b'\x88' * 20

Expand Down Expand Up @@ -95,9 +96,9 @@ def chain(chain_without_block_validation):


@pytest.fixture()
def rpc(chain, event_loop):
def rpc(chain, event_bus, event_loop):
# overrides fixture from conftest
return GraphQlServer(chain, event_loop)
return GraphQlServer(Eth1ChainRPCModule(chain, event_bus), event_loop)


@pytest.fixture
Expand Down Expand Up @@ -148,7 +149,7 @@ def genesis_state(base_genesis_state):
(
pytest.param(
build_request("{ block {number} }"),
{'result': {'block': {'number': '0x0'}}, 'errors': None},
{'data': {'block': {'number': '0x0'}}, 'errors': None},
id='eth_blockNumber'
),
pytest.param(
Expand All @@ -160,12 +161,12 @@ def genesis_state(base_genesis_state):
)
}
"""),
{'errors': None, 'result': {'estimateGas': 21000}},
{'errors': None, 'data': {'estimateGas': 21000}},
id='eth_estimateGas'
),
pytest.param(
build_request("{gasPrice}"),
{'errors': None, 'result': {'gasPrice': 1000000000}},
{'errors': None, 'data': {'gasPrice': 1000000000}},
id='eth_gasPrice'
),
pytest.param(
Expand All @@ -179,7 +180,7 @@ def genesis_state(base_genesis_state):
}
}
"""),
{'errors': None, 'result': {'account': {'balance': 0}}},
{'errors': None, 'data': {'account': {'balance': 0}}},
id='eth_getBalance'
),
pytest.param(
Expand All @@ -194,7 +195,7 @@ def genesis_state(base_genesis_state):
status
}
}"""), # noqa: W291
{'errors': None, 'result': {'call': {'data': '0x123456', 'gasUsed': 18, 'status': 1}}}
{'errors': None, 'data': {'call': {'data': '0x123456', 'gasUsed': 18, 'status': 1}}}
),
pytest.param(
build_request("""{
Expand All @@ -205,7 +206,7 @@ def genesis_state(base_genesis_state):
}"""),
{
'errors': None,
'result': {
'data': {
'block':
{
'hash': '0xdde15d36d345d0e70426a0ba36b3c449bf21fc461362c50271536f1614d9eaf3', # noqa E501
Expand All @@ -224,7 +225,7 @@ def genesis_state(base_genesis_state):
}"""),
{
'errors': None,
'result': {
'data': {
'block':
{
'hash': '0xdde15d36d345d0e70426a0ba36b3c449bf21fc461362c50271536f1614d9eaf3', # noqa: E501
Expand All @@ -240,7 +241,7 @@ def genesis_state(base_genesis_state):
transactionCount
}
}"""),
{'errors': None, 'result': {'block': {'transactionCount': '0x0'}}},
{'errors': None, 'data': {'block': {'transactionCount': '0x0'}}},
id='eth_getBlockTransactionCountByHash'
),
pytest.param(
Expand All @@ -249,7 +250,7 @@ def genesis_state(base_genesis_state):
transactionCount
}
}"""),
{'errors': None, 'result': {'block': {'transactionCount': '0x0'}}},
{'errors': None, 'data': {'block': {'transactionCount': '0x0'}}},
id='eth_getBlockTransactionCountByNumber'
),
pytest.param(
Expand All @@ -263,7 +264,7 @@ def genesis_state(base_genesis_state):
}
}
""" % encode_hex(SIMPLE_CONTRACT_ADDRESS)),
{'errors': None, 'result': {'account': {'code': encode_hex(SIMPLE_CONTRACT_CODE)}}},
{'errors': None, 'data': {'account': {'code': encode_hex(SIMPLE_CONTRACT_CODE)}}},
id='eth_getCode'
),
pytest.param(
Expand All @@ -277,7 +278,7 @@ def genesis_state(base_genesis_state):
}
}
""" % encode_hex(SIMPLE_CONTRACT_ADDRESS)),
{'errors': None, 'result': {'account': {'storage': '0x01'}}},
{'errors': None, 'data': {'account': {'storage': '0x01'}}},
id='eth_getStorageAt'
),
Expand Down Expand Up @@ -317,7 +318,7 @@ async def test_rpc_methods(
"""),
{
'errors': None,
'result': {
'data': {
'block': {
'transactionAt': {
'from': {
Expand Down Expand Up @@ -351,7 +352,7 @@ async def test_rpc_methods(
"""),
{
'errors': None,
'result': {
'data': {
'block': {
'transactionAt': {
'from': {
Expand Down Expand Up @@ -383,7 +384,7 @@ async def test_rpc_methods(
"""), # noqa: E501
{
'errors': None,
'result': {
'data': {
'transaction': {
'from': {
'address': '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b'
Expand All @@ -407,7 +408,7 @@ async def test_rpc_methods(
"""),
{
'errors': None,
'result': {
'data': {
'account': {
'transactionCount': '0x1'
}
Expand All @@ -431,7 +432,7 @@ async def test_rpc_methods(
"""), # noqa: E501
{
'errors': None,
'result': {
'data': {
'transaction': {
'from': {
'address': '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b'
Expand Down
2 changes: 1 addition & 1 deletion tests/json-fixtures-over-rpc/test_rpc_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def result_from_response(response_str):

async def call_rpc(rpc, method, params):
request = build_request(method, params)
response = await rpc.execute(request)
response = await rpc.execute_post(request)
return result_from_response(response)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
_SubParsersAction,
)
import asyncio

from typing import (
Tuple,
)
from lahja import EndpointAPI
from p2p.service import BaseService

from trinity.config import (
Eth1AppConfig,
Expand All @@ -14,6 +17,9 @@
from trinity.extensibility import (
AsyncioIsolatedComponent,
)
from trinity.rpc.http import (
HTTPServer,
)
from trinity.rpc.ipc import (
IPCServer,
)
Expand All @@ -22,6 +28,7 @@
)

from trinity.rpc.graph_ql.server import GraphQlServer
from trinity.rpc.json_rpc.modules import Eth1ChainRPCModule


class GraphQLRpcServerPlugin(AsyncioIsolatedComponent):
Expand All @@ -41,6 +48,16 @@ def configure_parser(cls, arg_parser: ArgumentParser, subparser: _SubParsersActi
action="store_true",
help="Enables the GRAPHQL-RPC Server",
)
arg_parser.add_argument(
"--enable-graphiql",
action="store_true",
help="Enables the HTTP Server that can be used to serve graphiql",
)
arg_parser.add_argument(
"--graphql-port",
default=8547,
help="Enables the GRAPHQL-RPC Server",
)

def do_start(self) -> None:
trinity_config = self.boot_info.trinity_config
Expand All @@ -49,10 +66,16 @@ def do_start(self) -> None:

db = DBClient.connect(trinity_config.database_ipc_path)
chain = chain_config.full_chain_class(db)
rpc = GraphQlServer(chain)
rpc = GraphQlServer(Eth1ChainRPCModule(chain, self.event_bus))
ipc_server = IPCServer(rpc, self.boot_info.trinity_config.graphql_ipc_path)
asyncio.ensure_future(exit_with_services(
asyncio.ensure_future(ipc_server.run())
services_to_exit: Tuple[BaseService, ...] = (
ipc_server,
self._event_bus_service,
))
asyncio.ensure_future(ipc_server.run())
)
if self.boot_info.args.enable_graphiql:
http_server = HTTPServer(rpc, port=self.boot_info.args.graphql_port)
asyncio.ensure_future(http_server.run())
services_to_exit += (http_server,)

asyncio.ensure_future(exit_with_services(*services_to_exit))
2 changes: 1 addition & 1 deletion trinity/components/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from trinity.components.builtin.fix_unclean_shutdown.component import (
FixUncleanShutdownComponent
)
from trinity.components.builtin.graphql_rpc.plugin import GraphQLRpcServerPlugin
from trinity.components.builtin.graphql_rpc.component import GraphQLRpcServerPlugin
from trinity.components.builtin.json_rpc.component import (
JsonRpcServerComponent,
)
Expand Down
14 changes: 13 additions & 1 deletion trinity/rpc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
from typing import (
Any,
Dict,
List,
)

from trinity.rpc.typing import Response


class BaseRPCServer(ABC):
@abstractmethod
async def execute(self, request: Dict[str, Any]) -> str:
async def execute_post(self, request: Dict[str, Any]) -> str:
...

@abstractmethod
async def execute_get(self, request: Dict[str, Any]) -> Response:
...

@property
@abstractmethod
def supported_methods(self) -> List[str]:
...
Loading

0 comments on commit 2690082

Please sign in to comment.