Skip to content

Commit

Permalink
Merge branch 'feat/08' into feat/trace-api
Browse files Browse the repository at this point in the history
  • Loading branch information
NotPeopling2day authored Apr 16, 2024
2 parents 6184e89 + 091f95f commit 3f08c89
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml

Expand Down
2 changes: 1 addition & 1 deletion docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ deployments:
mainnet:
- contract_type: MyContract
address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
goerli:
sepolia:
- contract_type: MyContract
address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
```
Expand Down
14 changes: 7 additions & 7 deletions docs/userguides/networks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Networks

When interacting with a blockchain, you will have to select an ecosystem (e.g. Ethereum, Arbitrum, or Fantom), a network (e.g. Mainnet or Goerli) and a provider (e.g. Eth-Tester, Geth, or Alchemy).
When interacting with a blockchain, you will have to select an ecosystem (e.g. Ethereum, Arbitrum, or Fantom), a network (e.g. Mainnet or Sepolia) and a provider (e.g. Eth-Tester, Geth, or Alchemy).
Networks are part of ecosystems and typically defined in plugins.
For example, the `ape-ethereum` plugin comes with Ape and can be used for handling EVM-like behavior.

Expand Down Expand Up @@ -195,7 +195,7 @@ To add a corresponding entry in `ape-etherscan` (assuming you are using `ape-eth
etherscan:
ethereum:
rate_limit: 15 # Configure a rate limit that makes sense for retry logic.
# The name of the entry is the same as your custom network!
customnetwork:
uri: https://custom.scan # URL used for showing transactions
Expand Down Expand Up @@ -360,9 +360,9 @@ ethereum:
# Most networks use 120 seconds (2 minutes).
transaction_acceptance_timeout: 60

# The amount of times to retry fetching a receipt. This is useful
# because decentralized systems may show the transaction accepted
# on some nodes but not on others, and potentially RPC requests
# The amount of times to retry fetching a receipt. This is useful
# because decentralized systems may show the transaction accepted
# on some nodes but not on others, and potentially RPC requests
# won't return a receipt immediately after sending its transaction.
# This config accounts for such delay. The default is `20`.
max_receipt_retries: 10
Expand All @@ -371,13 +371,13 @@ ethereum:
# estimates gas. Note: local networks tend to use "max" here
# by default.
gas_limit: auto

# Base-fee multipliers are useful for times when the base fee changes
# before a transaction is sent but after the base fee was derived,
# thus causing rejection. A multiplier reduces the chance of
# rejection. The default for live networks is `1.4` times the base fee.
base_fee_multiplier: 1.2

# The block time helps Ape make decisions about
# polling chain data.
block_time: 10
Expand Down
8 changes: 4 additions & 4 deletions docs/userguides/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ from ape.cli import ape_cli_context

@click.command()
@ape_cli_context()
def cli(cli_ctx):
def cli(cli_ctx):
# There is no connection yet at this point.
testnets = {
"ethereum": ["sepolia", "goerli"],
"polygon": ["mumbai"]
"ethereum": ["sepolia"],
"polygon": ["amoy"]
}
nm = cli_ctx.network_manager

Expand Down Expand Up @@ -137,7 +137,7 @@ Without specifying `--network`, the script with connect to your default network.
Else, specify the network using the `--network` flag:

```shell
ape run foobar --network polygon:mumbai:alchemy
ape run foobar --network polygon:amoy:alchemy
```

You can also change networks within the script using the `ProviderContextManager` (see examples in the CLI-script section above).
Expand Down
4 changes: 2 additions & 2 deletions docs/userguides/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ assert receipt.sender == dev
Deploying from [ape console](./console.html) allows you to interact with a contract in real time. You can also use the `--network` flag to connect a live network.

```bash
ape console --network ethereum:goerli:alchemy
ape console --network ethereum:sepolia:alchemy
```

This will launch an IPython shell:

```python
In [1]: dev = accounts.load("dev")
In [2]: token = dev.deploy(project.Token)
In [2]: token = dev.deploy(project.Token)
In [3]: token.contract_method_defined_in_contract()
```

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"urllib3>=2.0.0,<3",
"watchdog>=3.0,<4",
# ** Dependencies maintained by Ethereum Foundation **
"eth-abi>=4.2.1,<5",
"eth-abi>=5.1.0,<6",
"eth-account>=0.10.0,<0.11",
"eth-typing>=3.5.2,<4",
"eth-utils>=2.3.1,<3",
Expand Down
2 changes: 0 additions & 2 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
NETWORKS = {
# chain_id, network_id
"mainnet": (1, 1),
"goerli": (5, 5),
"sepolia": (11155111, 11155111),
}
BLUEPRINT_HEADER = HexBytes("0xfe71")
Expand Down Expand Up @@ -280,7 +279,6 @@ def _get_custom_network(self, name: str) -> NetworkConfig:

