Skip to content

Commit 855fafc

Browse files
authored
fix: issue where mistakenly said EthTester can handle fork networks [APE-1392] (#21)
1 parent 163e726 commit 855fafc

File tree

8 files changed

+74
-31
lines changed

8 files changed

+74
-31
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.2.0
3+
rev: v4.4.0
44
hooks:
55
- id: check-yaml
66

@@ -10,24 +10,24 @@ repos:
1010
- id: isort
1111

1212
- repo: https://github.com/psf/black
13-
rev: 23.3.0
13+
rev: 23.9.1
1414
hooks:
1515
- id: black
1616
name: black
1717

1818
- repo: https://github.com/pycqa/flake8
19-
rev: 6.0.0
19+
rev: 6.1.0
2020
hooks:
2121
- id: flake8
2222

2323
- repo: https://github.com/pre-commit/mirrors-mypy
24-
rev: v0.991
24+
rev: v1.5.1
2525
hooks:
2626
- id: mypy
2727
additional_dependencies: [types-setuptools, pydantic]
2828

2929
- repo: https://github.com/executablebooks/mdformat
30-
rev: 0.7.14
30+
rev: 0.7.17
3131
hooks:
3232
- id: mdformat
3333
additional_dependencies: [mdformat-gfm, mdformat-frontmatter]

ape_polygon/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ def networks():
3131
def providers():
3232
for network_name in NETWORKS:
3333
yield "polygon", network_name, GethProvider
34-
yield "polygon", f"{network_name}-fork", LocalProvider
3534

3635
yield "polygon", LOCAL_NETWORK_NAME, LocalProvider

ape_polygon/ecosystem.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ def _create_network_config(
2222

2323
def _create_local_config(**kwargs) -> NetworkConfig:
2424
return _create_network_config(
25+
block_time=0,
26+
default_provider=kwargs.pop("default_provider", None),
27+
gas_limit="max",
2528
required_confirmations=0,
26-
default_provider="test",
2729
transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT,
28-
gas_limit="max",
2930
**kwargs,
3031
)
3132

@@ -35,7 +36,7 @@ class PolygonConfig(PluginConfig):
3536
mainnet_fork: NetworkConfig = _create_local_config()
3637
mumbai: NetworkConfig = _create_network_config()
3738
mumbai_fork: NetworkConfig = _create_local_config()
38-
local: NetworkConfig = _create_local_config()
39+
local: NetworkConfig = _create_local_config(default_provider="test")
3940
default_network: str = LOCAL_NETWORK_NAME
4041

4142

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=51.1.1", "wheel", "setuptools_scm[toml]>=5.0"]
2+
requires = ["setuptools>=51.1.1", "wheel", "setuptools_scm[toml]>=5.0,<8"]
33

44
[tool.mypy]
55
exclude = "build/"

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"hypothesis>=6.2.0,<7", # Strategy-based fuzzer
1111
],
1212
"lint": [
13-
"black>=23.3.0,<24", # Auto-formatter and linter
14-
"mypy>=0.991,<1", # Static type analyzer
13+
"black>=23.9.1,<24", # Auto-formatter and linter
14+
"mypy>=1.5.1,<2", # Static type analyzer
1515
"types-setuptools", # Needed due to mypy typeshed
16-
"flake8>=6.0.0,<7", # Style linter
16+
"flake8>=6.1.0,<7", # Style linter
1717
"isort>=5.10.1,<6", # Import sorting linter
18-
"mdformat>=0.7.16", # Auto-formatter for markdown
18+
"mdformat>=0.7.17", # Auto-formatter for markdown
1919
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
2020
"mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates
2121
],

tests/conftest.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import ape
22
import pytest
3-
from ape._cli import cli as ape_cli
4-
from click.testing import CliRunner
53

64

75
@pytest.fixture
@@ -15,15 +13,14 @@ def accounts():
1513

1614

1715
@pytest.fixture
18-
def runner():
19-
return CliRunner()
20-
21-
22-
@pytest.fixture
23-
def cli():
24-
return ape_cli
16+
def polygon(networks):
17+
return networks.polygon
2518

2619

2720
@pytest.fixture
28-
def polygon(networks):
29-
return networks.polygon
21+
def eth_tester_provider():
22+
if not ape.networks.active_provider or ape.networks.provider.name != "test":
23+
with ape.networks.polygon.local.use_provider("test") as provider:
24+
yield provider
25+
else:
26+
yield ape.networks.provider

tests/test_ecosystem.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
import pytest
22
from ape_ethereum.transactions import TransactionType
3+
from ethpm_types.abi import MethodABI
34

45

5-
@pytest.mark.parametrize("type", (0, "0x0"))
6-
def test_create_transaction(polygon, type):
7-
with polygon.local.use_provider("test"):
8-
txn = polygon.create_transaction(type=type)
9-
assert txn.type == TransactionType.STATIC.value
6+
def test_gas_limit(polygon):
7+
assert polygon.config.local.gas_limit == "max"
8+
9+
10+
# NOTE: None because we want to show the default is DYNAMIC
11+
@pytest.mark.parametrize("tx_type", (None, 2, "0x2"))
12+
def test_create_transaction(polygon, tx_type, eth_tester_provider):
13+
tx = polygon.create_transaction(type=tx_type)
14+
assert tx.type == TransactionType.DYNAMIC.value
15+
assert tx.gas_limit == eth_tester_provider.max_gas
16+
17+
18+
@pytest.mark.parametrize(
19+
"tx_type",
20+
(
21+
TransactionType.STATIC.value,
22+
TransactionType.DYNAMIC.value,
23+
),
24+
)
25+
def test_encode_transaction(tx_type, polygon, eth_tester_provider):
26+
abi = MethodABI.parse_obj(
27+
{
28+
"type": "function",
29+
"name": "fooAndBar",
30+
"stateMutability": "nonpayable",
31+
"inputs": [],
32+
"outputs": [],
33+
}
34+
)
35+
address = "0x274b028b03A250cA03644E6c578D81f019eE1323"
36+
actual = polygon.encode_transaction(address, abi, sender=address, type=tx_type)
37+
assert actual.gas_limit == eth_tester_provider.max_gas

tests/test_integration.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import pytest
2+
from ape._cli import cli as ape_cli
3+
from click.testing import CliRunner
4+
15
EXPECTED_OUTPUT = """
26
polygon
37
├── mainnet
@@ -9,6 +13,16 @@
913
""".strip()
1014

1115

16+
@pytest.fixture
17+
def runner():
18+
return CliRunner()
19+
20+
21+
@pytest.fixture
22+
def cli():
23+
return ape_cli
24+
25+
1226
def assert_rich_text(actual: str, expected: str):
1327
"""
1428
The output from `rich` causes a bunch of extra spaces to
@@ -30,6 +44,10 @@ def assert_rich_text(actual: str, expected: str):
3044
assert expected_line in actual_lines
3145

3246

33-
def test_networks(runner, cli):
47+
def test_networks(runner, cli, polygon):
48+
# Do this in case local env changed it.
49+
polygon.mainnet.set_default_provider("geth")
50+
polygon.mumbai.set_default_provider("geth")
51+
3452
result = runner.invoke(cli, ["networks", "list"])
3553
assert_rich_text(result.output, EXPECTED_OUTPUT)

0 commit comments

Comments
 (0)