use v1.1.0 phase 0 test vectors (#2592)

* use v1.1.0 phase 0 test vectors

* re-export process_final_updates()
This commit is contained in:
tersec 2021-05-24 08:42:40 +00:00 committed by GitHub
parent 584fcd50c1
commit 3a59dc16c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 189 additions and 96 deletions

View File

@ -5,7 +5,6 @@ AllTests-mainnet
+ BASE_REWARD_FACTOR 64 [Preset: mainnet] OK
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: mainnet] OK
+ CHURN_LIMIT_QUOTIENT 65536 [Preset: mainnet] OK
CONFIG_NAME "mainnet" [Preset: mainnet] Skip
DEPOSIT_CHAIN_ID 1 [Preset: mainnet] Skip
DEPOSIT_CONTRACT_ADDRESS "0x00000000219ab540356cBB839Cbe05303d770 Skip
DEPOSIT_NETWORK_ID 1 [Preset: mainnet] Skip
@ -63,7 +62,7 @@ AllTests-mainnet
+ VALIDATOR_REGISTRY_LIMIT 1099511627776 [Preset: mainnet] OK
+ WHISTLEBLOWER_REWARD_QUOTIENT 512 [Preset: mainnet] OK
```
OK: 51/60 Fail: 0/60 Skip: 9/60
OK: 51/59 Fail: 0/59 Skip: 8/59
## Attestation pool processing [Preset: mainnet]
```diff
+ Attestations may arrive in any order [Preset: mainnet] OK
@ -323,4 +322,4 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
OK: 1/1 Fail: 0/1 Skip: 0/1
---TOTAL---
OK: 180/189 Fail: 0/189 Skip: 9/189
OK: 180/188 Fail: 0/188 Skip: 8/188

View File

