Skip to content

Commit

Permalink
test: fix test causing flaky fail (#1914)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Feb 6, 2024
1 parent e979257 commit dd3da4a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
name: black
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"hypothesis-jsonschema==0.19.0", # JSON Schema fuzzer extension
],
"lint": [
"black>=23.12.1,<24", # Auto-formatter and linter
"black>=24.1.1,<25", # Auto-formatter and linter
"mypy>=1.8.0,<2", # Static type analyzer
"types-PyYAML", # Needed due to mypy typeshed
"types-requests", # Needed due to mypy typeshed
Expand Down Expand Up @@ -121,7 +121,7 @@
"eth-typing>=3.5.2,<4",
"eth-utils>=2.3.1,<3",
"py-geth>=4.2.0,<5",
"web3[tester]>=6.12.0,<7",
"web3[tester]>=6.15.1,<7",
# ** Dependencies maintained by ApeWorX **
"eip712>=0.2.3,<0.4",
"ethpm-types>=0.6.7,<0.7",
Expand Down
6 changes: 2 additions & 4 deletions src/ape/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,10 @@ def __init__(self, generator: Union[Iterator[_T], Callable[[], Iterator[_T]]]):
self.cache: List = []

@overload
def __getitem__(self, index: int) -> _T:
...
def __getitem__(self, index: int) -> _T: ...

@overload
def __getitem__(self, index: slice) -> Sequence[_T]:
...
def __getitem__(self, index: slice) -> Sequence[_T]: ...

def __getitem__(self, index: Union[int, slice]) -> Union[_T, Sequence[_T]]:
if isinstance(index, int):
Expand Down
1 change: 1 addition & 0 deletions src/ape/utils/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base non-pydantic validator utils"""

import re
from warnings import warn

Expand Down
4 changes: 1 addition & 3 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ def get_abi(_topic: HexStr) -> Optional[LogInputABICollection]:
value[struct_key] = (
self.decode_address(struct_val)
if struct_type == "address"
else HexBytes(struct_val)
if "bytes" in struct_type
else struct_val
else HexBytes(struct_val) if "bytes" in struct_type else struct_val
)
converted_arguments[key] = value

Expand Down
4 changes: 1 addition & 3 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,9 @@ def base_fee(self) -> int:
return pending_base_fee

def _get_fee_history(self, block_number: int) -> FeeHistory:
# NOTE: Have to `reward_percentiles=[]` because of this bug:
# https://github.com/ethereum/web3.py/issues/3184
try:
return self.web3.eth.fee_history(1, BlockNumber(block_number), reward_percentiles=[])
except MethodUnavailable as err:
except (MethodUnavailable, AttributeError) as err:
raise APINotImplementedError(str(err)) from err

def _get_last_base_fee(self) -> int:
Expand Down
26 changes: 18 additions & 8 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tempfile
from pathlib import Path
from typing import Dict, Union
from typing import Dict, Optional, Union

import pytest
from pydantic_settings import SettingsConfigDict
Expand All @@ -19,21 +19,30 @@
from tests.functional.conftest import PROJECT_WITH_LONG_CONTRACTS_FOLDER


def test_deployments(networks, owner, vyper_contract_container):
def test_deployments(networks_connected_to_tester, owner, vyper_contract_container, config):
networks = networks_connected_to_tester # Connection needs to lookup config.

# First, obtain a "previously-deployed" contract.
instance = vyper_contract_container.deploy(1000200000, sender=owner)
address = instance.address

# Create a config using this new contract for a "later time".
data = {
**_create_deployments(address=instance.address),
**_create_deployments(address=address, contract_name=instance.contract_type.name),
"valid_ecosystems": {"ethereum": networks.ethereum},
"valid_networks": [LOCAL_NETWORK_NAME],
}
config = DeploymentConfigCollection(root=data)
assert config.root["ethereum"]["local"][0]["address"] == instance.address
deploy_config = DeploymentConfigCollection(root=data)
assert deploy_config.root["ethereum"]["local"][0]["address"] == address

orig = config.deployments
config.deployments = deploy_config
try:
# Ensure we can reference the deployment on the contract.
deployment = vyper_contract_container.deployments[0]
finally:
config.deployments = orig

# Ensure we can reference the deployment on the project.
deployment = vyper_contract_container.deployments[0]
assert deployment.address == instance.address


Expand Down Expand Up @@ -71,13 +80,14 @@ def _create_deployments(
ecosystem_name: str = "ethereum",
network_name: str = "local",
address: Union[int, str] = "0x0C25212C557D00024B7CA3DF3238683A35541354",
contract_name: Optional[str] = "MyContract",
) -> Dict:
return {
ecosystem_name: {
network_name: [
{
"address": address,
"contract_type": "MyContract",
"contract_type": contract_name,
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ def test_base_fee(eth_tester_provider):

# NOTE: Mostly doing this to ensure we are calling the fee history
# RPC correctly. There was a bug where we were not.
with pytest.raises(APINotImplementedError):
_ = eth_tester_provider._get_fee_history(0)
actual = eth_tester_provider._get_fee_history(0)
assert "baseFeePerGas" in actual


def test_create_access_list(eth_tester_provider, vyper_contract_instance, owner):
Expand Down

0 comments on commit dd3da4a

Please sign in to comment.