Skip to content

Commit aacb85a

Browse files
authored
feat: honor balance test config value (#105)
1 parent 9072616 commit aacb85a

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

ape-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ test:
3939
gas:
4040
exclude:
4141
- method_name: setAdd*
42+
43+
balance: 100_000 ETH

ape_foundry/provider.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def mnemonic(self) -> str:
131131
def number_of_accounts(self) -> int:
132132
return self._test_config.number_of_accounts
133133

134+
@property
135+
def initial_balance(self) -> int:
136+
"""
137+
Have to convert the WEI value to ETH, like Anvil expects.
138+
"""
139+
bal_in_wei = self._test_config.balance
140+
return bal_in_wei // 10**18
141+
134142
@property
135143
def process_name(self) -> str:
136144
return "anvil"
@@ -421,6 +429,8 @@ def build_command(self) -> list[str]:
421429
f"{self.number_of_accounts}",
422430
"--derivation-path",
423431
f"{self.test_config.hd_path}",
432+
"--balance",
433+
f"{self.initial_balance}",
424434
"--steps-tracing",
425435
"--block-base-fee-per-gas",
426436
f"{self.settings.base_fee}",

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
url="https://github.com/ApeWorX/ape-foundry",
7373
include_package_data=True,
7474
install_requires=[
75-
"eth-ape>=0.8.1,<0.9",
75+
"eth-ape>=0.8.9,<0.9",
7676
"ethpm-types", # Use same version as eth-ape
7777
"eth-pydantic-types", # Use same version as eth-ape
7878
"evm-trace", # Use same version as ape

tests/test_fork_provider.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from ape.exceptions import ContractLogicError
77
from ape_ethereum.ecosystem import NETWORKS
88

9+
from ape_foundry import FoundryNetworkConfig
10+
911
TESTS_DIRECTORY = Path(__file__).parent
1012
TEST_ADDRESS = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
1113

@@ -224,3 +226,8 @@ def test_contract_interaction(mainnet_fork_provider, owner, mainnet_fork_contrac
224226

225227
# Verify the estimate gas RPC was not used (since we are using max_gas).
226228
assert estimate_gas_spy.call_count == 0
229+
230+
231+
def test_fork_config_none():
232+
cfg = FoundryNetworkConfig.model_validate({"fork": None})
233+
assert isinstance(cfg["fork"], dict)

tests/test_provider.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
import pytest
4+
from ape import convert
45
from ape.api import TraceAPI
56
from ape.api.accounts import ImpersonatedAccount
67
from ape.contracts import ContractContainer
@@ -13,7 +14,7 @@
1314
from hexbytes import HexBytes
1415

1516
from ape_foundry import FoundryProviderError
16-
from ape_foundry.provider import FOUNDRY_CHAIN_ID, FoundryNetworkConfig
17+
from ape_foundry.provider import FOUNDRY_CHAIN_ID
1718

1819
TEST_WALLET_ADDRESS = "0xD9b7fdb3FC0A0Aa3A507dCf0976bc23D49a9C7A3"
1920

@@ -445,6 +446,9 @@ def test_disable_block_gas_limit(project, disconnected_provider):
445446
assert "--disable-block-gas-limit" in cmd
446447

447448

448-
def test_fork_config_none():
449-
cfg = FoundryNetworkConfig.model_validate({"fork": None})
450-
assert isinstance(cfg["fork"], dict)
449+
def test_initial_balance(accounts):
450+
# The value is set in the config, but checking it can be less just in case.
451+
# The regular default value is 10_000 so hopefully it isn't below that,
452+
# just showing we were able to increase it.
453+
acct = accounts[9]
454+
assert convert("10_000 ETH", int) < acct.balance <= convert("100_000 ETH", int)

0 commit comments

Comments
 (0)