Skip to content
/ ape Public
forked from ApeWorX/ape

Commit 091a650

Browse files
fix: custom config number of test accounts (ApeWorX#918)
1 parent f87d2a1 commit 091a650

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/ape_geth/providers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from geth.chain import initialize_chain # type: ignore
1818
from geth.process import BaseGethProcess # type: ignore
1919
from geth.wrapper import construct_test_chain_kwargs # type: ignore
20-
from pydantic import Extra
20+
from pydantic import Extra, PositiveInt
2121
from requests.exceptions import ConnectionError
2222
from web3 import HTTPProvider, Web3
2323
from web3.exceptions import ExtraDataLengthError
@@ -47,7 +47,7 @@ def __init__(
4747
hostname: str,
4848
port: int,
4949
mnemonic: str,
50-
number_of_accounts: int,
50+
number_of_accounts: PositiveInt,
5151
chain_id: int = 1337,
5252
initial_balance: Union[str, int] = to_wei(10000, "ether"),
5353
):

src/ape_test/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pydantic import PositiveInt
2+
13
from ape import plugins
24
from ape.api import PluginConfig
35
from ape.api.networks import LOCAL_NETWORK_NAME
@@ -9,7 +11,7 @@
911

1012
class Config(PluginConfig):
1113
mnemonic: str = DEFAULT_TEST_MNEMONIC
12-
number_of_accounts: int = DEFAULT_NUMBER_OF_TEST_ACCOUNTS
14+
number_of_accounts: PositiveInt = DEFAULT_NUMBER_OF_TEST_ACCOUNTS
1315

1416

1517
@plugins.register(plugins.Config)

src/ape_test/accounts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def config(self):
1717
@cached_property
1818
def _dev_accounts(self) -> List[GeneratedDevAccount]:
1919
mnemonic = self.config["mnemonic"]
20-
return generate_dev_accounts(mnemonic)
20+
return generate_dev_accounts(mnemonic, number_of_accounts=self.config["number_of_accounts"])
2121

2222
@property
2323
def aliases(self) -> Iterator[str]:

tests/functional/test_accounts.py

+17
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,20 @@ def test_unlock_from_prompt_and_sign_transaction(runner, keyfile_account, receiv
257257
with runner.isolation(input="y\n"):
258258
receipt = keyfile_account.transfer(receiver, "1 gwei")
259259
assert receipt.receiver == receiver
260+
261+
262+
def test_custom_num_of_test_accts_config(test_accounts, temp_config):
263+
from ape.utils.testing import DEFAULT_NUMBER_OF_TEST_ACCOUNTS
264+
265+
CUSTOM_NUMBER_OF_TEST_ACCOUNTS = 20
266+
267+
test_config = {
268+
"test": {
269+
"number_of_accounts": CUSTOM_NUMBER_OF_TEST_ACCOUNTS,
270+
}
271+
}
272+
273+
assert len(test_accounts) == DEFAULT_NUMBER_OF_TEST_ACCOUNTS
274+
275+
with temp_config(test_config):
276+
assert len(test_accounts) == CUSTOM_NUMBER_OF_TEST_ACCOUNTS

0 commit comments

Comments
 (0)