bump unittest2, clean up suite names (#5384)
Suite names were not being used because `test` has to have access to it during instantiation - this PR cleans things up a little while at the same time upgrading unittest2.
This commit is contained in:
parent
f99bb881f4
commit
6fab826487
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -40,35 +40,32 @@ doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
|
|||
OpVoluntaryExitDir])
|
||||
|
||||
proc runTest[T, U](
|
||||
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
||||
testSuiteDir, suiteName, opName, applyFile: string,
|
||||
applyProc: U, identifier: string) =
|
||||
let testDir = testSuiteDir / "pyspec_tests" / identifier
|
||||
|
||||
proc testImpl() =
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
|
||||
test prefix & baseDescription & testSuiteName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
test prefix & baseDescription & opName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState))
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState))
|
||||
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
testImpl()
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
suite baseDescription & "Attestation " & preset():
|
||||
proc applyAttestation(
|
||||
|
@ -85,7 +82,8 @@ suite baseDescription & "Attestation " & preset():
|
|||
|
||||
for path in walkTests(OpAttestationsDir):
|
||||
runTest[Attestation, typeof applyAttestation](
|
||||
OpAttestationsDir, "Attestation", "attestation", applyAttestation, path)
|
||||
OpAttestationsDir, suiteName, "Attestation", "attestation",
|
||||
applyAttestation, path)
|
||||
|
||||
suite baseDescription & "Attester Slashing " & preset():
|
||||
proc applyAttesterSlashing(
|
||||
|
@ -97,7 +95,7 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpAttSlashingDir):
|
||||
runTest[AttesterSlashing, typeof applyAttesterSlashing](
|
||||
OpAttSlashingDir, "Attester Slashing", "attester_slashing",
|
||||
OpAttSlashingDir, suiteName, "Attester Slashing", "attester_slashing",
|
||||
applyAttesterSlashing, path)
|
||||
|
||||
suite baseDescription & "Block Header " & preset():
|
||||
|
@ -109,7 +107,7 @@ suite baseDescription & "Block Header " & preset():
|
|||
|
||||
for path in walkTests(OpBlockHeaderDir):
|
||||
runTest[altair.BeaconBlock, typeof applyBlockHeader](
|
||||
OpBlockHeaderDir, "Block Header", "block", applyBlockHeader, path)
|
||||
OpBlockHeaderDir, suiteName, "Block Header", "block", applyBlockHeader, path)
|
||||
|
||||
suite baseDescription & "Deposit " & preset():
|
||||
proc applyDeposit(
|
||||
|
@ -119,7 +117,7 @@ suite baseDescription & "Deposit " & preset():
|
|||
|
||||
for path in walkTests(OpDepositsDir):
|
||||
runTest[Deposit, typeof applyDeposit](
|
||||
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
||||
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
|
||||
|
||||
suite baseDescription & "Proposer Slashing " & preset():
|
||||
proc applyProposerSlashing(
|
||||
|
@ -131,7 +129,7 @@ suite baseDescription & "Proposer Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpProposerSlashingDir):
|
||||
runTest[ProposerSlashing, typeof applyProposerSlashing](
|
||||
OpProposerSlashingDir, "Proposer Slashing", "proposer_slashing",
|
||||
OpProposerSlashingDir, suiteName, "Proposer Slashing", "proposer_slashing",
|
||||
applyProposerSlashing, path)
|
||||
|
||||
suite baseDescription & "Sync Aggregate " & preset():
|
||||
|
@ -145,7 +143,7 @@ suite baseDescription & "Sync Aggregate " & preset():
|
|||
|
||||
for path in walkTests(OpSyncAggregateDir):
|
||||
runTest[SyncAggregate, typeof applySyncAggregate](
|
||||
OpSyncAggregateDir, "Sync Aggregate", "sync_aggregate",
|
||||
OpSyncAggregateDir, suiteName, "Sync Aggregate", "sync_aggregate",
|
||||
applySyncAggregate, path)
|
||||
|
||||
suite baseDescription & "Voluntary Exit " & preset():
|
||||
|
@ -158,5 +156,5 @@ suite baseDescription & "Voluntary Exit " & preset():
|
|||
|
||||
for path in walkTests(OpVoluntaryExitDir):
|
||||
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
||||
OpVoluntaryExitDir, "Voluntary Exit", "voluntary_exit",
|
||||
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
||||
applyVoluntaryExit, path)
|
||||
|
|
|
@ -30,53 +30,50 @@ func init(T: type Deltas, len: int): T =
|
|||
proc runTest(rewardsDir, identifier: string) =
|
||||
let testDir = rewardsDir / identifier
|
||||
|
||||
proc `testImpl _ rewards _ identifier`() =
|
||||
test "EF - Altair - Rewards - " & identifier & preset():
|
||||
var info: altair.EpochInfo
|
||||
var info: altair.EpochInfo
|
||||
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
`testImpl _ rewards _ identifier`()
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
suite "EF - Altair - Rewards " & preset():
|
||||
for rewardsDir in [RewardsDirBasic, RewardsDirLeak, RewardsDirRandom]:
|
||||
for kind, path in walkDir(rewardsDir, relative = true, checkDir = true):
|
||||
runTest(rewardsDir, path)
|
||||
test "EF - Altair - Rewards - " & path & preset():
|
||||
runTest(rewardsDir, path)
|
||||
|
|
|
@ -44,36 +44,33 @@ doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
|
|||
OpSyncAggregateDir, OpVoluntaryExitDir])
|
||||
|
||||
proc runTest[T, U](
|
||||
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
||||
testSuiteDir, suiteName, opName, applyFile: string,
|
||||
applyProc: U, identifier: string) =
|
||||
let testDir = testSuiteDir / "pyspec_tests" / identifier
|
||||
|
||||
proc testImpl() =
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
|
||||
test prefix & baseDescription & testSuiteName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
test prefix & baseDescription & opName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(
|
||||
testDir/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(
|
||||
testDir/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
testImpl()
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
suite baseDescription & "Attestation " & preset():
|
||||
proc applyAttestation(
|
||||
|
@ -90,7 +87,8 @@ suite baseDescription & "Attestation " & preset():
|
|||
|
||||
for path in walkTests(OpAttestationsDir):
|
||||
runTest[Attestation, typeof applyAttestation](
|
||||
OpAttestationsDir, "Attestation", "attestation", applyAttestation, path)
|
||||
OpAttestationsDir, suiteName, "Attestation", "attestation",
|
||||
applyAttestation, path)
|
||||
|
||||
suite baseDescription & "Attester Slashing " & preset():
|
||||
proc applyAttesterSlashing(
|
||||
|
@ -102,7 +100,7 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpAttSlashingDir):
|
||||
runTest[AttesterSlashing, typeof applyAttesterSlashing](
|
||||
OpAttSlashingDir, "Attester Slashing", "attester_slashing",
|
||||
OpAttSlashingDir, suiteName, "Attester Slashing", "attester_slashing",
|
||||
applyAttesterSlashing, path)
|
||||
|
||||
suite baseDescription & "Block Header " & preset():
|
||||
|
@ -114,7 +112,8 @@ suite baseDescription & "Block Header " & preset():
|
|||
|
||||
for path in walkTests(OpBlockHeaderDir):
|
||||
runTest[bellatrix.BeaconBlock, typeof applyBlockHeader](
|
||||
OpBlockHeaderDir, "Block Header", "block", applyBlockHeader, path)
|
||||
OpBlockHeaderDir, suiteName, "Block Header", "block",
|
||||
applyBlockHeader, path)
|
||||
|
||||
suite baseDescription & "Deposit " & preset():
|
||||
proc applyDeposit(
|
||||
|
@ -124,7 +123,7 @@ suite baseDescription & "Deposit " & preset():
|
|||
|
||||
for path in walkTests(OpDepositsDir):
|
||||
runTest[Deposit, typeof applyDeposit](
|
||||
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
||||
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
|
||||
|
||||
suite baseDescription & "Execution Payload " & preset():
|
||||
for path in walkTests(OpExecutionPayloadDir):
|
||||
|
@ -139,7 +138,7 @@ suite baseDescription & "Execution Payload " & preset():
|
|||
preState, body.execution_payload, executePayload)
|
||||
|
||||
runTest[bellatrix.BeaconBlockBody, typeof applyExecutionPayload](
|
||||
OpExecutionPayloadDir, "Execution Payload", "body",
|
||||
OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
|
||||
applyExecutionPayload, path)
|
||||
|
||||
suite baseDescription & "Proposer Slashing " & preset():
|
||||
|
@ -152,7 +151,7 @@ suite baseDescription & "Proposer Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpProposerSlashingDir):
|
||||
runTest[ProposerSlashing, typeof applyProposerSlashing](
|
||||
OpProposerSlashingDir, "Proposer Slashing", "proposer_slashing",
|
||||
OpProposerSlashingDir, suiteName, "Proposer Slashing", "proposer_slashing",
|
||||
applyProposerSlashing, path)
|
||||
|
||||
suite baseDescription & "Sync Aggregate " & preset():
|
||||
|
@ -166,7 +165,7 @@ suite baseDescription & "Sync Aggregate " & preset():
|
|||
|
||||
for path in walkTests(OpSyncAggregateDir):
|
||||
runTest[SyncAggregate, typeof applySyncAggregate](
|
||||
OpSyncAggregateDir, "Sync Aggregate", "sync_aggregate",
|
||||
OpSyncAggregateDir, suiteName, "Sync Aggregate", "sync_aggregate",
|
||||
applySyncAggregate, path)
|
||||
|
||||
suite baseDescription & "Voluntary Exit " & preset():
|
||||
|
@ -179,5 +178,5 @@ suite baseDescription & "Voluntary Exit " & preset():
|
|||
|
||||
for path in walkTests(OpVoluntaryExitDir):
|
||||
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
||||
OpVoluntaryExitDir, "Voluntary Exit", "voluntary_exit",
|
||||
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
||||
applyVoluntaryExit, path)
|
||||
|
|
|
@ -30,53 +30,50 @@ func init(T: type Deltas, len: int): T =
|
|||
proc runTest(rewardsDir, identifier: string) =
|
||||
let testDir = rewardsDir / identifier
|
||||
|
||||
proc `testImpl _ rewards _ identifier`() =
|
||||
test "EF - Bellatrix - Rewards - " & identifier & preset():
|
||||
var info: altair.EpochInfo
|
||||
var info: altair.EpochInfo
|
||||
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
`testImpl _ rewards _ identifier`()
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
suite "EF - Bellatrix - Rewards " & preset():
|
||||
for rewardsDir in [RewardsDirBasic, RewardsDirLeak, RewardsDirRandom]:
|
||||
for kind, path in walkDir(rewardsDir, relative = true, checkDir = true):
|
||||
runTest(rewardsDir, path)
|
||||
test "EF - Bellatrix - Rewards - " & path & preset():
|
||||
runTest(rewardsDir, path)
|
||||
|
|
|
@ -48,36 +48,33 @@ doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
|
|||
OpWithdrawalsDir])
|
||||
|
||||
proc runTest[T, U](
|
||||
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
||||
testSuiteDir, suiteName, opName, applyFile: string,
|
||||
applyProc: U, identifier: string) =
|
||||
let testDir = testSuiteDir / "pyspec_tests" / identifier
|
||||
|
||||
proc testImpl() =
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
|
||||
test prefix & baseDescription & testSuiteName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, capella.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
test prefix & baseDescription & opName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, capella.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(
|
||||
testDir/"post.ssz_snappy", SSZ, capella.BeaconState))
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(
|
||||
testDir/"post.ssz_snappy", SSZ, capella.BeaconState))
|
||||
|
||||
reportDiff(preState, postState)
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
testImpl()
|
||||
reportDiff(preState, postState)
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
suite baseDescription & "Attestation " & preset():
|
||||
proc applyAttestation(
|
||||
|
@ -94,7 +91,8 @@ suite baseDescription & "Attestation " & preset():
|
|||
|
||||
for path in walkTests(OpAttestationsDir):
|
||||
runTest[Attestation, typeof applyAttestation](
|
||||
OpAttestationsDir, "Attestation", "attestation", applyAttestation, path)
|
||||
OpAttestationsDir, suiteName, "Attestation", "attestation",
|
||||
applyAttestation, path)
|
||||
|
||||
suite baseDescription & "Attester Slashing " & preset():
|
||||
proc applyAttesterSlashing(
|
||||
|
@ -106,7 +104,7 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpAttSlashingDir):
|
||||
runTest[AttesterSlashing, typeof applyAttesterSlashing](
|
||||
OpAttSlashingDir, "Attester Slashing", "attester_slashing",
|
||||
OpAttSlashingDir, suiteName, "Attester Slashing", "attester_slashing",
|
||||
applyAttesterSlashing, path)
|
||||
|
||||
suite baseDescription & "Block Header " & preset():
|
||||
|
@ -118,7 +116,8 @@ suite baseDescription & "Block Header " & preset():
|
|||
|
||||
for path in walkTests(OpBlockHeaderDir):
|
||||
runTest[capella.BeaconBlock, typeof applyBlockHeader](
|
||||
OpBlockHeaderDir, "Block Header", "block", applyBlockHeader, path)
|
||||
OpBlockHeaderDir, suiteName, "Block Header", "block",
|
||||
applyBlockHeader, path)
|
||||
|
||||
suite baseDescription & "BLS to execution change " & preset():
|
||||
proc applyBlsToExecutionChange(
|
||||
|
@ -130,7 +129,7 @@ suite baseDescription & "BLS to execution change " & preset():
|
|||
|
||||
for path in walkTests(OpBlsToExecutionChangeDir):
|
||||
runTest[SignedBLSToExecutionChange, typeof applyBlsToExecutionChange](
|
||||
OpBlsToExecutionChangeDir, "BLS to execution change", "address_change",
|
||||
OpBlsToExecutionChangeDir, suiteName, "BLS to execution change", "address_change",
|
||||
applyBlsToExecutionChange, path)
|
||||
|
||||
suite baseDescription & "Deposit " & preset():
|
||||
|
@ -141,7 +140,7 @@ suite baseDescription & "Deposit " & preset():
|
|||
|
||||
for path in walkTests(OpDepositsDir):
|
||||
runTest[Deposit, typeof applyDeposit](
|
||||
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
||||
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
|
||||
|
||||
suite baseDescription & "Execution Payload " & preset():
|
||||
for path in walkTests(OpExecutionPayloadDir):
|
||||
|
@ -156,7 +155,7 @@ suite baseDescription & "Execution Payload " & preset():
|
|||
preState, body.execution_payload, executePayload)
|
||||
|
||||
runTest[capella.BeaconBlockBody, typeof applyExecutionPayload](
|
||||
OpExecutionPayloadDir, "Execution Payload", "body",
|
||||
OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
|
||||
applyExecutionPayload, path)
|
||||
|
||||
suite baseDescription & "Proposer Slashing " & preset():
|
||||
|
@ -169,7 +168,7 @@ suite baseDescription & "Proposer Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpProposerSlashingDir):
|
||||
runTest[ProposerSlashing, typeof applyProposerSlashing](
|
||||
OpProposerSlashingDir, "Proposer Slashing", "proposer_slashing",
|
||||
OpProposerSlashingDir, suiteName, "Proposer Slashing", "proposer_slashing",
|
||||
applyProposerSlashing, path)
|
||||
|
||||
suite baseDescription & "Sync Aggregate " & preset():
|
||||
|
@ -183,7 +182,7 @@ suite baseDescription & "Sync Aggregate " & preset():
|
|||
|
||||
for path in walkTests(OpSyncAggregateDir):
|
||||
runTest[SyncAggregate, typeof applySyncAggregate](
|
||||
OpSyncAggregateDir, "Sync Aggregate", "sync_aggregate",
|
||||
OpSyncAggregateDir, suiteName, "Sync Aggregate", "sync_aggregate",
|
||||
applySyncAggregate, path)
|
||||
|
||||
suite baseDescription & "Voluntary Exit " & preset():
|
||||
|
@ -196,7 +195,7 @@ suite baseDescription & "Voluntary Exit " & preset():
|
|||
|
||||
for path in walkTests(OpVoluntaryExitDir):
|
||||
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
||||
OpVoluntaryExitDir, "Voluntary Exit", "voluntary_exit",
|
||||
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
||||
applyVoluntaryExit, path)
|
||||
|
||||
suite baseDescription & "Withdrawals " & preset():
|
||||
|
@ -207,5 +206,5 @@ suite baseDescription & "Withdrawals " & preset():
|
|||
|
||||
for path in walkTests(OpWithdrawalsDir):
|
||||
runTest[capella.ExecutionPayload, typeof applyWithdrawals](
|
||||
OpWithdrawalsDir, "Withdrawals", "execution_payload",
|
||||
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
||||
applyWithdrawals, path)
|
||||
|
|
|
@ -30,53 +30,50 @@ func init(T: type Deltas, len: int): T =
|
|||
proc runTest(rewardsDir, identifier: string) =
|
||||
let testDir = rewardsDir / identifier
|
||||
|
||||
proc `testImpl _ rewards _ identifier`() =
|
||||
test "EF - Capella - Rewards - " & identifier & preset():
|
||||
var info: altair.EpochInfo
|
||||
var info: altair.EpochInfo
|
||||
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, capella.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, capella.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
`testImpl _ rewards _ identifier`()
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
suite "EF - Capella - Rewards " & preset():
|
||||
for rewardsDir in [RewardsDirBasic, RewardsDirLeak, RewardsDirRandom]:
|
||||
for kind, path in walkDir(rewardsDir, relative = true, checkDir = true):
|
||||
runTest(rewardsDir, path)
|
||||
test "EF - Capella - Rewards - " & path & preset():
|
||||
runTest(rewardsDir, path)
|
||||
|
|
|
@ -48,36 +48,33 @@ doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
|
|||
OpWithdrawalsDir])
|
||||
|
||||
proc runTest[T, U](
|
||||
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
||||
testSuiteDir, suiteName, opName, applyFile: string,
|
||||
applyProc: U, identifier: string) =
|
||||
let testDir = testSuiteDir / "pyspec_tests" / identifier
|
||||
|
||||
proc testImpl() =
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
|
||||
test prefix & baseDescription & testSuiteName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, deneb.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
test prefix & baseDescription & opName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, deneb.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(
|
||||
testDir/"post.ssz_snappy", SSZ, deneb.BeaconState))
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(
|
||||
testDir/"post.ssz_snappy", SSZ, deneb.BeaconState))
|
||||
|
||||
reportDiff(preState, postState)
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
testImpl()
|
||||
reportDiff(preState, postState)
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
suite baseDescription & "Attestation " & preset():
|
||||
proc applyAttestation(
|
||||
|
@ -94,7 +91,8 @@ suite baseDescription & "Attestation " & preset():
|
|||
|
||||
for path in walkTests(OpAttestationsDir):
|
||||
runTest[Attestation, typeof applyAttestation](
|
||||
OpAttestationsDir, "Attestation", "attestation", applyAttestation, path)
|
||||
OpAttestationsDir, suiteName, "Attestation", "attestation",
|
||||
applyAttestation, path)
|
||||
|
||||
suite baseDescription & "Attester Slashing " & preset():
|
||||
proc applyAttesterSlashing(
|
||||
|
@ -106,7 +104,7 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpAttSlashingDir):
|
||||
runTest[AttesterSlashing, typeof applyAttesterSlashing](
|
||||
OpAttSlashingDir, "Attester Slashing", "attester_slashing",
|
||||
OpAttSlashingDir, suiteName, "Attester Slashing", "attester_slashing",
|
||||
applyAttesterSlashing, path)
|
||||
|
||||
suite baseDescription & "Block Header " & preset():
|
||||
|
@ -118,7 +116,8 @@ suite baseDescription & "Block Header " & preset():
|
|||
|
||||
for path in walkTests(OpBlockHeaderDir):
|
||||
runTest[deneb.BeaconBlock, typeof applyBlockHeader](
|
||||
OpBlockHeaderDir, "Block Header", "block", applyBlockHeader, path)
|
||||
OpBlockHeaderDir, suiteName, "Block Header", "block",
|
||||
applyBlockHeader, path)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/capella import
|
||||
SignedBLSToExecutionChange
|
||||
|
@ -133,7 +132,7 @@ suite baseDescription & "BLS to execution change " & preset():
|
|||
|
||||
for path in walkTests(OpBlsToExecutionChangeDir):
|
||||
runTest[SignedBLSToExecutionChange, typeof applyBlsToExecutionChange](
|
||||
OpBlsToExecutionChangeDir, "BLS to execution change", "address_change",
|
||||
OpBlsToExecutionChangeDir, suiteName, "BLS to execution change", "address_change",
|
||||
applyBlsToExecutionChange, path)
|
||||
|
||||
suite baseDescription & "Deposit " & preset():
|
||||
|
@ -144,7 +143,7 @@ suite baseDescription & "Deposit " & preset():
|
|||
|
||||
for path in walkTests(OpDepositsDir):
|
||||
runTest[Deposit, typeof applyDeposit](
|
||||
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
||||
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
|
||||
|
||||
suite baseDescription & "Execution Payload " & preset():
|
||||
for path in walkTests(OpExecutionPayloadDir):
|
||||
|
@ -158,7 +157,7 @@ suite baseDescription & "Execution Payload " & preset():
|
|||
process_execution_payload(preState, body, executePayload)
|
||||
|
||||
runTest[deneb.BeaconBlockBody, typeof applyExecutionPayload](
|
||||
OpExecutionPayloadDir, "Execution Payload", "body",
|
||||
OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
|
||||
applyExecutionPayload, path)
|
||||
|
||||
suite baseDescription & "Proposer Slashing " & preset():
|
||||
|
@ -171,7 +170,7 @@ suite baseDescription & "Proposer Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpProposerSlashingDir):
|
||||
runTest[ProposerSlashing, typeof applyProposerSlashing](
|
||||
OpProposerSlashingDir, "Proposer Slashing", "proposer_slashing",
|
||||
OpProposerSlashingDir, suiteName, "Proposer Slashing", "proposer_slashing",
|
||||
applyProposerSlashing, path)
|
||||
|
||||
suite baseDescription & "Sync Aggregate " & preset():
|
||||
|
@ -185,7 +184,7 @@ suite baseDescription & "Sync Aggregate " & preset():
|
|||
|
||||
for path in walkTests(OpSyncAggregateDir):
|
||||
runTest[SyncAggregate, typeof applySyncAggregate](
|
||||
OpSyncAggregateDir, "Sync Aggregate", "sync_aggregate",
|
||||
OpSyncAggregateDir, suiteName, "Sync Aggregate", "sync_aggregate",
|
||||
applySyncAggregate, path)
|
||||
|
||||
suite baseDescription & "Voluntary Exit " & preset():
|
||||
|
@ -198,7 +197,7 @@ suite baseDescription & "Voluntary Exit " & preset():
|
|||
|
||||
for path in walkTests(OpVoluntaryExitDir):
|
||||
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
||||
OpVoluntaryExitDir, "Voluntary Exit", "voluntary_exit",
|
||||
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
||||
applyVoluntaryExit, path)
|
||||
|
||||
suite baseDescription & "Withdrawals " & preset():
|
||||
|
@ -209,5 +208,5 @@ suite baseDescription & "Withdrawals " & preset():
|
|||
|
||||
for path in walkTests(OpWithdrawalsDir):
|
||||
runTest[deneb.ExecutionPayload, typeof applyWithdrawals](
|
||||
OpWithdrawalsDir, "Withdrawals", "execution_payload",
|
||||
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
||||
applyWithdrawals, path)
|
||||
|
|
|
@ -30,53 +30,50 @@ func init(T: type Deltas, len: int): T =
|
|||
proc runTest(rewardsDir, identifier: string) =
|
||||
let testDir = rewardsDir / identifier
|
||||
|
||||
proc `testImpl _ rewards _ identifier`() =
|
||||
test "EF - Deneb - Rewards - " & identifier & preset():
|
||||
var info: altair.EpochInfo
|
||||
var info: altair.EpochInfo
|
||||
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, deneb.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, deneb.BeaconState))
|
||||
flagDeltas = [
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas),
|
||||
parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)]
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
info.init(state[])
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
base_reward_per_increment = get_base_reward_per_increment(total_balance)
|
||||
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
var
|
||||
flagDeltas2: array[TimelyFlag, Deltas] = [
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len),
|
||||
Deltas.init(state[].validators.len)]
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
let finality_delay = get_finality_delay(state[])
|
||||
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
for flag_index in TimelyFlag:
|
||||
for validator_index, delta in get_flag_index_deltas(
|
||||
state[], flag_index, base_reward_per_increment, info, finality_delay):
|
||||
if not is_eligible_validator(info.validators[validator_index]):
|
||||
continue
|
||||
flagDeltas2[flag_index].rewards[validator_index] = delta.rewards
|
||||
flagDeltas2[flag_index].penalties[validator_index] = delta.penalties
|
||||
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
for validator_index, delta in get_inactivity_penalty_deltas(
|
||||
defaultRuntimeConfig, state[], info):
|
||||
inactivityPenaltyDeltas2.penalties[validator_index] = delta
|
||||
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
`testImpl _ rewards _ identifier`()
|
||||
check:
|
||||
flagDeltas == flagDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
suite "EF - Deneb - Rewards " & preset():
|
||||
for rewardsDir in [RewardsDirBasic, RewardsDirLeak, RewardsDirRandom]:
|
||||
for kind, path in walkDir(rewardsDir, relative = true, checkDir = true):
|
||||
runTest(rewardsDir, path)
|
||||
test "EF - Deneb - Rewards - " & path & preset():
|
||||
runTest(rewardsDir, path)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2023 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
@ -38,35 +38,32 @@ doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
|
|||
OpDepositsDir, OpProposerSlashingDir, OpVoluntaryExitDir])
|
||||
|
||||
proc runTest[T, U](
|
||||
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
||||
testSuiteDir, suiteName, opName, applyFile: string,
|
||||
applyProc: U, identifier: string) =
|
||||
let testDir = testSuiteDir / "pyspec_tests" / identifier
|
||||
|
||||
proc testImpl() =
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
let prefix =
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
"[Valid] "
|
||||
else:
|
||||
"[Invalid] "
|
||||
|
||||
test prefix & baseDescription & testSuiteName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
test prefix & baseDescription & suiteName & " - " & identifier:
|
||||
let preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
let done = applyProc(
|
||||
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
|
||||
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
if fileExists(testDir/"post.ssz_snappy"):
|
||||
let postState =
|
||||
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
testImpl()
|
||||
check:
|
||||
done.isOk()
|
||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check: done.isErr() # No post state = processing should fail
|
||||
|
||||
suite baseDescription & "Attestation " & preset():
|
||||
proc applyAttestation(
|
||||
|
@ -77,7 +74,8 @@ suite baseDescription & "Attestation " & preset():
|
|||
|
||||
for path in walkTests(OpAttestationsDir):
|
||||
runTest[Attestation, typeof applyAttestation](
|
||||
OpAttestationsDir, "Attestation", "attestation", applyAttestation, path)
|
||||
OpAttestationsDir, suiteName, "Attestation", "attestation",
|
||||
applyAttestation, path)
|
||||
|
||||
suite baseDescription & "Attester Slashing " & preset():
|
||||
proc applyAttesterSlashing(
|
||||
|
@ -89,7 +87,7 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpAttSlashingDir):
|
||||
runTest[AttesterSlashing, typeof applyAttesterSlashing](
|
||||
OpAttSlashingDir, "Attester Slashing", "attester_slashing",
|
||||
OpAttSlashingDir, suiteName, "Attester Slashing", "attester_slashing",
|
||||
applyAttesterSlashing, path)
|
||||
|
||||
suite baseDescription & "Block Header " & preset():
|
||||
|
@ -101,7 +99,8 @@ suite baseDescription & "Block Header " & preset():
|
|||
|
||||
for path in walkTests(OpBlockHeaderDir):
|
||||
runTest[phase0.BeaconBlock, typeof applyBlockHeader](
|
||||
OpBlockHeaderDir, "Block Header", "block", applyBlockHeader, path)
|
||||
OpBlockHeaderDir, suiteName, "Block Header", "block",
|
||||
applyBlockHeader, path)
|
||||
|
||||
suite baseDescription & "Deposit " & preset():
|
||||
proc applyDeposit(
|
||||
|
@ -111,7 +110,7 @@ suite baseDescription & "Deposit " & preset():
|
|||
|
||||
for path in walkTests(OpDepositsDir):
|
||||
runTest[Deposit, typeof applyDeposit](
|
||||
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
||||
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
|
||||
|
||||
suite baseDescription & "Proposer Slashing " & preset():
|
||||
proc applyProposerSlashing(
|
||||
|
@ -123,7 +122,7 @@ suite baseDescription & "Proposer Slashing " & preset():
|
|||
|
||||
for path in walkTests(OpProposerSlashingDir):
|
||||
runTest[ProposerSlashing, typeof applyProposerSlashing](
|
||||
OpProposerSlashingDir, "Proposer Slashing", "proposer_slashing",
|
||||
OpProposerSlashingDir, suiteName, "Proposer Slashing", "proposer_slashing",
|
||||
applyProposerSlashing, path)
|
||||
|
||||
suite baseDescription & "Voluntary Exit " & preset():
|
||||
|
@ -136,5 +135,5 @@ suite baseDescription & "Voluntary Exit " & preset():
|
|||
|
||||
for path in walkTests(OpVoluntaryExitDir):
|
||||
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
||||
OpVoluntaryExitDir, "Voluntary Exit", "voluntary_exit",
|
||||
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
||||
applyVoluntaryExit, path)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2020-2022 Status Research & Development GmbH
|
||||
# Copyright (c) 2020-2023 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
@ -35,76 +35,73 @@ func init(T: type Deltas, len: int): T =
|
|||
proc runTest(rewardsDir, identifier: string) =
|
||||
let testDir = rewardsDir / identifier
|
||||
|
||||
proc `testImpl _ rewards _ identifier`() =
|
||||
test "EF - Phase 0 - Rewards - " & identifier & preset():
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
sourceDeltas =
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas)
|
||||
targetDeltas =
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas)
|
||||
headDeltas = parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)
|
||||
inclusionDelayDeltas =
|
||||
parseTest(testDir/"inclusion_delay_deltas.ssz_snappy", SSZ, Deltas)
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
let
|
||||
state = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
sourceDeltas =
|
||||
parseTest(testDir/"source_deltas.ssz_snappy", SSZ, Deltas)
|
||||
targetDeltas =
|
||||
parseTest(testDir/"target_deltas.ssz_snappy", SSZ, Deltas)
|
||||
headDeltas = parseTest(testDir/"head_deltas.ssz_snappy", SSZ, Deltas)
|
||||
inclusionDelayDeltas =
|
||||
parseTest(testDir/"inclusion_delay_deltas.ssz_snappy", SSZ, Deltas)
|
||||
inactivityPenaltyDeltas =
|
||||
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
|
||||
|
||||
var
|
||||
cache = StateCache()
|
||||
info: phase0.EpochInfo
|
||||
finality_delay = (state[].get_previous_epoch() - state[].finalized_checkpoint.epoch)
|
||||
var
|
||||
cache = StateCache()
|
||||
info: phase0.EpochInfo
|
||||
finality_delay = (state[].get_previous_epoch() - state[].finalized_checkpoint.epoch)
|
||||
|
||||
info.init(state[])
|
||||
info.process_attestations(state[], cache)
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
total_balance_sqrt = integer_squareroot(total_balance)
|
||||
info.init(state[])
|
||||
info.process_attestations(state[], cache)
|
||||
let
|
||||
total_balance = info.balances.current_epoch
|
||||
total_balance_sqrt = integer_squareroot(total_balance)
|
||||
|
||||
var
|
||||
sourceDeltas2 = Deltas.init(state[].validators.len)
|
||||
targetDeltas2 = Deltas.init(state[].validators.len)
|
||||
headDeltas2 = Deltas.init(state[].validators.len)
|
||||
inclusionDelayDeltas2 = Deltas.init(state[].validators.len)
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
var
|
||||
sourceDeltas2 = Deltas.init(state[].validators.len)
|
||||
targetDeltas2 = Deltas.init(state[].validators.len)
|
||||
headDeltas2 = Deltas.init(state[].validators.len)
|
||||
inclusionDelayDeltas2 = Deltas.init(state[].validators.len)
|
||||
inactivityPenaltyDeltas2 = Deltas.init(state[].validators.len)
|
||||
|
||||
for index, validator in info.validators.mpairs():
|
||||
if not is_eligible_validator(validator):
|
||||
continue
|
||||
for index, validator in info.validators.mpairs():
|
||||
if not is_eligible_validator(validator):
|
||||
continue
|
||||
|
||||
let
|
||||
base_reward = get_base_reward_sqrt(
|
||||
state[], index.ValidatorIndex, total_balance_sqrt)
|
||||
let
|
||||
base_reward = get_base_reward_sqrt(
|
||||
state[], index.ValidatorIndex, total_balance_sqrt)
|
||||
|
||||
sourceDeltas2.add(index, get_source_delta(
|
||||
validator, base_reward, info.balances, finality_delay))
|
||||
targetDeltas2.add(index, get_target_delta(
|
||||
validator, base_reward, info.balances, finality_delay))
|
||||
headDeltas2.add(index, get_head_delta(
|
||||
validator, base_reward, info.balances, finality_delay))
|
||||
sourceDeltas2.add(index, get_source_delta(
|
||||
validator, base_reward, info.balances, finality_delay))
|
||||
targetDeltas2.add(index, get_target_delta(
|
||||
validator, base_reward, info.balances, finality_delay))
|
||||
headDeltas2.add(index, get_head_delta(
|
||||
validator, base_reward, info.balances, finality_delay))
|
||||
|
||||
let
|
||||
(inclusion_delay_delta, proposer_delta) =
|
||||
get_inclusion_delay_delta(validator, base_reward)
|
||||
inclusionDelayDeltas2.add(index, inclusion_delay_delta)
|
||||
let
|
||||
(inclusion_delay_delta, proposer_delta) =
|
||||
get_inclusion_delay_delta(validator, base_reward)
|
||||
inclusionDelayDeltas2.add(index, inclusion_delay_delta)
|
||||
|
||||
inactivityPenaltyDeltas2.add(index, get_inactivity_penalty_delta(
|
||||
validator, base_reward, finality_delay))
|
||||
inactivityPenaltyDeltas2.add(index, get_inactivity_penalty_delta(
|
||||
validator, base_reward, finality_delay))
|
||||
|
||||
if proposer_delta.isSome:
|
||||
let proposer_index = proposer_delta.get()[0]
|
||||
inclusionDelayDeltas2.add(proposer_index.int, proposer_delta.get()[1])
|
||||
if proposer_delta.isSome:
|
||||
let proposer_index = proposer_delta.get()[0]
|
||||
inclusionDelayDeltas2.add(proposer_index.int, proposer_delta.get()[1])
|
||||
|
||||
check:
|
||||
sourceDeltas == sourceDeltas2
|
||||
targetDeltas == targetDeltas2
|
||||
headDeltas == headDeltas2
|
||||
inclusionDelayDeltas == inclusionDelayDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
`testImpl _ rewards _ identifier`()
|
||||
check:
|
||||
sourceDeltas == sourceDeltas2
|
||||
targetDeltas == targetDeltas2
|
||||
headDeltas == headDeltas2
|
||||
inclusionDelayDeltas == inclusionDelayDeltas2
|
||||
inactivityPenaltyDeltas == inactivityPenaltyDeltas2
|
||||
|
||||
suite "EF - Phase 0 - Rewards " & preset():
|
||||
for rewardsDir in [RewardsDirBasic, RewardsDirLeak, RewardsDirRandom]:
|
||||
for kind, path in walkDir(rewardsDir, relative = true, checkDir = true):
|
||||
runTest(rewardsDir, path)
|
||||
test "EF - Phase 0 - Rewards - " & path & preset():
|
||||
runTest(rewardsDir, path)
|
||||
|
|
|
@ -17,27 +17,24 @@ import
|
|||
../helpers/debug_state
|
||||
|
||||
proc runTest(
|
||||
BeaconStateAnte, BeaconStatePost: type, forkNameName, forkDir: static[string],
|
||||
upgrade_func: auto, unitTestName: string) =
|
||||
BeaconStateAnte, BeaconStatePost: type, forkName, forkDir: static[string],
|
||||
upgrade_func: auto, suiteName, unitTestName: string) =
|
||||
let testDir = forkDir / unitTestName
|
||||
|
||||
proc `testImpl _ fork _ unitTestName`() =
|
||||
test "EF - " & forkNameName & " - Fork - " & unitTestName & preset():
|
||||
let
|
||||
preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconStateAnte))
|
||||
postState = newClone(
|
||||
parseTest(testDir/"post.ssz_snappy", SSZ, BeaconStatePost))
|
||||
test "EF - " & forkName & " - Fork - " & unitTestName & preset():
|
||||
let
|
||||
preState = newClone(
|
||||
parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconStateAnte))
|
||||
postState = newClone(
|
||||
parseTest(testDir/"post.ssz_snappy", SSZ, BeaconStatePost))
|
||||
|
||||
var cfg = defaultRuntimeConfig
|
||||
when BeaconStateAnte is phase0.BeaconState:
|
||||
cfg.ALTAIR_FORK_EPOCH = preState[].slot.epoch
|
||||
var cfg = defaultRuntimeConfig
|
||||
when BeaconStateAnte is phase0.BeaconState:
|
||||
cfg.ALTAIR_FORK_EPOCH = preState[].slot.epoch
|
||||
|
||||
let upgradedState = upgrade_func(cfg, preState[])
|
||||
check: upgradedState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(upgradedState, postState)
|
||||
|
||||
`testImpl _ fork _ unitTestName`()
|
||||
let upgradedState = upgrade_func(cfg, preState[])
|
||||
check: upgradedState[].hash_tree_root() == postState[].hash_tree_root()
|
||||
reportDiff(upgradedState, postState)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/altair import BeaconState
|
||||
|
||||
|
@ -46,7 +43,7 @@ suite "EF - Altair - Fork " & preset():
|
|||
SszTestsDir/const_preset/"altair"/"fork"/"fork"/"pyspec_tests"
|
||||
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
||||
runTest(phase0.BeaconState, altair.BeaconState, "Altair", OpForkDir,
|
||||
upgrade_to_altair, path)
|
||||
upgrade_to_altair, suiteName, path)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/bellatrix import BeaconState
|
||||
|
||||
|
@ -55,7 +52,7 @@ suite "EF - Bellatrix - Fork " & preset():
|
|||
SszTestsDir/const_preset/"bellatrix"/"fork"/"fork"/"pyspec_tests"
|
||||
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
||||
runTest(altair.BeaconState, bellatrix.BeaconState, "Bellatrix", OpForkDir,
|
||||
upgrade_to_bellatrix, path)
|
||||
upgrade_to_bellatrix, suiteName, path)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/capella import BeaconState
|
||||
|
||||
|
@ -64,7 +61,7 @@ suite "EF - Capella - Fork " & preset():
|
|||
SszTestsDir/const_preset/"capella"/"fork"/"fork"/"pyspec_tests"
|
||||
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
||||
runTest(bellatrix.BeaconState, capella.BeaconState, "Capella", OpForkDir,
|
||||
upgrade_to_capella, path)
|
||||
upgrade_to_capella, suiteName, path)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/deneb import BeaconState
|
||||
|
||||
|
@ -73,4 +70,4 @@ suite "EF - Deneb - Fork " & preset():
|
|||
SszTestsDir/const_preset/"deneb"/"fork"/"fork"/"pyspec_tests"
|
||||
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
||||
runTest(capella.BeaconState, deneb.BeaconState, "Deneb", OpForkDir,
|
||||
upgrade_to_deneb, path)
|
||||
upgrade_to_deneb, suiteName, path)
|
||||
|
|
|
@ -392,7 +392,7 @@ proc doRunTest(path: string, fork: ConsensusFork) =
|
|||
else:
|
||||
doAssert false, "Unsupported"
|
||||
|
||||
proc runTest(testType: static[string], path: string, fork: ConsensusFork) =
|
||||
proc runTest(suiteName: static[string], path: string, fork: ConsensusFork) =
|
||||
const SKIP = [
|
||||
# protoArray can handle blocks in the future gracefully
|
||||
# spec: https://github.com/ethereum/consensus-specs/blame/v1.1.3/specs/phase0/fork-choice.md#L349
|
||||
|
@ -407,7 +407,7 @@ proc runTest(testType: static[string], path: string, fork: ConsensusFork) =
|
|||
"all_valid",
|
||||
]
|
||||
|
||||
test testType & " - " & path.relativePath(SszTestsDir):
|
||||
test suiteName & " - " & path.relativePath(SszTestsDir):
|
||||
when defined(windows):
|
||||
# Some test files have very long paths
|
||||
skip()
|
||||
|
|
|
@ -20,7 +20,7 @@ import
|
|||
../testutil,
|
||||
./fixtures_utils, ./os_ops
|
||||
|
||||
proc runTest[T](path: string, objType: typedesc[T]) =
|
||||
proc runTest[T](suiteName, path: string, objType: typedesc[T]) =
|
||||
test "Light client - Single merkle proof - " & path.relativePath(SszTestsDir):
|
||||
type
|
||||
TestProof = object
|
||||
|
@ -69,8 +69,8 @@ suite "EF - Light client - Single merkle proof" & preset():
|
|||
for kind, path in walkDir(suitePath, relative = true, checkDir = true):
|
||||
case objName
|
||||
of "BeaconBlockBody":
|
||||
runTest(suitePath/path, BeaconBlockBodyType(consensusFork))
|
||||
runTest(suiteName, suitePath/path, BeaconBlockBodyType(consensusFork))
|
||||
of "BeaconState":
|
||||
runTest(suitePath/path, BeaconStateType(consensusFork))
|
||||
runTest(suiteName, suitePath/path, BeaconStateType(consensusFork))
|
||||
else:
|
||||
raiseAssert "Unknown test object: " & suitePath/path
|
||||
|
|
|
@ -122,7 +122,7 @@ proc loadSteps(path: string, fork_digests: ForkDigests): seq[TestStep] =
|
|||
else:
|
||||
doAssert false, "Unknown test step: " & $step
|
||||
|
||||
proc runTest(path: string) =
|
||||
proc runTest(suiteName, path: string) =
|
||||
test "Light client - Sync - " & path.relativePath(SszTestsDir):
|
||||
# Reduce stack size by making this a `proc`
|
||||
proc loadTestMeta(): (RuntimeConfig, TestMeta) =
|
||||
|
@ -269,4 +269,4 @@ suite "EF - Light client - Sync" & preset():
|
|||
continue
|
||||
for kind, path in walkDir(basePath, relative = true, checkDir = true):
|
||||
let combinedPath = basePath/path
|
||||
runTest(basePath/path)
|
||||
runTest(suiteName, basePath/path)
|
||||
|
|
|
@ -24,7 +24,7 @@ type
|
|||
TestMeta = object
|
||||
updates_count: uint64
|
||||
|
||||
proc runTest(path: string, lcDataFork: static LightClientDataFork) =
|
||||
proc runTest(suiteName, path: string, lcDataFork: static LightClientDataFork) =
|
||||
test "Light client - Update ranking - " & path.relativePath(SszTestsDir):
|
||||
let meta = block:
|
||||
var s = openFileStream(path/"meta.yaml")
|
||||
|
@ -64,5 +64,5 @@ suite "EF - Light client - Update ranking" & preset():
|
|||
withConsensusFork(fork):
|
||||
const lcDataFork = lcDataForkAtConsensusFork(consensusFork)
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
runTest(testsPath/path, lcDataFork)
|
||||
runTest(suiteName, testsPath/path, lcDataFork)
|
||||
else: raiseAssert "Unreachable"
|
||||
|
|
|
@ -23,45 +23,42 @@ from ./fixtures_utils import
|
|||
SSZ, SszTestsDir, hash_tree_root, parseTest, readSszBytes, toSszType
|
||||
|
||||
proc runTest(
|
||||
BS, SBB: type, testName, testDir: static[string], unitTestName: string) =
|
||||
BS, SBB: type, testName, testDir: static[string], suiteName, unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
let preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, BS))
|
||||
var
|
||||
fhPreState = ForkedHashedBeaconState.new(preState[])
|
||||
cache = StateCache()
|
||||
info = ForkedEpochInfo()
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
let preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, BS))
|
||||
var
|
||||
fhPreState = ForkedHashedBeaconState.new(preState[])
|
||||
cache = StateCache()
|
||||
info = ForkedEpochInfo()
|
||||
|
||||
# In test cases with more than 10 blocks the first 10 aren't 0-prefixed,
|
||||
# so purely lexicographic sorting wouldn't sort properly.
|
||||
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
||||
for i in 0 ..< numBlocks:
|
||||
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, SBB)
|
||||
|
||||
if hasPostState:
|
||||
state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback).expect("should apply block")
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk(),
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
# In test cases with more than 10 blocks the first 10 aren't 0-prefixed,
|
||||
# so purely lexicographic sorting wouldn't sort properly.
|
||||
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
||||
for i in 0 ..< numBlocks:
|
||||
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, SBB)
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, BS))
|
||||
when false:
|
||||
reportDiff(hashedPreState.phase0Data.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback).expect("should apply block")
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk(),
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, BS))
|
||||
when false:
|
||||
reportDiff(hashedPreState.phase0Data.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
template runForkBlockTests(
|
||||
forkDirName, forkHumanName: static[string], BeaconStateType,
|
||||
|
@ -78,19 +75,19 @@ template runForkBlockTests(
|
|||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest(
|
||||
BeaconStateType, BeaconBlockType,
|
||||
"EF - " & forkHumanName & " - Sanity - Blocks", SanityBlocksDir, path)
|
||||
"EF - " & forkHumanName & " - Sanity - Blocks", SanityBlocksDir, suiteName, path)
|
||||
|
||||
suite "EF - " & forkHumanName & " - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest(
|
||||
BeaconStateType, BeaconBlockType,
|
||||
"EF - " & forkHumanName & " - Finality", FinalityDir, path)
|
||||
"EF - " & forkHumanName & " - Finality", FinalityDir, suiteName, path)
|
||||
|
||||
suite "EF - " & forkHumanName & " - Random " & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest(
|
||||
BeaconStateType, BeaconBlockType,
|
||||
"EF - " & forkHumanName & " - Random", RandomDir, path)
|
||||
"EF - " & forkHumanName & " - Random", RandomDir, suiteName, path)
|
||||
|
||||
runForkBlockTests(
|
||||
"phase0", "Phase 0", phase0.BeaconState, phase0.SignedBeaconBlock)
|
||||
|
|
|
@ -15,36 +15,33 @@ from ../testutil import check, preset, suite, test
|
|||
from ../../beacon_chain/spec/state_transition import process_slots
|
||||
from ../helpers/debug_state import reportDiff
|
||||
|
||||
proc runTest(T: type, testDir, forkName: static[string], identifier: string) =
|
||||
proc runTest(T: type, testDir, forkName: static[string], suiteName, identifier: string) =
|
||||
let
|
||||
testDir = testDir / identifier
|
||||
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
|
||||
|
||||
proc `testImpl _ slots _ identifier`() =
|
||||
test "EF - " & forkName & " - Slots - " & identifier & " [Preset: " & const_preset & "]":
|
||||
let
|
||||
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T))
|
||||
postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, T))
|
||||
var
|
||||
fhPreState = ForkedHashedBeaconState.new(preState[])
|
||||
cache = StateCache()
|
||||
info: ForkedEpochInfo
|
||||
test "EF - " & forkName & " - Slots - " & identifier & " [Preset: " & const_preset & "]":
|
||||
let
|
||||
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T))
|
||||
postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, T))
|
||||
var
|
||||
fhPreState = ForkedHashedBeaconState.new(preState[])
|
||||
cache = StateCache()
|
||||
info: ForkedEpochInfo
|
||||
|
||||
check:
|
||||
process_slots(
|
||||
defaultRuntimeConfig,
|
||||
fhPreState[], getStateField(fhPreState[], slot) + num_slots, cache,
|
||||
info, {}).isOk()
|
||||
check:
|
||||
process_slots(
|
||||
defaultRuntimeConfig,
|
||||
fhPreState[], getStateField(fhPreState[], slot) + num_slots, cache,
|
||||
info, {}).isOk()
|
||||
|
||||
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
withState(fhPreState[]):
|
||||
when forkyState.data isnot typeof(postState[]):
|
||||
doAssert false, "mismatched pre/post forks"
|
||||
else:
|
||||
reportDiff(forkyState.data, postState[])
|
||||
|
||||
`testImpl _ slots _ identifier`()
|
||||
withState(fhPreState[]):
|
||||
when forkyState.data isnot typeof(postState[]):
|
||||
doAssert false, "mismatched pre/post forks"
|
||||
else:
|
||||
reportDiff(forkyState.data, postState[])
|
||||
|
||||
func sanitySlotsDir(preset_dir: string): string {.compileTime.} =
|
||||
SszTestsDir/const_preset/preset_dir/"sanity"/"slots"/"pyspec_tests"
|
||||
|
@ -55,7 +52,7 @@ suite "EF - Phase 0 - Sanity - Slots " & preset():
|
|||
const phase0SanitySlotsDir = sanitySlotsDir("phase0")
|
||||
for kind, path in walkDir(
|
||||
phase0SanitySlotsDir, relative = true, checkDir = true):
|
||||
runTest(phase0.BeaconState, phase0SanitySlotsDir, "Phase 0", path)
|
||||
runTest(phase0.BeaconState, phase0SanitySlotsDir, "Phase 0", suiteName, path)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/altair import BeaconState
|
||||
|
||||
|
@ -63,7 +60,7 @@ suite "EF - Altair - Sanity - Slots " & preset():
|
|||
const altairSanitySlotsDir = sanitySlotsDir("altair")
|
||||
for kind, path in walkDir(
|
||||
altairSanitySlotsDir, relative = true, checkDir = true):
|
||||
runTest(altair.BeaconState, altairSanitySlotsDir, "Altair", path)
|
||||
runTest(altair.BeaconState, altairSanitySlotsDir, "Altair", suiteName, path)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/bellatrix import BeaconState
|
||||
|
||||
|
@ -71,7 +68,7 @@ suite "EF - Bellatrix - Sanity - Slots " & preset():
|
|||
const bellatrixSanitySlotsDir = sanitySlotsDir("bellatrix")
|
||||
for kind, path in walkDir(
|
||||
bellatrixSanitySlotsDir, relative = true, checkDir = true):
|
||||
runTest(bellatrix.BeaconState, bellatrixSanitySlotsDir, "Bellatrix", path)
|
||||
runTest(bellatrix.BeaconState, bellatrixSanitySlotsDir, "Bellatrix", suiteName, path)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/capella import BeaconState
|
||||
|
||||
|
@ -79,7 +76,7 @@ suite "EF - Capella - Sanity - Slots " & preset():
|
|||
const capellaSanitySlotsDir = sanitySlotsDir("capella")
|
||||
for kind, path in walkDir(
|
||||
capellaSanitySlotsDir, relative = true, checkDir = true):
|
||||
runTest(capella.BeaconState, capellaSanitySlotsDir, "Capella", path)
|
||||
runTest(capella.BeaconState, capellaSanitySlotsDir, "Capella", suiteName, path)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/deneb import BeaconState
|
||||
|
||||
|
@ -87,4 +84,4 @@ suite "EF - Deneb - Sanity - Slots " & preset():
|
|||
const denebSanitySlotsDir = sanitySlotsDir("deneb")
|
||||
for kind, path in walkDir(
|
||||
denebSanitySlotsDir, relative = true, checkDir = true):
|
||||
runTest(deneb.BeaconState, denebSanitySlotsDir, "Deneb", path)
|
||||
runTest(deneb.BeaconState, denebSanitySlotsDir, "Deneb", suiteName, path)
|
||||
|
|
|
@ -35,48 +35,45 @@ proc getTransitionInfo(testPath: string): TransitionInfo =
|
|||
proc runTest(
|
||||
AnteBeaconState, PostBeaconState, AnteBeaconBlock, PostBeaconBlock: type,
|
||||
cfg: RuntimeConfig, testName, testDir: static[string],
|
||||
unitTestName: string, fork_block: int) =
|
||||
suiteName, unitTestName: string, fork_block: int) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
test testName & " - " & unitTestName & preset():
|
||||
let preState =
|
||||
newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, AnteBeaconState))
|
||||
var
|
||||
fhPreState = ForkedHashedBeaconState.new(preState[])
|
||||
cache = StateCache()
|
||||
info = ForkedEpochInfo()
|
||||
test testName & " - " & unitTestName & preset():
|
||||
let preState =
|
||||
newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, AnteBeaconState))
|
||||
var
|
||||
fhPreState = ForkedHashedBeaconState.new(preState[])
|
||||
cache = StateCache()
|
||||
info = ForkedEpochInfo()
|
||||
|
||||
# In test cases with more than 10 blocks the first 10 aren't 0-prefixed,
|
||||
# so purely lexicographic sorting wouldn't sort properly.
|
||||
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
||||
for i in 0 ..< numBlocks:
|
||||
if i <= fork_block:
|
||||
let
|
||||
blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, AnteBeaconBlock)
|
||||
res = state_transition(
|
||||
cfg, fhPreState[], blck, cache, info,
|
||||
flags = {skipStateRootValidation}, noRollback)
|
||||
# In test cases with more than 10 blocks the first 10 aren't 0-prefixed,
|
||||
# so purely lexicographic sorting wouldn't sort properly.
|
||||
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
||||
for i in 0 ..< numBlocks:
|
||||
if i <= fork_block:
|
||||
let
|
||||
blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, AnteBeaconBlock)
|
||||
res = state_transition(
|
||||
cfg, fhPreState[], blck, cache, info,
|
||||
flags = {skipStateRootValidation}, noRollback)
|
||||
|
||||
res.expect("no failure when applying block " & $i)
|
||||
else:
|
||||
let
|
||||
blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, PostBeaconBlock)
|
||||
res = state_transition(
|
||||
cfg, fhPreState[], blck, cache, info,
|
||||
flags = {skipStateRootValidation}, noRollback)
|
||||
res.expect("no failure when applying block " & $i)
|
||||
else:
|
||||
let
|
||||
blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, PostBeaconBlock)
|
||||
res = state_transition(
|
||||
cfg, fhPreState[], blck, cache, info,
|
||||
flags = {skipStateRootValidation}, noRollback)
|
||||
|
||||
res.expect("no failure when applying block " & $i)
|
||||
res.expect("no failure when applying block " & $i)
|
||||
|
||||
let postState = newClone(
|
||||
parseTest(testPath/"post.ssz_snappy", SSZ, PostBeaconState))
|
||||
when false:
|
||||
reportDiff(fhPreState.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
let postState = newClone(
|
||||
parseTest(testPath/"post.ssz_snappy", SSZ, PostBeaconState))
|
||||
when false:
|
||||
reportDiff(fhPreState.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/phase0 import
|
||||
BeaconState, SignedBeaconBlock
|
||||
|
@ -94,7 +91,7 @@ suite "EF - Altair - Transition " & preset():
|
|||
runTest(
|
||||
phase0.BeaconState, altair.BeaconState, phase0.SignedBeaconBlock,
|
||||
altair.SignedBeaconBlock, cfg, "EF - Altair - Transition", TransitionDir,
|
||||
path, transitionInfo.fork_block)
|
||||
suiteName, path, transitionInfo.fork_block)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/bellatrix import
|
||||
BeaconState, SignedBeaconBlock
|
||||
|
@ -110,7 +107,7 @@ suite "EF - Bellatrix - Transition " & preset():
|
|||
runTest(
|
||||
altair.BeaconState, bellatrix.BeaconState, altair.SignedBeaconBlock,
|
||||
bellatrix.SignedBeaconBlock, cfg, "EF - Bellatrix - Transition",
|
||||
TransitionDir, path, transitionInfo.fork_block)
|
||||
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/capella import
|
||||
BeaconState, SignedBeaconBlock
|
||||
|
@ -126,7 +123,7 @@ suite "EF - Capella - Transition " & preset():
|
|||
runTest(
|
||||
bellatrix.BeaconState, capella.BeaconState, bellatrix.SignedBeaconBlock,
|
||||
capella.SignedBeaconBlock, cfg, "EF - Capella - Transition",
|
||||
TransitionDir, path, transitionInfo.fork_block)
|
||||
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
||||
|
||||
from ../../beacon_chain/spec/datatypes/deneb import
|
||||
BeaconState, SignedBeaconBlock
|
||||
|
@ -142,4 +139,4 @@ suite "EF - Deneb - Transition " & preset():
|
|||
runTest(
|
||||
capella.BeaconState, deneb.BeaconState, capella.SignedBeaconBlock,
|
||||
deneb.SignedBeaconBlock, cfg, "EF - Deneb - Transition",
|
||||
TransitionDir, path, transitionInfo.fork_block)
|
||||
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
||||
|
|
|
@ -160,11 +160,11 @@ suite "Light client" & preset():
|
|||
var store {.noinit.}: ForkedLightClientStore
|
||||
withForkyBootstrap(bootstrap):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
var storeRes = initialize_light_client_store(
|
||||
trusted_block_root, forkyBootstrap, cfg)
|
||||
check storeRes.isOk
|
||||
store = ForkedLightClientStore(kind: lcDataFork)
|
||||
store.forky(lcDataFork) = storeRes.get
|
||||
var storeRes = newClone(initialize_light_client_store(
|
||||
trusted_block_root, forkyBootstrap, cfg))
|
||||
check storeRes[].isOk
|
||||
store = (ref ForkedLightClientStore)(kind: lcDataFork)[]
|
||||
store.forky(lcDataFork) = storeRes[].get
|
||||
|
||||
# Sync to latest sync committee period
|
||||
var numIterations = 0
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b178f47527074964f76c395ad0dfc81cf118f379
|
||||
Subproject commit e1b7a9f418342bc93132fb954ada9ded7defed80
|
Loading…
Reference in New Issue