@ -24,9 +24,11 @@ FixtureAll-mainnet
+ Rewards - full_random_0 [Preset: mainnet] OK
+ Rewards - full_random_1 [Preset: mainnet] OK
+ Rewards - full_random_2 [Preset: mainnet] OK
+ Rewards - full_random_3 [Preset: mainnet] OK
+ Rewards - full_random_five_epoch_leak [Preset: mainnet] OK
+ Rewards - full_random_leak [Preset: mainnet] OK
+ Rewards - full_random_low_balances [Preset: mainnet] OK
+ Rewards - full_random_low_balances_0 [Preset: mainnet] OK
+ Rewards - full_random_low_balances_1 [Preset: mainnet] OK
+ Rewards - full_random_misc_balances [Preset: mainnet] OK
+ Rewards - full_random_ten_epoch_leak [Preset: mainnet] OK
+ Rewards - half_full [Preset: mainnet] OK
@ -84,12 +86,16 @@ FixtureAll-mainnet
+ [Invalid] att2_high_index OK
+ [Invalid] bad_source_root OK
+ [Invalid] before_inclusion_delay OK
+ [Invalid] correct_after_epoch_delay OK
+ [Invalid] empty_participants_seemingly_valid_sig OK
+ [Invalid] empty_participants_zeroes_sig OK
+ [Invalid] epochs_are_different OK
+ [Invalid] future_target_epoch OK
+ [Invalid] headers_are_same_sigs_are_different OK
+ [Invalid] headers_are_same_sigs_are_same OK
+ [Invalid] incorrect_head_after_epoch_delay OK
+ [Invalid] incorrect_head_and_target_after_epoch_delay OK
+ [Invalid] incorrect_target_after_epoch_delay OK
+ [Invalid] invalid_attestation_signature OK
+ [Invalid] invalid_current_source_root OK
+ [Invalid] invalid_different_proposer_indices OK
@ -138,11 +144,6 @@ FixtureAll-mainnet
+ [Valid] new_deposit_under_max OK
+ [Valid] success_top_up OK
+ [Valid] valid_sig_but_forked_state OK
+ [Valid] Official - Finality - finality_no_updates_at_genesis [Preset: mainnet] OK
+ [Valid] Official - Finality - finality_rule_1 [Preset: mainnet] OK
+ [Valid] Official - Finality - finality_rule_2 [Preset: mainnet] OK
+ [Valid] Official - Finality - finality_rule_3 [Preset: mainnet] OK
+ [Valid] Official - Finality - finality_rule_4 [Preset: mainnet] OK
+ [Valid] Official - Sanity - Blocks - attestation [Preset: mainnet] OK
+ [Valid] Official - Sanity - Blocks - attester_slashing [Preset: mainnet] OK
+ [Valid] Official - Sanity - Blocks - balance_driven_status_transitions [Preset: mainnet] OK
@ -166,27 +167,50 @@ FixtureAll-mainnet
+ [Valid] Official - Sanity - Blocks - skipped_slots [Preset: mainnet] OK
+ [Valid] Official - Sanity - Blocks - slash_and_exit_diff_index [Preset: mainnet] OK
+ [Valid] Official - Sanity - Blocks - voluntary_exit [Preset: mainnet] OK
+ [Valid] correct_epoch_delay OK
+ [Valid] correct_min_inclusion_delay OK
+ [Valid] correct_sqrt_epoch_delay OK
+ [Valid] default_exit_epoch_subsequent_exit OK
+ [Valid] incorrect_head_and_target_epoch_delay OK
+ [Valid] incorrect_head_and_target_min_inclusion_delay OK
+ [Valid] incorrect_head_and_target_sqrt_epoch_delay OK
+ [Valid] incorrect_head_epoch_delay OK
+ [Valid] incorrect_head_min_inclusion_delay OK
+ [Valid] incorrect_head_sqrt_epoch_delay OK
+ [Valid] incorrect_target_epoch_delay OK
+ [Valid] incorrect_target_min_inclusion_delay OK
+ [Valid] incorrect_target_sqrt_epoch_delay OK
+ [Valid] success OK
+ [Valid] success_already_exited_long_ago OK
+ [Valid] success_already_exited_recent OK
+ [Valid] success_block_header OK
+ [Valid] success_double OK
+ [Valid] success_exit_queue OK
+ [Valid] success_low_balances OK
+ [Valid] success_misc_balances OK
+ [Valid] success_multi_proposer_index_iterations OK
+ [Valid] success_previous_epoch OK
+ [Valid] success_slashed_and_proposer_index_the_same OK
+ [Valid] success_surround OK
+ [Valid] success_with_effective_balance_disparity OK
```
OK: 175/175 Fail: 0/175 Skip: 0/175
## Official - Epoch Processing - Final updates [Preset: mainnet]
OK: 191/191 Fail: 0/191 Skip: 0/191
## Official - Epoch Processing - Effective balance updates [Preset: mainnet]
```diff
+ Final updates - effective_balance_hysteresis [Preset: mainnet] OK
+ Final updates - eth1_vote_no_reset [Preset: mainnet] OK
+ Final updates - eth1_vote_reset [Preset: mainnet] OK
+ Final updates - historical_root_accumulator [Preset: mainnet] OK
+ Effective balance updates - effective_balance_hysteresis [Preset: mainnet] OK
```
OK: 4/4 Fail: 0/4 Skip: 0/4
OK: 1/1 Fail: 0/1 Skip: 0/1
## Official - Epoch Processing - Eth1 data reset [Preset: mainnet]
```diff
+ Eth1 data reset - eth1_vote_no_reset [Preset: mainnet] OK
+ Eth1 data reset - eth1_vote_reset [Preset: mainnet] OK
```
OK: 2/2 Fail: 0/2 Skip: 0/2
## Official - Epoch Processing - Historical roots update [Preset: mainnet]
```diff
+ Historical roots update - historical_root_accumulator [Preset: mainnet] OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## Official - Epoch Processing - Justification & Finalization [Preset: mainnet]
```diff
+ Justification & Finalization - 123_ok_support [Preset: mainnet] OK
@ -200,6 +224,16 @@ OK: 4/4 Fail: 0/4 Skip: 0/4
+ Justification & Finalization - 23_poor_support [Preset: mainnet] OK
```
OK: 9/9 Fail: 0/9 Skip: 0/9
## Official - Epoch Processing - Participation record updates [Preset: mainnet]
```diff
+ Participation record updates - updated_participation_record [Preset: mainnet] OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## Official - Epoch Processing - RANDAO mixes reset [Preset: mainnet]
```diff
+ RANDAO mixes reset - updated_randao_mixes [Preset: mainnet] OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## Official - Epoch Processing - Registry updates [Preset: mainnet]
```diff
+ Registry updates - activation_queue_activation_and_ejection [Preset: mainnet] OK
@ -214,11 +248,17 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
OK: 8/8 Fail: 0/8 Skip: 0/8
## Official - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
+ Slashings - max_penalties [Preset: mainnet] OK
+ Slashings - minimal_penalty [Preset: mainnet] OK
+ Slashings - scaled_penalties [Preset: mainnet] OK
+ Slashings - small_penalty [Preset: mainnet] OK
```
OK: 3/3 Fail: 0/3 Skip: 0/3
OK: 4/4 Fail: 0/4 Skip: 0/4
## Official - Epoch Processing - Slashings reset [Preset: mainnet]
```diff
+ Slashings reset - flush_slashings [Preset: mainnet] OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
---TOTAL---
OK: 199/199 Fail: 0/199 Skip: 0/199
OK: 219/219 Fail: 0/219 Skip: 0/219

View File

@ -466,7 +466,7 @@ func process_slashings*(state: var BeaconState, total_balance: Gwei) {.nbench.}=
decrease_balance(state, index.ValidatorIndex, penalty)
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#eth1-data-votes-updates
func process_eth1_data_reset(state: var BeaconState) {.nbench.} =
func process_eth1_data_reset*(state: var BeaconState) {.nbench.} =
let next_epoch = get_current_epoch(state) + 1
# Reset eth1 data votes
@ -474,7 +474,7 @@ func process_eth1_data_reset(state: var BeaconState) {.nbench.} =
state.eth1_data_votes = default(type state.eth1_data_votes)
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates
func process_effective_balance_updates(state: var BeaconState) {.nbench.} =
func process_effective_balance_updates*(state: var BeaconState) {.nbench.} =
# Update effective balances with hysteresis
for index in 0..<state.validators.len:
let balance = state.balances.asSeq()[index]
@ -493,14 +493,14 @@ func process_effective_balance_updates(state: var BeaconState) {.nbench.} =
MAX_EFFECTIVE_BALANCE)
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#slashings-balances-updates
func process_slashings_reset(state: var BeaconState) {.nbench.} =
func process_slashings_reset*(state: var BeaconState) {.nbench.} =
let next_epoch = get_current_epoch(state) + 1
# Reset slashings
state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#randao-mixes-updates
func process_randao_mixes_reset(state: var BeaconState) {.nbench.} =
func process_randao_mixes_reset*(state: var BeaconState) {.nbench.} =
let
current_epoch = get_current_epoch(state)
next_epoch = current_epoch + 1
@ -510,7 +510,7 @@ func process_randao_mixes_reset(state: var BeaconState) {.nbench.} =
get_randao_mix(state, current_epoch)
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#historical-roots-updates
func process_historical_roots_update(state: var BeaconState) {.nbench.} =
func process_historical_roots_update*(state: var BeaconState) {.nbench.} =
# Set historical root accumulator
let next_epoch = get_current_epoch(state) + 1
@ -524,7 +524,7 @@ func process_historical_roots_update(state: var BeaconState) {.nbench.} =
raiseAssert "no more room for historical roots, so long and thanks for the fish!"
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#participation-records-rotation
func process_participation_record_updates(state: var BeaconState) {.nbench.} =
func process_participation_record_updates*(state: var BeaconState) {.nbench.} =
# Rotate current/previous epoch attestations - using swap avoids copying all
# elements using a slow genericSeqAssign
state.previous_epoch_attestations.clear()

View File

@ -11,7 +11,8 @@ import
# Internals
../../beacon_chain/ssz,
../../beacon_chain/spec/[datatypes, crypto, state_transition_epoch],
# Status libs
# Status libs,
snappy,
stew/byteutils,
serialization, json_serialization
@ -28,7 +29,7 @@ export # Workaround:
# #######################
# JSON deserialization
proc readValue*(r: var JsonReader, a: var seq[byte]) =
func readValue*(r: var JsonReader, a: var seq[byte]) =
## Custom deserializer for seq[byte]
a = hexToSeqByte(r.readValue(string))
@ -42,9 +43,10 @@ type
const
FixturesDir* =
currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
SszTestsDir* = FixturesDir / "tests-v" & SPEC_VERSION
SszTestsDir* = FixturesDir / "tests-v1.1.0-alpha.5"
MaxObjectSize* = 3_000_000
proc parseTest*(path: string, Format: typedesc[Json or SSZ], T: typedesc): T =
proc parseTest*(path: string, Format: typedesc[Json], T: typedesc): T =
try:
# debugEcho " [Debug] Loading file: \"", path, '\"'
result = Format.loadFile(path, T)
@ -65,6 +67,16 @@ proc sszDecodeEntireInput*(input: openArray[byte], Decoded: type): Decoded =
if stream.readable:
raise newException(UnconsumedInput, "Remaining bytes in the input")
proc parseTest*(path: string, Format: typedesc[SSZ], T: typedesc): T =
try:
# debugEcho " [Debug] Loading file: \"", path, '\"'
sszDecodeEntireInput(snappy.decode(readFileBytes(path), MaxObjectSize), T)
except SerializationError as err:
writeStackTrace()
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write err.formatMsg(path), "\n"
quit 1
proc process_justification_and_finalization*(state: var BeaconState) =
var cache = StateCache()
@ -73,7 +85,7 @@ proc process_justification_and_finalization*(state: var BeaconState) =
rewards.process_attestations(state, cache)
process_justification_and_finalization(state, rewards.total_balances)
proc process_slashings*(state: var BeaconState) =
func process_slashings*(state: var BeaconState) =
var cache = StateCache()
var rewards: RewardInfo
rewards.init(state)

View File

@ -34,7 +34,7 @@ proc runTest(identifier: string) =
proc `testImpl _ operations_attestations _ identifier`() =
var prefix: string
if existsFile(testDir/"post.ssz"):
if existsFile(testDir/"post.ssz_snappy"):
prefix = "[Valid] "
else:
prefix = "[Invalid] "
@ -42,11 +42,14 @@ proc runTest(identifier: string) =
test prefix & identifier:
var cache = StateCache()
let attestation = parseTest(testDir/"attestation.ssz", SSZ, Attestation)
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
let attestation =
parseTest(testDir/"attestation.ssz_snappy", SSZ, Attestation)
var preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
if existsFile(testDir/"post.ssz"):
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
if existsFile(testDir/"post.ssz_snappy"):
let postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
let done = process_attestation(preState[], attestation, {}, cache).isOk
doAssert done, "Valid attestation not processed"
check: preState[].hash_tree_root() == postState[].hash_tree_root()

View File

@ -33,21 +33,25 @@ proc runTest(identifier: string) =
proc `testImpl _ operations_attester_slashing _ identifier`() =
var prefix: string
if existsFile(testDir/"post.ssz"):
if existsFile(testDir/"post.ssz_snappy"):
prefix = "[Valid] "
else:
prefix = "[Invalid] "
test prefix & identifier:
var cache = StateCache()
let attesterSlashing =
parseTest(testDir/"attester_slashing.ssz_snappy", SSZ, AttesterSlashing)
var
cache = StateCache()
preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
let attesterSlashing = parseTest(testDir/"attester_slashing.ssz", SSZ, AttesterSlashing)
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
if existsFile(testDir/"post.ssz"):
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
let done = process_attester_slashing(preState[], attesterSlashing,
{}, cache).isOk
if existsFile(testDir/"post.ssz_snappy"):
let
postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
done = process_attester_slashing(preState[], attesterSlashing,
{}, cache).isOk
doAssert done, "Valid attestater slashing not processed"
check: preState[].hash_tree_root() == postState[].hash_tree_root()
reportDiff(preState, postState)

View File

@ -33,20 +33,23 @@ proc runTest(identifier: string) =
proc `testImpl _ blockheader _ identifier`() =
var prefix: string
if existsFile(testDir/"post.ssz"):
if existsFile(testDir/"post.ssz_snappy"):
prefix = "[Valid] "
else:
prefix = "[Invalid] "
test prefix & identifier:
var cache = StateCache()
let blck = parseTest(testDir/"block.ssz_snappy", SSZ, BeaconBlock)
var
cache = StateCache()
preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
let blck = parseTest(testDir/"block.ssz", SSZ, BeaconBlock)
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
if existsFile(testDir/"post.ssz"):
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
let done = process_block_header(preState[], blck, {}, cache).isOk
if existsFile(testDir/"post.ssz_snappy"):
let
postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
done = process_block_header(preState[], blck, {}, cache).isOk
doAssert done, "Valid block header not processed"
check: preState[].hash_tree_root() == postState[].hash_tree_root()
reportDiff(preState, postState)

View File

@ -33,17 +33,19 @@ proc runTest(identifier: string) =
proc `testImpl _ operations_deposits _ identifier`() =
var prefix: string
if existsFile(testDir/"post.ssz"):
if existsFile(testDir/"post.ssz_snappy"):
prefix = "[Valid] "
else:
prefix = "[Invalid] "
test prefix & " " & identifier:
let deposit = parseTest(testDir/"deposit.ssz", SSZ, Deposit)
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
let deposit = parseTest(testDir/"deposit.ssz_snappy", SSZ, Deposit)
var preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
if existsFile(testDir/"post.ssz"):
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
if existsFile(testDir/"post.ssz_snappy"):
let postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
discard process_deposit(defaultRuntimePreset, preState[], deposit)
reportDiff(preState, postState)
else:

View File

@ -33,20 +33,25 @@ proc runTest(identifier: string) =
proc `testImpl_proposer_slashing _ identifier`() =
var prefix: string
if existsFile(testDir/"post.ssz"):
if existsFile(testDir/"post.ssz_snappy"):
prefix = "[Valid] "
else:
prefix = "[Invalid] "
test prefix & identifier:
let proposerSlashing = parseTest(testDir/"proposer_slashing.ssz", SSZ, ProposerSlashing)
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
let proposerSlashing = parseTest(
testDir/"proposer_slashing.ssz_snappy", SSZ, ProposerSlashing)
var
preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
cache = StateCache()
var cache = StateCache()
if existsFile(testDir/"post.ssz"):
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
let done = process_proposer_slashing(preState[], proposerSlashing, {}, cache).isOk
if existsFile(testDir/"post.ssz_snappy"):
let
postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
done = process_proposer_slashing(
preState[], proposerSlashing, {}, cache).isOk
doAssert done, "Valid proposer slashing not processed"
check: preState[].hash_tree_root() == postState[].hash_tree_root()
reportDiff(preState, postState)

View File

@ -33,21 +33,25 @@ proc runTest(identifier: string) =
proc `testImpl _ voluntary_exit _ identifier`() =
var prefix: string
if existsFile(testDir/"post.ssz"):
if existsFile(testDir/"post.ssz_snappy"):
prefix = "[Valid] "
else:
prefix = "[Invalid] "
test prefix & identifier:
let voluntaryExit = parseTest(testDir/"voluntary_exit.ssz", SSZ, SignedVoluntaryExit)
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
let voluntaryExit = parseTest(
testDir/"voluntary_exit.ssz_snappy", SSZ, SignedVoluntaryExit)
var
preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
cache = StateCache()
var cache = StateCache()
if existsFile(testDir/"post.ssz"):
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
let done =
process_voluntary_exit(preState[], voluntaryExit, {}, cache).isOk
if existsFile(testDir/"post.ssz_snappy"):
let
postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
done =
process_voluntary_exit(preState[], voluntaryExit, {}, cache).isOk
doAssert done, "Valid voluntary exit not processed"
check: preState[].hash_tree_root() == postState[].hash_tree_root()
reportDiff(preState, postState)

View File

@ -50,16 +50,18 @@ proc runTest(rewardsDir, identifier: string) =
proc `testImpl _ rewards _ identifier`() =
test "Rewards" & " - " & identifier & preset():
var
state = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
state = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
cache = StateCache()
let
sourceDeltas = parseTest(testDir/"source_deltas.ssz", SSZ, Deltas)
targetDeltas = parseTest(testDir/"target_deltas.ssz", SSZ, Deltas)
headDeltas = parseTest(testDir/"head_deltas.ssz", SSZ, Deltas)
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", SSZ, Deltas)
parseTest(testDir/"inclusion_delay_deltas.ssz_snappy", SSZ, Deltas)
inactivityPenaltyDeltas =
parseTest(testDir/"inactivity_penalty_deltas.ssz", SSZ, Deltas)
parseTest(testDir/"inactivity_penalty_deltas.ssz_snappy", SSZ, Deltas)
var
rewards = RewardInfo()

View File

@ -31,12 +31,12 @@ proc runTest(testName, testDir, unitTestName: string) =
proc `testImpl _ blck _ testName`() =
let
hasPostState = existsFile(testPath/"post.ssz")
hasPostState = existsFile(testPath/"post.ssz_snappy")
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
test prefix & testName & " - " & unitTestName & preset():
var
preState = newClone(parseTest(testPath/"pre.ssz", SSZ, BeaconState))
preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, BeaconState))
hashedPreState = (ref HashedBeaconState)(
data: preState[], root: hash_tree_root(preState[]))
cache = StateCache()
@ -44,9 +44,9 @@ proc runTest(testName, testDir, unitTestName: string) =
# 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")).len
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
for i in 0 ..< numBlocks:
let blck = parseTest(testPath/"blocks_" & $i & ".ssz", SSZ, SignedBeaconBlock)
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, SignedBeaconBlock)
if hasPostState:
let success = state_transition(
@ -61,7 +61,7 @@ proc runTest(testName, testDir, unitTestName: string) =
"We didn't expect these invalid blocks to be processed"
if hasPostState:
let postState = newClone(parseTest(testPath/"post.ssz", SSZ, BeaconState))
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, BeaconState))
when false:
reportDiff(hashedPreState.data, postState)
doAssert hashedPreState.root == postState[].hash_tree_root()

View File

@ -27,12 +27,12 @@ proc runTest(identifier: string) =
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
hashedPreState = (ref HashedBeaconState)(
data: preState[], root: hash_tree_root(preState[]))
cache = StateCache()
rewards: RewardInfo
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
check:
process_slots(

View File

@ -14,6 +14,8 @@ import
# Beacon chain internals
../../beacon_chain/spec/[crypto, datatypes, digest],
../../beacon_chain/ssz,
# Status libraries
snappy,
# Test utilities
../testutil, ./fixtures_utils
@ -45,7 +47,8 @@ type
proc checkSSZ(T: type SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
# Deserialize into a ref object to not fill Nim stack
let encoded = readFileBytes(dir/"serialized.ssz")
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
var deserialized = newClone(sszDecodeEntireInput(encoded, T))
# SignedBeaconBlocks usually not hashed because they're identified by
@ -62,7 +65,8 @@ proc checkSSZ(T: type SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeR
proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
# Deserialize into a ref object to not fill Nim stack
let encoded = readFileBytes(dir/"serialized.ssz")
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
var deserialized = newClone(sszDecodeEntireInput(encoded, T))
check: expectedHash.root == "0x" & toLowerASCII($hash_tree_root(deserialized[]))

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2020 Status Research & Development GmbH
# Copyright (c) 2018-2021 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).
@ -10,7 +10,7 @@ import
os, strutils, streams, strformat, strscans,
macros, typetraits,
# Status libraries
faststreams, ../testutil,
faststreams, snappy, ../testutil,
# Third-party
yaml,
# Beacon chain internals
@ -82,7 +82,7 @@ type
proc checkBasic(T: typedesc,
dir: string,
expectedHash: SSZHashTreeRoot) =
var fileContents = readFileBytes(dir/"serialized.ssz")
var fileContents = snappy.decode(readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
var deserialized = newClone(sszDecodeEntireInput(fileContents, T))
let expectedHash = expectedHash.root

View File

@ -29,8 +29,8 @@ template runSuite(suiteDir, testName: string, transitionProc: untyped{ident}, us
let unitTestName = testDir.rsplit(DirSep, 1)[1]
test testName & " - " & unitTestName & preset():
# BeaconState objects are stored on the heap to avoid stack overflow
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
var preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState))
let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
when useCache:
var cache = StateCache()
@ -66,5 +66,20 @@ runSuite(SlashingsDir, "Slashings", process_slashings, useCache = false)
# Final updates
# ---------------------------------------------------------------
const FinalUpdatesDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"final_updates"/"pyspec_tests"
runSuite(FinalUpdatesDir, "Final updates", process_final_updates, useCache = false)
const Eth1DataResetDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"eth1_data_reset/"/"pyspec_tests"
runSuite(Eth1DataResetDir, "Eth1 data reset", process_eth1_data_reset, useCache = false)
const EffectiveBalanceUpdatesDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"effective_balance_updates"/"pyspec_tests"
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates", process_effective_balance_updates, useCache = false)
const SlashingsResetDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"slashings_reset"/"pyspec_tests"
runSuite(SlashingsResetDir, "Slashings reset", process_slashings_reset, useCache = false)
const RandaoMixesResetDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"randao_mixes_reset"/"pyspec_tests"
runSuite(RandaoMixesResetDir, "RANDAO mixes reset", process_randao_mixes_reset, useCache = false)
const HistoricalRootsUpdateDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"historical_roots_update"/"pyspec_tests"
runSuite(HistoricalRootsUpdateDir, "Historical roots update", process_historical_roots_update, useCache = false)
const ParticipationRecordsDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"participation_record_updates"/"pyspec_tests"
runSuite(ParticipationRecordsDir, "Participation record updates", process_participation_record_updates, useCache = false)