-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move 2 tests to new paradigm + start writing new TestBase
- Loading branch information
1 parent
ac13c51
commit 9ea5c7c
Showing
3 changed files
with
63 additions
and
48 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,28 +1,22 @@ | ||
from pyrum import SubprocessConn, Rumor | ||
import trio | ||
from .utils import with_rumor | ||
|
||
@with_rumor | ||
async def run(rumor, args): | ||
try: | ||
await rumor.host.start() | ||
|
||
async def run(args): | ||
async with SubprocessConn(cmd='rumor bare') as conn: | ||
async with trio.open_nursery() as nursery: | ||
try: | ||
rumor = Rumor(conn, nursery) | ||
await rumor.host.start() | ||
# TODO: check type of result | ||
enr = await rumor.enr.make() | ||
await rumor.dv5.run(args['enr']) | ||
|
||
# TODO: check type of result | ||
enr = await rumor.enr.make() | ||
# TODO: result validation | ||
result = await rumor.dv5.ping(target=args['enr']) | ||
# TODO: result validation | ||
result = await rumor.dv5.lookup(target=args['enr') | ||
|
||
await rumor.dv5.run(args['enr']) | ||
await rumor.dv5.cancel() | ||
|
||
# TODO: result validation | ||
result = await rumor.dv5.ping(target=args['enr']) | ||
return 0 | ||
|
||
# TODO: result validation | ||
result = await rumor.dv5.lookup(target=args['enr') | ||
|
||
await rumor.dv5.cancel() | ||
|
||
return (0, None) | ||
|
||
finally: | ||
nursery.cancel_scope.cancel() | ||
except: | ||
return 1 |
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,34 +1,28 @@ | ||
import sys | ||
|
||
import trio | ||
from eth2spec.utils.ssz.ssz_typing import uint64 | ||
from pyrum import SubprocessConn, Rumor | ||
from sclients import connect_rumor | ||
|
||
from ..utils import * | ||
|
||
from lib.console import ConsoleWriter | ||
from ..utils import parse_response, with_rumor | ||
|
||
async def test_ping(enr): | ||
async with SubprocessConn(cmd='rumor bare') as conn: | ||
async with trio.open_nursery() as nursery: | ||
rumor = Rumor(conn, nursery) | ||
peer_id = await connect_rumor(rumor, enr) | ||
|
||
for i in range(5): | ||
req = uint64(i).encode_bytes().hex() | ||
resp = await rumor.rpc.ping.req.raw(peer_id, req, raw=True, compression='snappy') | ||
resp_data = parse_response(resp) | ||
@with_rumor | ||
async def run(rumor, args): | ||
peer_id = await connect_rumor(rumor, args['enr']) | ||
|
||
pong = uint64.decode_bytes(bytes.fromhex(resp_data)) | ||
return_code = 0 | ||
for i in range(5): | ||
req = uint64(i).encode_bytes().hex() | ||
resp = await rumor.rpc.ping.req.raw(peer_id, req, raw=True, compression='snappy') | ||
(rc, resp_data) = parse_response(resp) | ||
if rc != 0: | ||
return_code = rc | ||
continue | ||
|
||
if not isinstance(pong, int) or pong < 0: | ||
print( | ||
f'ping -- invalid ping response: {pong}', | ||
file=sys.stderr | ||
) | ||
pong = uint64.decode_bytes(bytes.fromhex(resp_data)) | ||
|
||
nursery.cancel_scope.cancel() | ||
if not isinstance(pong, int) or pong < 0: | ||
return_code = 1 | ||
|
||
if __name__ == '__main__': | ||
args = parse_args('--enr') | ||
trio.run(test_ping, args.enr) | ||
return return_code |
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