Skip to content

Commit

Permalink
Update tests to accomodate required cli options, polygon-endpoint, an…
Browse files Browse the repository at this point in the history
…d use of TACoChildApplicationAgent for sampling.
  • Loading branch information
derekpierre committed Nov 14, 2023
1 parent f9fe8b3 commit 59d12d9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ContractAgency,
CoordinatorAgent,
StakingProvidersReservoir,
TACoApplicationAgent,
TACoChildApplicationAgent,
)
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import ContractRegistry
Expand Down Expand Up @@ -182,7 +182,7 @@ def mock_reservoir(
}
return StakingProvidersReservoir(addresses)

mock_agent = mock_contract_agency.get_agent(TACoApplicationAgent)
mock_agent = mock_contract_agency.get_agent(TACoChildApplicationAgent)
mock_agent.get_staking_provider_reservoir = mock_reservoir


Expand All @@ -208,6 +208,7 @@ def porter(ursulas, mock_rest_middleware, test_registry):
porter = Porter(
domain=TEMPORARY_DOMAIN,
eth_endpoint=MOCK_ETH_PROVIDER_URI,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,
registry=test_registry,
abort_on_learning_error=True,
start_learning_now=True,
Expand Down
26 changes: 26 additions & 0 deletions tests/pre/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Iterable, Optional

import pytest
from eth_typing import ChecksumAddress
from nucypher.blockchain.eth.agents import (
StakingProvidersReservoir,
TACoApplicationAgent,
)


@pytest.fixture(scope="module", autouse=True)
def mock_sample_reservoir(testerchain, mock_contract_agency):
def mock_reservoir(
without: Optional[Iterable[ChecksumAddress]] = None, *args, **kwargs
):
addresses = {
address: 1
for address in testerchain.stake_providers_accounts
if address not in without
}
return StakingProvidersReservoir(addresses)

# TODO - this is needed for PRE Policy.enact(...) sample functionality which
# uses TACoApplication - should we change this (in `nucypher`)?
mock_agent = mock_contract_agency.get_agent(TACoApplicationAgent)
mock_agent.get_staking_provider_reservoir = mock_reservoir
28 changes: 27 additions & 1 deletion tests/test_porter_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def test_porter_cli_run_simple(click_runner, teacher_uri):
TEMPORARY_DOMAIN_NAME,
"--eth-endpoint",
TEST_ETH_PROVIDER_URI,
"--polygon-endpoint",
TEST_ETH_PROVIDER_URI,
"--teacher",
teacher_uri,
)
Expand All @@ -42,6 +44,8 @@ def test_porter_cli_run_simple(click_runner, teacher_uri):
TEMPORARY_DOMAIN_NAME,
"--eth-endpoint",
TEST_ETH_PROVIDER_URI,
"--polygon-endpoint",
TEST_ETH_PROVIDER_URI,
"--http-port",
non_default_port,
"--teacher",
Expand All @@ -60,12 +64,30 @@ def test_porter_cli_run_eth_provider_must_be_provided(click_runner, teacher_uri)
"--dry-run",
"--domain",
TEMPORARY_DOMAIN_NAME,
"--polygon-endpoint",
TEST_ETH_PROVIDER_URI,
"--teacher",
teacher_uri,
)
result = click_runner.invoke(porter_cli, porter_run_command, catch_exceptions=False)
assert result.exit_code != 0, result.output
assert f"--eth-endpoint is required" in result.output
assert "Missing option '--eth-endpoint'" in result.output


def test_porter_cli_run_polygon_provider_must_be_provided(click_runner, teacher_uri):
porter_run_command = (
"run",
"--dry-run",
"--domain",
TEMPORARY_DOMAIN_NAME,
"--eth-endpoint",
TEST_ETH_PROVIDER_URI,
"--teacher",
teacher_uri,
)
result = click_runner.invoke(porter_cli, porter_run_command, catch_exceptions=False)
assert result.exit_code != 0, result.output
assert "Missing option '--polygon-endpoint'" in result.output


def test_cli_run_with_cors_origin(click_runner, teacher_uri):
Expand All @@ -78,6 +100,8 @@ def test_cli_run_with_cors_origin(click_runner, teacher_uri):
TEMPORARY_DOMAIN_NAME,
"--eth-endpoint",
TEST_ETH_PROVIDER_URI,
"--polygon-endpoint",
TEST_ETH_PROVIDER_URI,
"--teacher",
teacher_uri,
"--allow-origins",
Expand All @@ -99,6 +123,8 @@ def test_cli_run_with_empty_string_cors_origin(click_runner, teacher_uri):
TEMPORARY_DOMAIN_NAME,
"--eth-endpoint",
TEST_ETH_PROVIDER_URI,
"--polygon-endpoint",
TEST_ETH_PROVIDER_URI,
"--teacher",
teacher_uri,
"--allow-origins",
Expand Down

0 comments on commit 59d12d9

Please sign in to comment.