|
1 | 1 | """Test the types in the `ethereum_test_rpc` package."""
|
2 | 2 |
|
| 3 | +from typing import Any, Dict |
| 4 | + |
3 | 5 | import pytest
|
4 | 6 |
|
5 | 7 | from ethereum_test_rpc import EthConfigResponse
|
6 | 8 |
|
7 |
| -eth_config_json_data = """ |
8 |
| -{ |
| 9 | +eth_config_dict: Dict[str, Any] = { |
9 | 10 | "current": {
|
10 |
| - "activationTime": 0, |
11 |
| - "blobSchedule": { |
12 |
| - "baseFeeUpdateFraction": 3338477, |
13 |
| - "max": 6, |
14 |
| - "target": 3 |
15 |
| - }, |
16 |
| - "chainId": "0x88bb0", |
17 |
| - "precompiles": { |
18 |
| - "0x0000000000000000000000000000000000000001": "ECREC", |
19 |
| - "0x0000000000000000000000000000000000000002": "SHA256", |
20 |
| - "0x0000000000000000000000000000000000000003": "RIPEMD160", |
21 |
| - "0x0000000000000000000000000000000000000004": "ID", |
22 |
| - "0x0000000000000000000000000000000000000005": "MODEXP", |
23 |
| - "0x0000000000000000000000000000000000000006": "BN254_ADD", |
24 |
| - "0x0000000000000000000000000000000000000007": "BN254_MUL", |
25 |
| - "0x0000000000000000000000000000000000000008": "BN254_PAIRING", |
26 |
| - "0x0000000000000000000000000000000000000009": "BLAKE2F", |
27 |
| - "0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION" |
28 |
| - }, |
29 |
| - "systemContracts": { |
30 |
| - "BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02" |
31 |
| - } |
| 11 | + "activationTime": 0, |
| 12 | + "blobSchedule": {"baseFeeUpdateFraction": 3338477, "max": 6, "target": 3}, |
| 13 | + "chainId": "0x88bb0", |
| 14 | + "forkId": "0xbef71d30", |
| 15 | + "precompiles": { |
| 16 | + "BLAKE2F": "0x0000000000000000000000000000000000000009", |
| 17 | + "BN254_ADD": "0x0000000000000000000000000000000000000006", |
| 18 | + "BN254_MUL": "0x0000000000000000000000000000000000000007", |
| 19 | + "BN254_PAIRING": "0x0000000000000000000000000000000000000008", |
| 20 | + "ECREC": "0x0000000000000000000000000000000000000001", |
| 21 | + "ID": "0x0000000000000000000000000000000000000004", |
| 22 | + "KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a", |
| 23 | + "MODEXP": "0x0000000000000000000000000000000000000005", |
| 24 | + "RIPEMD160": "0x0000000000000000000000000000000000000003", |
| 25 | + "SHA256": "0x0000000000000000000000000000000000000002", |
| 26 | + }, |
| 27 | + "systemContracts": {"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"}, |
32 | 28 | },
|
33 |
| - "currentHash": "0x2eedf329", |
34 |
| - "currentForkId": "0xbef71d30", |
35 | 29 | "next": {
|
36 |
| - "activationTime": 1742999832, |
37 |
| - "blobSchedule": { |
38 |
| - "baseFeeUpdateFraction": 5007716, |
39 |
| - "max": 9, |
40 |
| - "target": 6 |
41 |
| - }, |
42 |
| - "chainId": "0x88bb0", |
43 |
| - "precompiles": { |
44 |
| - "0x0000000000000000000000000000000000000001": "ECREC", |
45 |
| - "0x0000000000000000000000000000000000000002": "SHA256", |
46 |
| - "0x0000000000000000000000000000000000000003": "RIPEMD160", |
47 |
| - "0x0000000000000000000000000000000000000004": "ID", |
48 |
| - "0x0000000000000000000000000000000000000005": "MODEXP", |
49 |
| - "0x0000000000000000000000000000000000000006": "BN254_ADD", |
50 |
| - "0x0000000000000000000000000000000000000007": "BN254_MUL", |
51 |
| - "0x0000000000000000000000000000000000000008": "BN254_PAIRING", |
52 |
| - "0x0000000000000000000000000000000000000009": "BLAKE2F", |
53 |
| - "0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION", |
54 |
| - "0x000000000000000000000000000000000000000b": "BLS12_G1ADD", |
55 |
| - "0x000000000000000000000000000000000000000c": "BLS12_G1MSM", |
56 |
| - "0x000000000000000000000000000000000000000d": "BLS12_G2ADD", |
57 |
| - "0x000000000000000000000000000000000000000e": "BLS12_G2MSM", |
58 |
| - "0x000000000000000000000000000000000000000f": "BLS12_PAIRING_CHECK", |
59 |
| - "0x0000000000000000000000000000000000000010": "BLS12_MAP_FP_TO_G1", |
60 |
| - "0x0000000000000000000000000000000000000011": "BLS12_MAP_FP2_TO_G2" |
61 |
| - }, |
62 |
| - "systemContracts": { |
63 |
| - "BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02", |
64 |
| - "CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251", |
65 |
| - "DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa", |
66 |
| - "HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935", |
67 |
| - "WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002" |
68 |
| - } |
| 30 | + "activationTime": 1742999832, |
| 31 | + "blobSchedule": {"baseFeeUpdateFraction": 5007716, "max": 9, "target": 6}, |
| 32 | + "chainId": "0x88bb0", |
| 33 | + "forkId": "0x0929e24e", |
| 34 | + "precompiles": { |
| 35 | + "BLAKE2F": "0x0000000000000000000000000000000000000009", |
| 36 | + "BLS12_G1ADD": "0x000000000000000000000000000000000000000b", |
| 37 | + "BLS12_G1MSM": "0x000000000000000000000000000000000000000c", |
| 38 | + "BLS12_G2ADD": "0x000000000000000000000000000000000000000d", |
| 39 | + "BLS12_G2MSM": "0x000000000000000000000000000000000000000e", |
| 40 | + "BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011", |
| 41 | + "BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010", |
| 42 | + "BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f", |
| 43 | + "BN254_ADD": "0x0000000000000000000000000000000000000006", |
| 44 | + "BN254_MUL": "0x0000000000000000000000000000000000000007", |
| 45 | + "BN254_PAIRING": "0x0000000000000000000000000000000000000008", |
| 46 | + "ECREC": "0x0000000000000000000000000000000000000001", |
| 47 | + "ID": "0x0000000000000000000000000000000000000004", |
| 48 | + "KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a", |
| 49 | + "MODEXP": "0x0000000000000000000000000000000000000005", |
| 50 | + "RIPEMD160": "0x0000000000000000000000000000000000000003", |
| 51 | + "SHA256": "0x0000000000000000000000000000000000000002", |
| 52 | + }, |
| 53 | + "systemContracts": { |
| 54 | + "BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02", |
| 55 | + "CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": ( |
| 56 | + "0x0000bbddc7ce488642fb579f8b00f3a590007251" |
| 57 | + ), |
| 58 | + "DEPOSIT_CONTRACT_ADDRESS": ("0x00000000219ab540356cbb839cbe05303d7705fa"), |
| 59 | + "HISTORY_STORAGE_ADDRESS": ("0x0000f90827f1c53a10cb7a02335b175320002935"), |
| 60 | + "WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": ("0x00000961ef480eb55e80d19ad83579a64c007002"), |
| 61 | + }, |
| 62 | + }, |
| 63 | + "last": { |
| 64 | + "activationTime": 1742999832, |
| 65 | + "blobSchedule": {"baseFeeUpdateFraction": 5007716, "max": 9, "target": 6}, |
| 66 | + "chainId": "0x88bb0", |
| 67 | + "forkId": "0x0929e24e", |
| 68 | + "precompiles": { |
| 69 | + "BLAKE2F": "0x0000000000000000000000000000000000000009", |
| 70 | + "BLS12_G1ADD": "0x000000000000000000000000000000000000000b", |
| 71 | + "BLS12_G1MSM": "0x000000000000000000000000000000000000000c", |
| 72 | + "BLS12_G2ADD": "0x000000000000000000000000000000000000000d", |
| 73 | + "BLS12_G2MSM": "0x000000000000000000000000000000000000000e", |
| 74 | + "BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011", |
| 75 | + "BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010", |
| 76 | + "BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f", |
| 77 | + "BN254_ADD": "0x0000000000000000000000000000000000000006", |
| 78 | + "BN254_MUL": "0x0000000000000000000000000000000000000007", |
| 79 | + "BN254_PAIRING": "0x0000000000000000000000000000000000000008", |
| 80 | + "ECREC": "0x0000000000000000000000000000000000000001", |
| 81 | + "ID": "0x0000000000000000000000000000000000000004", |
| 82 | + "KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a", |
| 83 | + "MODEXP": "0x0000000000000000000000000000000000000005", |
| 84 | + "RIPEMD160": "0x0000000000000000000000000000000000000003", |
| 85 | + "SHA256": "0x0000000000000000000000000000000000000002", |
| 86 | + }, |
| 87 | + "systemContracts": { |
| 88 | + "BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02", |
| 89 | + "CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": ( |
| 90 | + "0x0000bbddc7ce488642fb579f8b00f3a590007251" |
| 91 | + ), |
| 92 | + "DEPOSIT_CONTRACT_ADDRESS": ("0x00000000219ab540356cbb839cbe05303d7705fa"), |
| 93 | + "HISTORY_STORAGE_ADDRESS": ("0x0000f90827f1c53a10cb7a02335b175320002935"), |
| 94 | + "WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": ("0x00000961ef480eb55e80d19ad83579a64c007002"), |
| 95 | + }, |
69 | 96 | },
|
70 |
| - "nextHash": "0x0d82a81f", |
71 |
| - "nextForkId": "0x0929e24e" |
72 | 97 | }
|
73 |
| -""" |
74 | 98 |
|
75 | 99 |
|
76 | 100 | @pytest.fixture
|
77 | 101 | def eth_config_response() -> EthConfigResponse:
|
78 | 102 | """Get the `eth_config` response from the client to be verified by all tests."""
|
79 |
| - return EthConfigResponse.model_validate_json(eth_config_json_data) |
| 103 | + return EthConfigResponse.model_validate(eth_config_dict) |
80 | 104 |
|
81 | 105 |
|
82 | 106 | def test_fork_config_get_hash(eth_config_response: EthConfigResponse) -> None:
|
83 | 107 | """Test the `get_hash` method of the `ForkConfig` class."""
|
84 |
| - assert eth_config_response.current is not None |
85 |
| - assert eth_config_response.current_hash is not None |
86 |
| - assert eth_config_response.current.get_hash() == eth_config_response.current_hash, ( |
87 |
| - "Current fork config hash does not match expected value: " |
88 |
| - f"{eth_config_response.current.get_hash()} != {eth_config_response.current_hash}" |
89 |
| - ) |
90 |
| - assert eth_config_response.next is not None |
91 |
| - assert eth_config_response.next_hash is not None |
92 |
| - assert eth_config_response.next.get_hash() == eth_config_response.next_hash, ( |
93 |
| - "Next fork config hash does not match expected value: " |
94 |
| - f"{eth_config_response.next.get_hash()} != {eth_config_response.next_hash}" |
95 |
| - ) |
| 108 | + # Iterate through each fork config and validate |
| 109 | + for config_name in ("current", "next", "last"): |
| 110 | + config = getattr(eth_config_response, config_name) |
| 111 | + expected = eth_config_dict[config_name] |
| 112 | + if config is None: |
| 113 | + assert expected is None |
| 114 | + continue |
| 115 | + |
| 116 | + # Top-level fields |
| 117 | + assert config.activation_time == expected["activationTime"] |
| 118 | + assert str(config.chain_id) == expected["chainId"] |
| 119 | + assert str(config.fork_id) == expected["forkId"] |
| 120 | + |
| 121 | + # Precompiles |
| 122 | + assert set(config.precompiles.keys()) == set(expected["precompiles"].keys()) |
| 123 | + for k, v in expected["precompiles"].items(): |
| 124 | + assert config.precompiles[k] == v |
| 125 | + |
| 126 | + # System contracts |
| 127 | + assert set(config.system_contracts.keys()) == set(expected["systemContracts"].keys()) |
| 128 | + for k, v in expected["systemContracts"].items(): |
| 129 | + assert config.system_contracts[k] == v |
| 130 | + |
| 131 | + # Blob schedule |
| 132 | + if expected.get("blobSchedule") is not None: |
| 133 | + assert config.blob_schedule is not None |
| 134 | + assert ( |
| 135 | + config.blob_schedule.target_blobs_per_block == expected["blobSchedule"]["target"] |
| 136 | + ) |
| 137 | + assert config.blob_schedule.max_blobs_per_block == expected["blobSchedule"]["max"] |
| 138 | + assert ( |
| 139 | + config.blob_schedule.base_fee_update_fraction |
| 140 | + == expected["blobSchedule"]["baseFeeUpdateFraction"] |
| 141 | + ) |
| 142 | + else: |
| 143 | + assert config.blob_schedule is None |
0 commit comments