Skip to content

Commit

Permalink
refactor: remove goerli (#169)
Browse files Browse the repository at this point in the history
Co-authored-by: Juliya Smith <[email protected]>
  • Loading branch information
NotPeopling2day and antazoey committed May 10, 2024
1 parent daa1b44 commit fd2499f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 46 deletions.
5 changes: 1 addition & 4 deletions ape_hardhat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def providers():

yield "arbitrum", LOCAL_NETWORK_NAME, HardhatProvider
yield "arbitrum", "mainnet-fork", HardhatForkProvider
# TODO: Remove when goerli is sunset
yield "arbitrum", "goerli-fork", HardhatForkProvider
yield "arbitrum", "sepolia-fork", HardhatForkProvider

yield "avalanche", LOCAL_NETWORK_NAME, HardhatProvider
Expand All @@ -43,8 +41,6 @@ def providers():

yield "optimism", LOCAL_NETWORK_NAME, HardhatProvider
yield "optimism", "mainnet-fork", HardhatForkProvider
# TODO: Remove when goerli is sunset
yield "optimism", "goerli-fork", HardhatForkProvider
yield "optimism", "sepolia-fork", HardhatForkProvider

yield "base", LOCAL_NETWORK_NAME, HardhatProvider
Expand All @@ -54,6 +50,7 @@ def providers():
yield "polygon", LOCAL_NETWORK_NAME, HardhatProvider
yield "polygon", "mainnet-fork", HardhatForkProvider
yield "polygon", "mumbai-fork", HardhatForkProvider
yield "polygon", "amoy-fork", HardhatForkProvider

yield "gnosis", LOCAL_NETWORK_NAME, HardhatProvider
yield "gnosis", "mainnet-fork", HardhatForkProvider
Expand Down
4 changes: 0 additions & 4 deletions tests/ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ hardhat:
upstream_provider: alchemy
block_number: 17040366
host: 127.0.0.1:7110
goerli:
upstream_provider: alchemy
block_number: 7849922
host: 127.0.0.1:7111
sepolia:
upstream_provider: alchemy
block_number: 3091950
Expand Down
18 changes: 8 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import shutil
import subprocess
import tempfile
from contextlib import contextmanager
from pathlib import Path
from tempfile import mkdtemp
Expand All @@ -14,6 +13,7 @@
from ape.contracts import ContractContainer
from ape.exceptions import APINotImplementedError, UnknownSnapshotError
from ape.managers.config import CONFIG_FILE_NAME
from ape.utils import create_tempdir
from ethpm_types import ContractType

from ape_hardhat import HardhatProvider
Expand All @@ -29,7 +29,7 @@
# Needed to test tracing support in core `ape test` command.
pytest_plugins = ["pytester"]
MAINNET_FORK_PORT = 9001
GOERLI_FORK_PORT = 9002
SEPOLIA_FORK_PORT = 9002


def pytest_runtest_makereport(item, call):
Expand Down Expand Up @@ -211,14 +211,14 @@ def mainnet_fork_provider(name, networks, mainnet_fork_port):


@pytest.fixture
def goerli_fork_port():
return GOERLI_FORK_PORT
def sepolia_fork_port():
return SEPOLIA_FORK_PORT


@pytest.fixture
def goerli_fork_provider(name, networks, goerli_fork_port):
with networks.ethereum.goerli_fork.use_provider(
name, provider_settings={"host": f"http://127.0.0.1:{goerli_fork_port}"}
def sepolia_fork_provider(name, networks, sepolia_fork_port):
with networks.ethereum.sepolia_fork.use_provider(
name, provider_settings={"host": f"http://127.0.0.1:{sepolia_fork_port}"}
) as provider:
yield provider

Expand All @@ -227,9 +227,7 @@ def goerli_fork_provider(name, networks, goerli_fork_port):
def temp_config(config):
@contextmanager
def func(data: Dict, package_json: Optional[Dict] = None):
with tempfile.TemporaryDirectory() as temp_dir_str:
temp_dir = Path(temp_dir_str)

with create_tempdir() as temp_dir:
config._cached_configs = {}
config_file = temp_dir / CONFIG_FILE_NAME
config_file.touch()
Expand Down
47 changes: 23 additions & 24 deletions tests/test_fork_provider.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import tempfile
from pathlib import Path

import pytest
from ape.api.networks import LOCAL_NETWORK_NAME
from ape.contracts import ContractInstance
from ape.exceptions import ContractLogicError
from ape.utils import create_tempdir
from ape_ethereum.ecosystem import NETWORKS

from ape_hardhat.provider import HardhatForkProvider
Expand All @@ -20,7 +20,7 @@ def mainnet_fork_contract_instance(owner, contract_container, mainnet_fork_provi

@pytest.mark.fork
def test_multiple_providers(
name, networks, connected_provider, mainnet_fork_port, goerli_fork_port
name, networks, connected_provider, mainnet_fork_port, sepolia_fork_port
):
default_host = "http://127.0.0.1:8545"
assert networks.active_provider.name == name
Expand All @@ -34,14 +34,14 @@ def test_multiple_providers(
assert networks.active_provider.name == name
assert networks.active_provider.network.name == "mainnet-fork"
assert networks.active_provider.uri == mainnet_fork_host
goerli_fork_host = f"http://127.0.0.1:{goerli_fork_port}"
sepolia_fork_host = f"http://127.0.0.1:{sepolia_fork_port}"

with networks.ethereum.goerli_fork.use_provider(
name, provider_settings={"host": goerli_fork_host}
with networks.ethereum.sepolia_fork.use_provider(
name, provider_settings={"host": sepolia_fork_host}
):
assert networks.active_provider.name == name
assert networks.active_provider.network.name == "goerli-fork"
assert networks.active_provider.uri == goerli_fork_host
assert networks.active_provider.network.name == "sepolia-fork"
assert networks.active_provider.uri == sepolia_fork_host

assert networks.active_provider.name == name
assert networks.active_provider.network.name == "mainnet-fork"
Expand All @@ -52,15 +52,15 @@ def test_multiple_providers(
assert networks.active_provider.uri == default_host


@pytest.mark.parametrize("network", [k for k in NETWORKS.keys()])
@pytest.mark.parametrize("network", [k for k in NETWORKS.keys() if k != "goerli"])
def test_fork_config(name, config, network):
plugin_config = config.get_config(name)
network_config = plugin_config["fork"].get("ethereum", {}).get(network, {})
assert network_config.get("upstream_provider") == "alchemy", "config not registered"


@pytest.mark.fork
def test_goerli_impersonate(accounts, goerli_fork_provider):
def test_sepolia_impersonate(accounts, sepolia_fork_provider):
impersonated_account = accounts[TEST_ADDRESS]
other_account = accounts[0]
receipt = impersonated_account.transfer(other_account, "1 wei")
Expand All @@ -84,28 +84,27 @@ def test_request_timeout(networks, config, mainnet_fork_provider):
assert actual == expected

# Test default behavior
with tempfile.TemporaryDirectory() as temp_dir_str:
temp_dir = Path(temp_dir_str)
with create_tempdir() as temp_dir:
with config.using_project(temp_dir):
assert networks.active_provider.timeout == 300


@pytest.mark.fork
def test_reset_fork_no_fork_block_number(networks, goerli_fork_provider):
goerli_fork_provider.mine(5)
prev_block_num = goerli_fork_provider.get_block("latest").number
goerli_fork_provider.reset_fork()
block_num_after_reset = goerli_fork_provider.get_block("latest").number
def test_reset_fork_no_fork_block_number(networks, sepolia_fork_provider):
sepolia_fork_provider.mine(5)
prev_block_num = sepolia_fork_provider.get_block("latest").number
sepolia_fork_provider.reset_fork()
block_num_after_reset = sepolia_fork_provider.get_block("latest").number
assert block_num_after_reset < prev_block_num


@pytest.mark.fork
def test_reset_fork_specify_block_number_via_argument(networks, goerli_fork_provider):
goerli_fork_provider.mine(5)
prev_block_num = goerli_fork_provider.get_block("latest").number
def test_reset_fork_specify_block_number_via_argument(networks, sepolia_fork_provider):
sepolia_fork_provider.mine(5)
prev_block_num = sepolia_fork_provider.get_block("latest").number
new_block_number = prev_block_num - 1
goerli_fork_provider.reset_fork(block_number=new_block_number)
block_num_after_reset = goerli_fork_provider.get_block("latest").number
sepolia_fork_provider.reset_fork(block_number=new_block_number)
block_num_after_reset = sepolia_fork_provider.get_block("latest").number
assert block_num_after_reset == new_block_number


Expand Down Expand Up @@ -177,9 +176,9 @@ def test_get_receipt(mainnet_fork_provider, mainnet_fork_contract_instance, owne
("mainnet", 8994, False, 15_964_699, False),
("mainnet", 8995, False, 15_932_345, True),
("mainnet", 8996, True, 15_900_000, False),
("goerli", 8997, False, 7_948_861, False),
("goerli", 8998, False, 7_424_430, True),
("goerli", 8999, True, 7_900_000, False),
("sepolia", 8997, False, 7_948_861, False),
("sepolia", 8998, False, 7_424_430, True),
("sepolia", 8999, True, 7_900_000, False),
],
)
def test_hardhat_command(
Expand Down
6 changes: 2 additions & 4 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import shutil
import tempfile
from pathlib import Path

import pytest
import requests
Expand All @@ -9,6 +7,7 @@
from ape.contracts import ContractContainer
from ape.exceptions import ContractLogicError
from ape.types import CallTreeNode, TraceFrame
from ape.utils import create_tempdir
from evm_trace import CallType
from hexbytes import HexBytes

Expand Down Expand Up @@ -146,8 +145,7 @@ def test_request_timeout(connected_provider, config):
assert actual == expected

# Test default behavior
with tempfile.TemporaryDirectory() as temp_dir_str:
temp_dir = Path(temp_dir_str)
with create_tempdir() as temp_dir:
with config.using_project(temp_dir):
assert connected_provider.timeout == 30

Expand Down

0 comments on commit fd2499f

Please sign in to comment.