This repository has been archived by the owner on May 13, 2024. It is now read-only.
forked from evmos/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,85 @@ | ||
# import asyncio | ||
# import json | ||
# from collections import defaultdict | ||
import asyncio | ||
import json | ||
from collections import defaultdict | ||
|
||
# import websockets | ||
# from pystarport import ports | ||
import websockets | ||
from pystarport import ports | ||
|
||
|
||
# def test_single_request_netversion(ethermint): | ||
# ethermint.use_websocket() | ||
# eth_ws = ethermint.w3.provider | ||
def test_single_request_netversion(ethermint): | ||
ethermint.use_websocket() | ||
eth_ws = ethermint.w3.provider | ||
|
||
# response = eth_ws.make_request("net_version", []) | ||
response = eth_ws.make_request("net_version", []) | ||
|
||
# # net_version should be 9000 | ||
# assert response["result"] == "9000", "got " + response["result"] + ", expected 9000" | ||
# net_version should be 9000 | ||
assert response["result"] == "9000", "got " + response["result"] + ", expected 9000" | ||
|
||
|
||
# # note: | ||
# # batch requests still not implemented in web3.py | ||
# # todo: follow https://github.com/ethereum/web3.py/issues/832, add tests when complete | ||
# note: | ||
# batch requests still not implemented in web3.py | ||
# todo: follow https://github.com/ethereum/web3.py/issues/832, add tests when complete | ||
|
||
# # eth_subscribe and eth_unsubscribe support still not implemented in web3.py | ||
# # todo: follow https://github.com/ethereum/web3.py/issues/1402, add tests when complete | ||
# eth_subscribe and eth_unsubscribe support still not implemented in web3.py | ||
# todo: follow https://github.com/ethereum/web3.py/issues/1402, add tests when complete | ||
|
||
|
||
# class Client: | ||
# def __init__(self, ws): | ||
# self._ws = ws | ||
# self._subs = defaultdict(asyncio.Queue) | ||
# self._rsps = defaultdict(asyncio.Queue) | ||
class Client: | ||
def __init__(self, ws): | ||
self._ws = ws | ||
self._subs = defaultdict(asyncio.Queue) | ||
self._rsps = defaultdict(asyncio.Queue) | ||
|
||
# async def receive_loop(self): | ||
# while True: | ||
# msg = json.loads(await self._ws.recv()) | ||
# if "id" in msg: | ||
# # responses | ||
# await self._rsps[msg["id"]].put(msg) | ||
async def receive_loop(self): | ||
while True: | ||
msg = json.loads(await self._ws.recv()) | ||
if "id" in msg: | ||
# responses | ||
await self._rsps[msg["id"]].put(msg) | ||
|
||
# async def recv_response(self, rpcid): | ||
# rsp = await self._rsps[rpcid].get() | ||
# del self._rsps[rpcid] | ||
# return rsp | ||
async def recv_response(self, rpcid): | ||
rsp = await self._rsps[rpcid].get() | ||
del self._rsps[rpcid] | ||
return rsp | ||
|
||
# async def send(self, id): | ||
# await self._ws.send( | ||
# json.dumps({"id": id, "method": "web3_clientVersion", "params": []}) | ||
# ) | ||
# rsp = await self.recv_response(id) | ||
# assert "error" not in rsp | ||
async def send(self, id): | ||
await self._ws.send( | ||
json.dumps({"id": id, "method": "web3_clientVersion", "params": []}) | ||
) | ||
rsp = await self.recv_response(id) | ||
assert "error" not in rsp | ||
|
||
|
||
# def test_web3_client_version(ethermint): | ||
# ethermint_ws = ethermint.copy() | ||
# ethermint_ws.use_websocket() | ||
# port = ethermint_ws.base_port(0) | ||
# url = f"ws://127.0.0.1:{ports.evmrpc_ws_port(port)}" | ||
# loop = asyncio.get_event_loop() | ||
def test_web3_client_version(ethermint): | ||
ethermint_ws = ethermint.copy() | ||
ethermint_ws.use_websocket() | ||
port = ethermint_ws.base_port(0) | ||
url = f"ws://127.0.0.1:{ports.evmrpc_ws_port(port)}" | ||
loop = asyncio.get_event_loop() | ||
|
||
# async def async_test(): | ||
# async with websockets.connect(url) as ws: | ||
# c = Client(ws) | ||
# t = asyncio.create_task(c.receive_loop()) | ||
# # run send concurrently | ||
# await asyncio.gather(*[c.send(id) for id in ["0", 1, 2.0]]) | ||
# t.cancel() | ||
# try: | ||
# await t | ||
# except asyncio.CancelledError: | ||
# # allow retry | ||
# pass | ||
async def async_test(): | ||
async with websockets.connect(url) as ws: | ||
c = Client(ws) | ||
t = asyncio.create_task(c.receive_loop()) | ||
# run send concurrently | ||
await asyncio.gather(*[c.send(id) for id in ["0", 1, 2.0]]) | ||
t.cancel() | ||
try: | ||
await t | ||
except asyncio.CancelledError: | ||
# allow retry | ||
pass | ||
|
||
# loop.run_until_complete(async_test()) | ||
loop.run_until_complete(async_test()) | ||
|
||
|
||
# def test_batch_request_netversion(ethermint): | ||
# return | ||
def test_batch_request_netversion(ethermint): | ||
return | ||
|
||
|
||
# def test_ws_subscribe_log(ethermint): | ||
# return | ||
def test_ws_subscribe_log(ethermint): | ||
return | ||
|
||
|
||
# def test_ws_subscribe_newheads(ethermint): | ||
# return | ||
def test_ws_subscribe_newheads(ethermint): | ||
return |