class EthereumConfig(BaseEthereumConfig):
mainnet: NetworkConfig = create_network_config(block_time=13)
goerli: NetworkConfig = create_network_config(block_time=15)
sepolia: NetworkConfig = create_network_config(block_time=15)


Expand Down
1 change: 0 additions & 1 deletion src/ape_geth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def wait(self, *args, **kwargs):
class GethNetworkConfig(PluginConfig):
# Make sure you are running the right networks when you try for these
mainnet: Dict = {"uri": get_random_rpc("ethereum", "mainnet")}
goerli: Dict = {"uri": get_random_rpc("ethereum", "goerli")}
sepolia: Dict = {"uri": get_random_rpc("ethereum", "sepolia")}
# Make sure to run via `geth --dev` (or similar)
local: Dict = {**DEFAULT_SETTINGS.copy(), "chain_id": DEFAULT_TEST_CHAIN_ID}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def use_debug(logger):
@pytest.fixture
def dummy_live_network(chain):
original_network = chain.provider.network.name
chain.provider.network.name = "goerli"
chain.provider.network.name = "sepolia"
yield chain.provider.network
chain.provider.network.name = original_network

Expand Down
20 changes: 10 additions & 10 deletions tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def test_repr_on_local_network_and_disconnected(networks):

@geth_process_test
def test_repr_on_live_network_and_disconnected(networks):
geth = networks.get_provider_from_choice("ethereum:goerli:geth")
assert repr(geth) == "<geth chain_id=5>"
geth = networks.get_provider_from_choice("ethereum:sepolia:geth")
assert repr(geth) == "<geth chain_id=11155111>"


@geth_process_test
Expand All @@ -100,8 +100,8 @@ def test_chain_id_when_connected(geth_provider):

@geth_process_test
def test_chain_id_live_network_not_connected(networks):
geth = networks.get_provider_from_choice("ethereum:goerli:geth")
assert geth.chain_id == 5
geth = networks.get_provider_from_choice("ethereum:sepolia:geth")
assert geth.chain_id == 11155111


@geth_process_test
Expand All @@ -126,12 +126,12 @@ def test_connect_wrong_chain_id(ethereum, geth_provider, web3_factory):
start_network = geth_provider.network
expected_error_message = (
f"Provider connected to chain ID '{geth_provider._web3.eth.chain_id}', "
"which does not match network chain ID '5'. "
"Are you connected to 'goerli'?"
"which does not match network chain ID '11155111'. "
"Are you connected to 'sepolia'?"
)

try:
geth_provider.network = ethereum.get_network("goerli")
geth_provider.network = ethereum.get_network("sepolia")

# Ensure when reconnecting, it does not use HTTP
web3_factory.return_value = geth_provider._web3
Expand All @@ -145,15 +145,15 @@ def test_connect_wrong_chain_id(ethereum, geth_provider, web3_factory):
def test_connect_to_chain_that_started_poa(mock_web3, web3_factory, ethereum):
"""
Ensure that when connecting to a chain that
started out as PoA, such as Goerli, we include
started out as PoA, such as Sepolia, we include
the right middleware. Note: even if the chain
is no longer PoA, we still need the middleware
to fetch blocks during the PoA portion of the chain.
"""
mock_web3.eth.get_block.side_effect = ExtraDataLengthError
mock_web3.eth.chain_id = ethereum.goerli.chain_id
mock_web3.eth.chain_id = ethereum.sepolia.chain_id
web3_factory.return_value = mock_web3
provider = ethereum.goerli.get_provider("geth")
provider = ethereum.sepolia.get_provider("geth")
provider.provider_settings = {"uri": "http://node.example.com"} # fake
provider.connect()

