Skip to content

Commit

Permalink
fix: issues found from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jun 19, 2024
1 parent e0e4726 commit fb6792a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
14 changes: 9 additions & 5 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def networks(self) -> dict[str, "NetworkAPI"]:
custom_networks: list[dict] = [
n
for n in self.network_manager.custom_networks
if (n["ecosystem"] or self.network_manager.default_ecosystem.name) == self.name
if n.get("ecosystem", self.network_manager.default_ecosystem.name) == self.name
]

# Ensure forks are added automatically for custom networks.
Expand Down Expand Up @@ -276,8 +276,11 @@ def networks(self) -> dict[str, "NetworkAPI"]:
network_type = create_network_type(
custom_net["chain_id"], custom_net["chain_id"], is_fork=is_fork
)
if "request_header" not in custom_net:
custom_net["request_header"] = self.request_header

network_api = network_type.model_validate(custom_net)
network_api._default_provider = custom_net["default_provider"]
network_api._default_provider = custom_net.get("default_provider", "node")
network_api._is_custom = True
networks[net_name] = network_api

Expand Down Expand Up @@ -504,15 +507,16 @@ def get_network(self, network_name: str) -> "NetworkAPI":
"""

names = {network_name, network_name.replace("-", "_"), network_name.replace("_", "-")}
networks = self.networks
for name in names:
if name in self.networks:
return self.networks[name]
if name in networks:
return networks[name]

elif name == "custom":
# Is an adhoc-custom network NOT from config.
return self.custom_network

raise NetworkNotFoundError(network_name, ecosystem=self.name, options=self.networks)
raise NetworkNotFoundError(network_name, ecosystem=self.name, options=networks)

def get_network_data(
self, network_name: str, provider_filter: Optional[Collection[str]] = None
Expand Down
8 changes: 6 additions & 2 deletions src/ape/managers/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,14 @@ def outgoing(self) -> Iterator[ReceiptAPI]:
# TODO: Add ephemeral network sessional history to `ape-cache` instead,
# and remove this (replace with `yield from iter(self[:len(self)])`)
for receipt in self.sessional:
if receipt.nonce < start_nonce:
if receipt.nonce is None:
# Not an on-chain receipt? idk - has only seen as anomaly in tests.
continue

elif receipt.nonce < start_nonce:
raise QueryEngineError("Sessional history corrupted")

if receipt.nonce > start_nonce:
elif receipt.nonce > start_nonce:
# NOTE: There's a gap in our sessional history, so fetch from query engine
yield from iter(self[start_nonce : receipt.nonce + 1]) # noqa: E203

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def wrapper(fn):
compiler = ape.compilers.get_compiler(name)
if compiler:

def test_skip_from_compiler():
def test_skip_from_compiler(*args, **kwargs):
pytest.mark.skip(msg_f.format(name))

# NOTE: By returning a function, we avoid a collection warning.
Expand Down
7 changes: 3 additions & 4 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,9 @@ def test_network_gas_limit_invalid_numeric_string(project):
Test that using hex strings for a network's gas_limit config must be
prefixed with '0x'
"""
eth_config = _sepolia_with_gas_limit("4D2")
with project.temp_config(**eth_config):
with pytest.raises(AttributeError, match="Gas limit hex str must include '0x' prefix."):
_ = project.config.ethereum
sep_cfg = _sepolia_with_gas_limit("4D2")["ethereum"]["sepolia"]
with pytest.raises(ValidationError, match="Gas limit hex str must include '0x' prefix."):
NetworkConfig.model_validate(sep_cfg)


def test_dependencies(project_with_dependency_config):
Expand Down
9 changes: 6 additions & 3 deletions tests/functional/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,10 @@ def test_compile(self, project):
api = LocalDependency(local=path, name="ooga", version="1.0.0")
dependency = Dependency(api, project)
contract_path = dependency.project.contracts_folder / "CCC.json"
contract_path.parent.mkdir(exist_ok=True, parents=True)
contract_path.write_text(
'[{"name":"foo","type":"fallback", "stateMutability":"nonpayable"}]'
'[{"name":"foo","type":"fallback", "stateMutability":"nonpayable"}]',
encoding="utf8",
)
result = dependency.compile()
assert len(result) == 1
Expand All @@ -630,9 +632,10 @@ def test_compile_missing_compilers(self, project, ape_caplog):
api = LocalDependency(local=path, name="ooga2", version="1.1.0")
dependency = Dependency(api, project)
sol_path = dependency.project.contracts_folder / "Sol.sol"
sol_path.write_text("// Sol")
sol_path.parent.mkdir(exist_ok=True, parents=True)
sol_path.write_text("// Sol", encoding="utf8")
vy_path = dependency.project.contracts_folder / "Vy.vy"
vy_path.write_text("# Vy")
vy_path.write_text("# Vy", encoding="utf8")
expected = (
"Compiling dependency produced no contract types. "
"Try installing 'ape-solidity' or 'ape-vyper'."
Expand Down

0 comments on commit fb6792a

Please sign in to comment.