Skip to content

Commit

Permalink
fix: allow empty fork config to default to empty dict (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored May 9, 2024
1 parent 947141d commit be1cf2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from evm_trace import CallType, ParityTraceList
from evm_trace import TraceFrame as EvmTraceFrame
from evm_trace import get_calltree_from_geth_trace, get_calltree_from_parity_trace
from pydantic import model_validator
from pydantic import field_validator, model_validator
from pydantic_settings import SettingsConfigDict
from web3 import HTTPProvider, Web3
from web3.exceptions import ContractCustomError
Expand Down Expand Up @@ -96,10 +96,10 @@ class FoundryNetworkConfig(PluginConfig):
# Mapping of ecosystem_name => network_name => FoundryForkConfig
fork: Dict[str, Dict[str, FoundryForkConfig]] = {}

disable_block_gas_limit: bool = False
"""
Disable the ``call.gas_limit <= block.gas_limit`` constraint.
"""
disable_block_gas_limit: bool = False

auto_mine: bool = True
"""
Expand All @@ -111,8 +111,14 @@ class FoundryNetworkConfig(PluginConfig):
Set a block time to allow mining to happen on an interval
rather than only when a new transaction is submitted.
"""

model_config = SettingsConfigDict(extra="allow")

@field_validator("fork", mode="before")
@classmethod
def _validate_fork(cls, value):
return value or {}


def _call(*args):
return call([*args], stderr=PIPE, stdout=PIPE, stdin=PIPE)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from hexbytes import HexBytes

from ape_foundry import FoundryProviderError
from ape_foundry.provider import FOUNDRY_CHAIN_ID, _extract_custom_error
from ape_foundry.provider import FOUNDRY_CHAIN_ID, FoundryNetworkConfig, _extract_custom_error

TEST_WALLET_ADDRESS = "0xD9b7fdb3FC0A0Aa3A507dCf0976bc23D49a9C7A3"

Expand Down Expand Up @@ -490,3 +490,8 @@ def trace(txn_hash: str, *args, **kwargs):

# Show failure was tracked
assert tracker[0] == HexBytes(tx.txn_hash).hex()


def test_fork_config_none():
cfg = FoundryNetworkConfig.model_validate({"fork": None})
assert isinstance(cfg["fork"], dict)

0 comments on commit be1cf2e

Please sign in to comment.