Expand Down
22 changes: 11 additions & 11 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,26 @@ def _create_deployments(


def test_ethereum_network_configs(config, temp_config):
eth_config = {"ethereum": {"goerli": {"default_provider": "test"}}}
eth_config = {"ethereum": {"sepolia": {"default_provider": "test"}}}
with temp_config(eth_config):
actual = config.get_config("ethereum")
assert actual.goerli.default_provider == "test"
assert actual.sepolia.default_provider == "test"

# Ensure that non-updated fields remain unaffected
assert actual.goerli.block_time == 15
assert actual.sepolia.block_time == 15


def test_network_gas_limit_default(config):
eth_config = config.get_config("ethereum")

assert eth_config.goerli.gas_limit == "auto"
assert eth_config.sepolia.gas_limit == "auto"
assert eth_config.local.gas_limit == "max"


def _goerli_with_gas_limit(gas_limit: GasLimit) -> dict:
def _sepolia_with_gas_limit(gas_limit: GasLimit) -> dict:
return {
"ethereum": {
"goerli": {
"sepolia": {
"default_provider": "test",
"gas_limit": gas_limit,
}
Expand All @@ -124,25 +124,25 @@ def _goerli_with_gas_limit(gas_limit: GasLimit) -> dict:

@pytest.mark.parametrize("gas_limit", ("auto", "max"))
def test_network_gas_limit_string_config(gas_limit, config, temp_config):
eth_config = _goerli_with_gas_limit(gas_limit)
eth_config = _sepolia_with_gas_limit(gas_limit)

with temp_config(eth_config):
actual = config.get_config("ethereum")

assert actual.goerli.gas_limit == gas_limit
assert actual.sepolia.gas_limit == gas_limit

# Local configuration is unaffected
assert actual.local.gas_limit == "max"


@pytest.mark.parametrize("gas_limit", (1234, "1234", 0x4D2, "0x4D2"))
def test_network_gas_limit_numeric_config(gas_limit, config, temp_config):
eth_config = _goerli_with_gas_limit(gas_limit)
eth_config = _sepolia_with_gas_limit(gas_limit)

with temp_config(eth_config):
actual = config.get_config("ethereum")

assert actual.goerli.gas_limit == 1234
assert actual.sepolia.gas_limit == 1234

# Local configuration is unaffected
assert actual.local.gas_limit == "max"
Expand All @@ -153,7 +153,7 @@ def test_network_gas_limit_invalid_numeric_string(config, temp_config):
Test that using hex strings for a network's gas_limit config must be
prefixed with '0x'
"""
eth_config = _goerli_with_gas_limit("4D2")
eth_config = _sepolia_with_gas_limit("4D2")
with pytest.raises(ValueError, match="Gas limit hex str must include '0x' prefix."):
with temp_config(eth_config):
pass
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def test_gas_limit_local_networks(ethereum, network_name):


def test_gas_limit_live_networks(ethereum):
network = ethereum.get_network("goerli")
network = ethereum.get_network("sepolia")
assert network.gas_limit == "auto"


Expand Down Expand Up @@ -773,7 +773,7 @@ def test_set_default_network_not_exists(temp_config, ethereum):

def test_networks(ethereum):
actual = ethereum.networks
for net in ("goerli", "sepolia", "mainnet", LOCAL_NETWORK_NAME):
for net in ("sepolia", "mainnet", LOCAL_NETWORK_NAME):
assert net in actual
assert isinstance(actual[net], NetworkAPI)

Expand All @@ -783,7 +783,6 @@ def test_networks_includes_custom_networks(
):
actual = ethereum.networks
for net in (
"goerli",
"sepolia",
"mainnet",
LOCAL_NETWORK_NAME,
Expand Down
18 changes: 9 additions & 9 deletions tests/functional/test_network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def test_get_provider_when_not_found(ethereum):
name = "goerli-fork"
name = "sepolia-fork"
network = ethereum.get_network(name)
expected = f"No provider named 'test' in network '{name}' in ecosystem 'ethereum'.*"
with pytest.raises(ProviderNotFoundError, match=expected):
Expand All @@ -19,18 +19,18 @@ def test_get_provider_when_not_found(ethereum):
@pytest.mark.parametrize("scheme", ("http", "https", "ws", "wss"))
def test_get_provider_http(ethereum, scheme):
uri = f"{scheme}://example.com"
network = ethereum.get_network("goerli")
network = ethereum.get_network("sepolia")
actual = network.get_provider(uri)
assert actual.uri == uri
assert actual.network.name == "goerli"
assert actual.network.name == "sepolia"


def test_get_provider_ipc(ethereum):
path = "path/to/geth.ipc"
network = ethereum.get_network("goerli")
network = ethereum.get_network("sepolia")
actual = network.get_provider(path)
assert actual.ipc_path == Path(path)
assert actual.network.name == "goerli"
assert actual.network.name == "sepolia"


def test_get_provider_custom_network(custom_networks_config, ethereum):
Expand All @@ -41,22 +41,22 @@ def test_get_provider_custom_network(custom_networks_config, ethereum):


def test_block_times(ethereum):
assert ethereum.goerli.block_time == 15
assert ethereum.sepolia.block_time == 15


def test_set_default_provider_not_exists(temp_config, ape_caplog, ethereum):
bad_provider = "NOT_EXISTS"
expected = f"Provider '{bad_provider}' not found in network 'ethereum:goerli'."
expected = f"Provider '{bad_provider}' not found in network 'ethereum:sepolia'."
with pytest.raises(NetworkError, match=expected):
ethereum.goerli.set_default_provider(bad_provider)
ethereum.sepolia.set_default_provider(bad_provider)


def test_gas_limits(ethereum, config, project_with_source_files_contract):
"""
Test the default gas limit configurations for local and live networks.
"""
_ = project_with_source_files_contract # Ensure use of project with default config
assert ethereum.goerli.gas_limit == "auto"
assert ethereum.sepolia.gas_limit == "auto"
assert ethereum.local.gas_limit == "max"


Expand Down
Loading

0 comments on commit 3f08c89

Please sign in to comment.