|
11 | 11 | ) |
12 | 12 | from eth2spec.test.helpers.bls_to_execution_changes import get_signed_address_change |
13 | 13 | from eth2spec.test.helpers.constants import ( |
14 | | - ALTAIR, |
15 | | - BELLATRIX, |
16 | | - CAPELLA, |
17 | | - DENEB, |
18 | | - EIP6110, |
19 | | - EIP7002, |
| 14 | + PHASE0, |
| 15 | + PREVIOUS_FORK_OF, |
20 | 16 | ) |
21 | 17 | from eth2spec.test.helpers.deposits import ( |
22 | 18 | prepare_state_and_deposit, |
@@ -146,45 +142,34 @@ def state_transition_across_slots_with_ignoring_proposers(spec, |
146 | 142 | next_slot(spec, state) |
147 | 143 |
|
148 | 144 |
|
| 145 | +def get_upgrade_fn(spec, fork): |
| 146 | + try: |
| 147 | + # TODO: make all upgrade_to_* function names consistent? |
| 148 | + fn = eval(f"spec.upgrade_to_{fork}") |
| 149 | + return fn |
| 150 | + except Exception: |
| 151 | + raise ValueError(f"Unknown fork: {fork}") |
| 152 | + |
| 153 | + |
149 | 154 | def do_fork(state, spec, post_spec, fork_epoch, with_block=True, sync_aggregate=None, operation_dict=None): |
150 | 155 | spec.process_slots(state, state.slot + 1) |
151 | 156 |
|
152 | 157 | assert state.slot % spec.SLOTS_PER_EPOCH == 0 |
153 | 158 | assert spec.get_current_epoch(state) == fork_epoch |
154 | 159 |
|
155 | | - if post_spec.fork == ALTAIR: |
156 | | - state = post_spec.upgrade_to_altair(state) |
157 | | - elif post_spec.fork == BELLATRIX: |
158 | | - state = post_spec.upgrade_to_bellatrix(state) |
159 | | - elif post_spec.fork == CAPELLA: |
160 | | - state = post_spec.upgrade_to_capella(state) |
161 | | - elif post_spec.fork == DENEB: |
162 | | - state = post_spec.upgrade_to_deneb(state) |
163 | | - elif post_spec.fork == EIP6110: |
164 | | - state = post_spec.upgrade_to_eip6110(state) |
165 | | - elif post_spec.fork == EIP7002: |
166 | | - state = post_spec.upgrade_to_eip7002(state) |
| 160 | + state = get_upgrade_fn(post_spec, post_spec.fork)(state) |
167 | 161 |
|
168 | 162 | assert state.fork.epoch == fork_epoch |
169 | 163 |
|
170 | | - if post_spec.fork == ALTAIR: |
171 | | - assert state.fork.previous_version == post_spec.config.GENESIS_FORK_VERSION |
172 | | - assert state.fork.current_version == post_spec.config.ALTAIR_FORK_VERSION |
173 | | - elif post_spec.fork == BELLATRIX: |
174 | | - assert state.fork.previous_version == post_spec.config.ALTAIR_FORK_VERSION |
175 | | - assert state.fork.current_version == post_spec.config.BELLATRIX_FORK_VERSION |
176 | | - elif post_spec.fork == CAPELLA: |
177 | | - assert state.fork.previous_version == post_spec.config.BELLATRIX_FORK_VERSION |
178 | | - assert state.fork.current_version == post_spec.config.CAPELLA_FORK_VERSION |
179 | | - elif post_spec.fork == DENEB: |
180 | | - assert state.fork.previous_version == post_spec.config.CAPELLA_FORK_VERSION |
181 | | - assert state.fork.current_version == post_spec.config.DENEB_FORK_VERSION |
182 | | - elif post_spec.fork == EIP6110: |
183 | | - assert state.fork.previous_version == post_spec.config.DENEB_FORK_VERSION |
184 | | - assert state.fork.current_version == post_spec.config.EIP6110_FORK_VERSION |
185 | | - elif post_spec.fork == EIP7002: |
186 | | - assert state.fork.previous_version == post_spec.config.CAPELLA_FORK_VERSION |
187 | | - assert state.fork.current_version == post_spec.config.EIP7002_FORK_VERSION |
| 164 | + previous_fork = PREVIOUS_FORK_OF[post_spec.fork] |
| 165 | + if previous_fork == PHASE0: |
| 166 | + previous_version = spec.config.GENESIS_FORK_VERSION |
| 167 | + else: |
| 168 | + previous_version = getattr(post_spec.config, f"{previous_fork.upper()}_FORK_VERSION") |
| 169 | + current_version = getattr(post_spec.config, f"{post_spec.fork.upper()}_FORK_VERSION") |
| 170 | + |
| 171 | + assert state.fork.previous_version == previous_version |
| 172 | + assert state.fork.current_version == current_version |
188 | 173 |
|
189 | 174 | if with_block: |
190 | 175 | return state, _state_transition_and_sign_block_at_slot( |
|
0 commit comments