|
15 | 15 | import json
|
16 | 16 | import pkgutil
|
17 | 17 | from dataclasses import dataclass
|
18 |
| -from typing import Any, Callable, Dict, Generic, Type, TypeVar |
| 18 | +from typing import Any, Callable, Dict, Generic, Type, TypeVar, Union |
19 | 19 |
|
20 | 20 | from ethereum_rlp import rlp
|
21 | 21 | from ethereum_types.bytes import Bytes, Bytes8, Bytes32, FixedBytes
|
@@ -83,7 +83,7 @@ class GenesisConfiguration:
|
83 | 83 | [`timestamp`]: ref:ethereum.frontier.blocks.Header.timestamp
|
84 | 84 | """
|
85 | 85 |
|
86 |
| - initial_accounts: Dict[str, Dict] |
| 86 | + initial_accounts: Dict[str, Dict[str, Union[str, Dict[str, str]]]] |
87 | 87 | """
|
88 | 88 | State of the blockchain at genesis.
|
89 | 89 | """
|
@@ -204,16 +204,31 @@ def add_genesis_block(
|
204 | 204 |
|
205 | 205 | for hex_address, account in genesis.initial_accounts.items():
|
206 | 206 | address = hardfork.hex_to_address(hex_address)
|
| 207 | + |
| 208 | + nonce = account.get("nonce", "0") |
| 209 | + assert isinstance(nonce, (str, int)) |
| 210 | + |
| 211 | + balance = account.get("balance", "0") |
| 212 | + assert isinstance(balance, str) |
| 213 | + |
| 214 | + code = account.get("code", "0x") |
| 215 | + assert isinstance(code, str) |
| 216 | + |
207 | 217 | hardfork.set_account(
|
208 | 218 | chain.state,
|
209 | 219 | address,
|
210 | 220 | hardfork.Account(
|
211 |
| - Uint(int(account.get("nonce", "0"))), |
212 |
| - hex_or_base_10_str_to_u256(account.get("balance", 0)), |
213 |
| - hex_to_bytes(account.get("code", "0x")), |
| 221 | + Uint(int(nonce)), |
| 222 | + hex_or_base_10_str_to_u256(balance), |
| 223 | + hex_to_bytes(code), |
214 | 224 | ),
|
215 | 225 | )
|
216 |
| - for key, value in account.get("storage", {}).items(): |
| 226 | + |
| 227 | + maybe_storage = account.get("storage", {}) |
| 228 | + assert isinstance(maybe_storage, dict) |
| 229 | + storage: Dict[str, str] = maybe_storage |
| 230 | + |
| 231 | + for key, value in storage.items(): |
217 | 232 | hardfork.set_storage(
|
218 | 233 | chain.state, address, hex_to_bytes32(key), hex_to_u256(value)
|
219 | 234 | )
|
|
0 commit comments