Skip to content

Commit

Permalink
test: modify host when launching temp rpc node to demonstrate eth-bro…
Browse files Browse the repository at this point in the history
…wnie#1533

Modify fixtures and tests to use a different host ip when launching a temporary rpc network node. This demonstrates that the host parameter is not respected when launching the node.
  • Loading branch information
danceratopz committed May 17, 2022
1 parent 54c1151 commit d596cb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
24 changes: 19 additions & 5 deletions tests/network/rpc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ def original_port(xdist_id):
return 8545 + xdist_id


@pytest.fixture(scope="session")
def temp_host(xdist_id):
return "127.0.0.2"


@pytest.fixture(scope="session")
def original_host():
return "127.0.0.1"


@pytest.fixture(scope="module")
def _no_rpc_setup(rpc, chain, web3, temp_port, original_port, network_name):
def _no_rpc_setup(
rpc, chain, web3, temp_port, original_port, temp_host, original_host, network_name
):
CONFIG.networks[network_name]["cmd_settings"]["port"] = temp_port
web3.connect(f"http://127.0.0.1:{temp_port}")
CONFIG.networks[network_name]["host"] = f"http://{temp_host}"
web3.connect(f"http://{temp_host}:{temp_port}")
proc = rpc.process
reset_id = chain._reset_id
rpc.process = None
Expand All @@ -29,7 +42,8 @@ def _no_rpc_setup(rpc, chain, web3, temp_port, original_port, network_name):
_notify_registry(0)
yield
CONFIG.networks[network_name]["cmd_settings"]["port"] = original_port
web3.connect(f"http://127.0.0.1:{original_port}")
# CONFIG.networks[network_name]["host"] = temp_host
web3.connect(f"http://{original_host}:{original_port}")
# rpc.launch = rpc._launch
rpc.kill(False)
_notify_registry(0)
Expand All @@ -44,7 +58,7 @@ def no_rpc(_no_rpc_setup, rpc):


@pytest.fixture
def temp_rpc(no_rpc, temp_port):
def temp_rpc(no_rpc, temp_port, temp_host):
if not no_rpc.process or not no_rpc.is_active():
no_rpc.launch("ganache-cli", port=temp_port)
no_rpc.launch("ganache-cli", port=temp_port, host=temp_host)
yield no_rpc
7 changes: 4 additions & 3 deletions tests/network/rpc/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ def test_launch_process_fails(no_rpc):
no_rpc.launch("ganache-cli --help")


def test_launch(no_rpc, temp_port):
def test_launch(no_rpc, temp_port, temp_host):
assert not no_rpc.is_active()
assert not no_rpc.is_child()
no_rpc.launch("ganache-cli", port=temp_port)
no_rpc.launch("ganache-cli", port=temp_port, host=temp_host)
assert no_rpc.is_active()
assert no_rpc.is_child()


def test_launch_with_mnemonic(no_rpc, temp_port):
def test_launch_with_mnemonic(no_rpc, temp_port, temp_host):
no_rpc.kill(False)
no_rpc.launch(
"ganache-cli",
port=temp_port,
host=temp_host,
mnemonic="patient rude simple dog close planet oval animal hunt sketch suspect slim",
)
assert brownie.network.accounts[0] == "0x7cB87a59C85a0c6d8E2953ed54f1c9E4C28E25E5"
Expand Down

0 comments on commit d596cb2

Please sign in to comment.