From 47d8f737ebb8f164638ebd92b0ac87d32e66af0d Mon Sep 17 00:00:00 2001 From: antazoey Date: Mon, 22 Jul 2024 17:32:23 -0500 Subject: [PATCH] feat: honor `balance` config for test accounts initial balance (#175) --- ape-config.yaml | 2 ++ ape_hardhat/provider.py | 6 +++++- setup.py | 2 +- tests/test_provider.py | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ape-config.yaml b/ape-config.yaml index 2ec905d..243f30d 100644 --- a/ape-config.yaml +++ b/ape-config.yaml @@ -41,3 +41,5 @@ test: gas: exclude: - method_name: setAdd* + + balance: 100_000 ETH diff --git a/ape_hardhat/provider.py b/ape_hardhat/provider.py index 5f16638..0fb13a2 100644 --- a/ape_hardhat/provider.py +++ b/ape_hardhat/provider.py @@ -60,7 +60,8 @@ accounts: {{ mnemonic: "{mnemonic}", path: "{hd_path}", - count: {number_of_accounts} + count: {number_of_accounts}, + accountsBalance: "{initial_balance}", }} }}, }}, @@ -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, @@ -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. @@ -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, diff --git a/setup.py b/setup.py index b70252a..7a3fec9 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/tests/test_provider.py b/tests/test_provider.py index 3b30a50..8d9860b 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -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 @@ -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)