Skip to content

Commit

Permalink
fix: type issue with block time:
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Feb 5, 2025
1 parent a7e163a commit 7e5b5d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
31 changes: 20 additions & 11 deletions src/ape_node/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from urllib.parse import urlparse

from eth_utils import add_0x_prefix, to_hex
from geth.chain import initialize_chain
from geth.chain import initialize_chain as initialize_gethdev_chain
from geth.process import BaseGethProcess
from geth.wrapper import construct_test_chain_kwargs
from pydantic import field_validator
Expand Down Expand Up @@ -111,6 +111,8 @@ def __init__(
extra_funded_accounts: Optional[list[str]] = None,
hd_path: Optional[str] = DEFAULT_TEST_HD_PATH,
block_time: Optional[int] = None,
generate_accounts: bool = True,
initialize_chain: bool = True,
):
executable = executable or "geth"
if not shutil.which(executable):
Expand Down Expand Up @@ -143,7 +145,7 @@ def __init__(
kwargs_ctor["ws_addr"] = None
kwargs_ctor["ws_port"] = None
if block_time is not None:
kwargs_ctor["dev_period"] = block_time
kwargs_ctor["dev_period"] = f"{block_time}"

geth_kwargs = construct_test_chain_kwargs(**kwargs_ctor)

Expand All @@ -152,15 +154,22 @@ def __init__(

geth_kwargs["dev_mode"] = True
hd_path = hd_path or DEFAULT_TEST_HD_PATH
self._dev_accounts = generate_dev_accounts(
mnemonic, number_of_accounts=number_of_accounts, hd_path=hd_path
)
addresses = [a.address for a in self._dev_accounts]
addresses.extend(extra_funded_accounts or [])
bal_dict = {"balance": str(initial_balance)}
alloc = {a: bal_dict for a in addresses}
genesis = create_genesis_data(alloc, chain_id)
initialize_chain(genesis, self.data_dir)

if generate_accounts:
self._dev_accounts = generate_dev_accounts(
mnemonic, number_of_accounts=number_of_accounts, hd_path=hd_path
)
else:
self._dev_accounts = []

if initialize_chain:
addresses = [a.address for a in self._dev_accounts]
addresses.extend(extra_funded_accounts or [])
bal_dict = {"balance": str(initial_balance)}
alloc = {a: bal_dict for a in addresses}
genesis = create_genesis_data(alloc, chain_id)
initialize_gethdev_chain(genesis, self.data_dir)

super().__init__(geth_kwargs)

@classmethod
Expand Down
14 changes: 13 additions & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def web3(self) -> Web3:
def test_geth_bin_not_found():
bin_name = "__NOT_A_REAL_EXECUTABLE_HOPEFULLY__"
with pytest.raises(NodeSoftwareNotInstalledError):
_ = GethDevProcess(Path.cwd(), executable=bin_name)
_ = GethDevProcess(Path.cwd() / "notexists", executable=bin_name)


@geth_process_test
Expand Down Expand Up @@ -935,3 +935,15 @@ def test_geth_dev_from_uri_ipc(data_folder):
assert kwargs.get("ws_api") is None
assert kwargs.get("ws_addr") is None
assert kwargs.get("rpc_addr") is None


@geth_process_test
def test_geth_dev_block_period(data_folder):
geth_dev = GethDevProcess.from_uri(
"path/to/geth.ipc",
data_folder,
block_time=1,
generate_accounts=False,
initialize_chain=False,
)
assert geth_dev.geth_kwargs["dev_period"] == "1"

0 comments on commit 7e5b5d5

Please sign in to comment.