Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: honor balance config for test accounts initial balance #175

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ test:
gas:
exclude:
- method_name: setAdd*

balance: 100_000 ETH
6 changes: 5 additions & 1 deletion ape_hardhat/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
accounts: {{
mnemonic: "{mnemonic}",
path: "{hd_path}",
count: {number_of_accounts}
count: {number_of_accounts},
accountsBalance: "{initial_balance}",
}}
}},
}},
Expand All @@ -79,6 +80,7 @@ def _validate_hardhat_config_file(
path: Path,
mnemonic: str,
num_of_accounts: int,
initial_balance: int,
hardhat_version: str,
hard_fork: Optional[str] = None,
hd_path: Optional[str] = None,
Expand Down Expand Up @@ -107,6 +109,7 @@ def _validate_hardhat_config_file(
mnemonic=mnemonic,
number_of_accounts=num_of_accounts,
hard_fork=hard_fork,
initial_balance=initial_balance,
)
if not path.is_file():
# Create default '.js' file.
Expand Down Expand Up @@ -674,6 +677,7 @@ def _get_command(self) -> list[str]:
self.hardhat_config_file,
self.mnemonic,
self.number_of_accounts,
self._test_config.balance,
self.hardhat_version,
hard_fork=self.config.evm_version,
hd_path=self.test_config.hd_path or DEFAULT_TEST_HD_PATH,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
url="https://github.com/ApeWorX/ape-hardhat",
include_package_data=True,
install_requires=[
"eth-ape>=0.8.1,<0.9",
"eth-ape>=0.8.9,<0.9",
"ethpm-types", # Use same version as eth-ape
"evm-trace", # Use same version as eth-ape
"web3", # Use same version as eth-ape
Expand Down
8 changes: 8 additions & 0 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
import requests
from ape import convert
from ape.api import ReceiptAPI, TraceAPI
from ape.api.accounts import ImpersonatedAccount
from ape.contracts import ContractContainer
Expand Down Expand Up @@ -306,3 +307,10 @@ def test_hardfork(project, networks):
with project.temp_config(hardhat={"evm_version": "london"}):
with networks.ethereum.local.use_provider("hardhat") as provider:
assert provider.config.evm_version == "london"


def test_initial_balance(accounts):
# We configured it to be 100_000 ETH but the default is 10_000 ETH and
# we may have spent some, so just assert its in between those two ranges.
acct = accounts[9]
assert convert("10_000 ETH", int) < acct.balance <= convert("100_000 ETH", int)
Loading