Skip to content

Commit cb0a2bb

Browse files
cryptomentalcburgdorf
authored andcommitted
test_trinity_cli: Add Trinity attach web3 interaction test.
The test attaches to running Trinity and interacts with the console. Verifies that the w3 object is available and is able to read network version. Bases on Christoph Burgdorf's [[email protected]] test skeleton. Fixes: ethereum#1472
1 parent 2e674ce commit cb0a2bb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
],
5353
'test': [
5454
"hypothesis==3.69.5",
55+
"pexpect>=4.6, <5",
5556
# pinned to <3.7 until async fixtures work again
5657
# https://github.com/pytest-dev/pytest-asyncio/issues/89
5758
"pytest>=3.6,<3.7",

tests/trinity/integration/test_trinity_cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
import pexpect
13
import pytest
24

35
from trinity.tools.async_process_runner import AsyncProcessRunner
@@ -109,6 +111,34 @@ async def test_light_boot(async_process_runner, command):
109111
})
110112

111113

114+
@pytest.mark.parametrize(
115+
'command',
116+
(
117+
('trinity', ),
118+
)
119+
)
120+
@pytest.mark.asyncio
121+
async def test_web3(command, async_process_runner):
122+
await async_process_runner.run(command, timeout_sec=30)
123+
assert await contains_all(async_process_runner.stderr, {
124+
"Started DB server process",
125+
"Started networking process",
126+
"IPC started at",
127+
})
128+
129+
attached_trinity = pexpect.spawn('trinity', ['attach'], logfile=sys.stdout)
130+
try:
131+
attached_trinity.expect("An instance of Web3 connected to the running chain")
132+
attached_trinity.sendline("w3.net.version")
133+
attached_trinity.expect("'1'")
134+
attached_trinity.sendline("w3")
135+
attached_trinity.expect("web3.main.Web3")
136+
except pexpect.TIMEOUT:
137+
raise Exception("Trinity attach timeout")
138+
finally:
139+
attached_trinity.close()
140+
141+
112142
@pytest.mark.parametrize(
113143
'command',
114144
(

0 commit comments

Comments
 (0)