use `forks` sugar in `loadForkedState` testing function (#5720)
Adjust `loadForkedState` to use `withState` sugar to reduce code duplication.
This commit is contained in:
parent
07455e67a9
commit
95e9740506
|
@ -121,36 +121,10 @@ proc parseTest*(path: string, Format: typedesc[SSZ], T: typedesc): T =
|
|||
stderr.write err.formatMsg(path), "\n"
|
||||
quit 1
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/capella import BeaconState
|
||||
from ../../beacon_chain/spec/datatypes/deneb import BeaconState
|
||||
|
||||
proc loadForkedState*(
|
||||
path: string, fork: ConsensusFork): ref ForkedHashedBeaconState =
|
||||
var forkedState: ref ForkedHashedBeaconState
|
||||
case fork
|
||||
of ConsensusFork.Deneb:
|
||||
let state = newClone(parseTest(path, SSZ, deneb.BeaconState))
|
||||
forkedState = (ref ForkedHashedBeaconState)(kind: ConsensusFork.Deneb)
|
||||
forkedState.denebData.data = state[]
|
||||
forkedState.denebData.root = hash_tree_root(state[])
|
||||
of ConsensusFork.Capella:
|
||||
let state = newClone(parseTest(path, SSZ, capella.BeaconState))
|
||||
forkedState = (ref ForkedHashedBeaconState)(kind: ConsensusFork.Capella)
|
||||
forkedState.capellaData.data = state[]
|
||||
forkedState.capellaData.root = hash_tree_root(state[])
|
||||
of ConsensusFork.Bellatrix:
|
||||
let state = newClone(parseTest(path, SSZ, bellatrix.BeaconState))
|
||||
forkedState = (ref ForkedHashedBeaconState)(kind: ConsensusFork.Bellatrix)
|
||||
forkedState.bellatrixData.data = state[]
|
||||
forkedState.bellatrixData.root = hash_tree_root(state[])
|
||||
of ConsensusFork.Altair:
|
||||
let state = newClone(parseTest(path, SSZ, altair.BeaconState))
|
||||
forkedState = (ref ForkedHashedBeaconState)(kind: ConsensusFork.Altair)
|
||||
forkedState.altairData.data = state[]
|
||||
forkedState.altairData.root = hash_tree_root(state[])
|
||||
of ConsensusFork.Phase0:
|
||||
let state = newClone(parseTest(path, SSZ, phase0.BeaconState))
|
||||
forkedState = (ref ForkedHashedBeaconState)(kind: ConsensusFork.Phase0)
|
||||
forkedState.phase0Data.data = state[]
|
||||
forkedState.phase0Data.root = hash_tree_root(state[])
|
||||
forkedState
|
||||
path: string, consensusFork: ConsensusFork): ref ForkedHashedBeaconState =
|
||||
let state = (ref ForkedHashedBeaconState)(kind: consensusFork)
|
||||
withState(state[]):
|
||||
forkyState.data = parseTest(path, SSZ, consensusFork.BeaconState)
|
||||
forkyState.root = hash_tree_root(forkyState.data)
|
||||
state
|
||||
|
|
Loading…
Reference in New Issue