Make `compute_new_state_root` a pure function

This commit is contained in:
Hsiao-Wei Wang 2020-04-27 22:05:47 +08:00
parent d311248d35
commit 2dbc333270
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
2 changed files with 5 additions and 3 deletions

View File

@ -340,9 +340,10 @@ It is useful to be able to run a state transition function (working on a copy of
```python
def compute_new_state_root(state: BeaconState, block: BeaconBlock) -> Root:
process_slots(state, block.slot)
process_block(state, block)
return hash_tree_root(state)
temp_state: BeaconState = state.copy()
signed_block = SignedBeaconBlock(message=block)
temp_state = state_transition(temp_state, signed_block, validate_result=False)
return hash_tree_root(temp_state)
```
##### Signature

View File

@ -246,6 +246,7 @@ def test_compute_new_state_root(spec, state):
state_root = spec.compute_new_state_root(state, block)
assert state_root != pre_state.hash_tree_root()
assert state == pre_state
# dumb verification
spec.process_slots(post_state, block.slot)