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"
|
stderr.write err.formatMsg(path), "\n"
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
from ../../beacon_chain/spec/datatypes/capella import BeaconState
|
|
||||||
from ../../beacon_chain/spec/datatypes/deneb import BeaconState
|
|
||||||
|
|
||||||
proc loadForkedState*(
|
proc loadForkedState*(
|
||||||
path: string, fork: ConsensusFork): ref ForkedHashedBeaconState =
|
path: string, consensusFork: ConsensusFork): ref ForkedHashedBeaconState =
|
||||||
var forkedState: ref ForkedHashedBeaconState
|
let state = (ref ForkedHashedBeaconState)(kind: consensusFork)
|
||||||
case fork
|
withState(state[]):
|
||||||
of ConsensusFork.Deneb:
|
forkyState.data = parseTest(path, SSZ, consensusFork.BeaconState)
|
||||||
let state = newClone(parseTest(path, SSZ, deneb.BeaconState))
|
forkyState.root = hash_tree_root(forkyState.data)
|
||||||
forkedState = (ref ForkedHashedBeaconState)(kind: ConsensusFork.Deneb)
|
state
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in New Issue