refactor executionPayload tests; reduce HashSet creation (#3003)

This commit is contained in:
tersec 2021-10-20 11:36:38 +00:00 committed by GitHub
parent 44d762119c
commit c0a2f1c98e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 122 additions and 200 deletions

View File

@ -188,19 +188,6 @@ ConsensusSpecPreset-mainnet
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: mainne OK
+ [Invalid] bad_everything_regular_payload OK
+ [Invalid] bad_execution_first_payload OK
+ [Invalid] bad_execution_regular_payload OK
+ [Invalid] bad_number_regular_payload OK
+ [Invalid] bad_parent_hash_regular_payload OK
+ [Invalid] bad_random_first_payload OK
+ [Invalid] bad_random_regular_payload OK
+ [Invalid] bad_timestamp_first_payload OK
+ [Invalid] bad_timestamp_regular_payload OK
+ [Invalid] gaslimit_lower_minus_regular_payload OK
+ [Invalid] gaslimit_minimum_minus_regular_payload OK
+ [Invalid] gaslimit_upper_plus_regular_payload OK
+ [Invalid] gasused_gaslimit_plus_regular_payload OK
+ [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: mainnet] OK
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: mainnet] OK
@ -334,16 +321,6 @@ ConsensusSpecPreset-mainnet
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: mainnet OK
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: mainne OK
+ [Valid] gaslimit_lower_regular_payload OK
+ [Valid] gaslimit_max_first_payload OK
+ [Valid] gaslimit_minimum_regular_payload OK
+ [Valid] gaslimit_upper_regular_payload OK
+ [Valid] gaslimit_zero_first_payload OK
+ [Valid] gasused_gaslimit_regular_payload OK
+ [Valid] success_first_payload OK
+ [Valid] success_first_payload_with_gap_slot OK
+ [Valid] success_regular_payload OK
+ [Valid] success_regular_payload_with_gap_slot OK
+ altair_fork_random_0 OK
+ altair_fork_random_1 OK
+ altair_fork_random_2 OK
@ -361,7 +338,7 @@ ConsensusSpecPreset-mainnet
+ fork_random_misc_balances OK
+ next_sync_committee_merkle_proof OK
```
OK: 358/358 Fail: 0/358 Skip: 0/358
OK: 335/335 Fail: 0/335 Skip: 0/335
## Attestation
```diff
+ [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK
@ -1028,6 +1005,33 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Testing VoluntaryExit OK
```
OK: 27/27 Fail: 0/27 Skip: 0/27
## Execution Payload
```diff
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_everything_re OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_fir OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_reg OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_number_regula OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_parent_hash_r OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_first_ OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_regula OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_fir OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_reg OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_mi OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_pl OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_re OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_max_firs OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_re OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_zero_fir OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
```
OK: 23/23 Fail: 0/23 Skip: 0/23
## Proposer Slashing
```diff
+ [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK

View File

@ -190,19 +190,6 @@ ConsensusSpecPreset-minimal
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: minima OK
+ [Invalid] bad_everything_regular_payload OK
+ [Invalid] bad_execution_first_payload OK
+ [Invalid] bad_execution_regular_payload OK
+ [Invalid] bad_number_regular_payload OK
+ [Invalid] bad_parent_hash_regular_payload OK
+ [Invalid] bad_random_first_payload OK
+ [Invalid] bad_random_regular_payload OK
+ [Invalid] bad_timestamp_first_payload OK
+ [Invalid] bad_timestamp_regular_payload OK
+ [Invalid] gaslimit_lower_minus_regular_payload OK
+ [Invalid] gaslimit_minimum_minus_regular_payload OK
+ [Invalid] gaslimit_upper_plus_regular_payload OK
+ [Invalid] gasused_gaslimit_plus_regular_payload OK
+ [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: minimal] OK
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: minimal] OK
@ -351,20 +338,10 @@ ConsensusSpecPreset-minimal
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: minimal OK
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: minima OK
+ [Valid] gaslimit_lower_regular_payload OK
+ [Valid] gaslimit_max_first_payload OK
+ [Valid] gaslimit_minimum_regular_payload OK
+ [Valid] gaslimit_upper_regular_payload OK
+ [Valid] gaslimit_zero_first_payload OK
+ [Valid] gasused_gaslimit_regular_payload OK
+ [Valid] success_first_payload OK
+ [Valid] success_first_payload_with_gap_slot OK
+ [Valid] success_regular_payload OK
+ [Valid] success_regular_payload_with_gap_slot OK
+ finality_root_merkle_proof OK
+ next_sync_committee_merkle_proof OK
```
OK: 361/361 Fail: 0/361 Skip: 0/361
OK: 338/338 Fail: 0/338 Skip: 0/338
## Attestation
```diff
+ [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK
@ -1065,6 +1042,33 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Testing VoluntaryExit OK
```
OK: 27/27 Fail: 0/27 Skip: 0/27
## Execution Payload
```diff
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_everything_re OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_fir OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_reg OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_number_regula OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_parent_hash_r OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_first_ OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_regula OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_fir OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_reg OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_mi OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_pl OK
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_re OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_max_firs OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_re OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_zero_fir OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
```
OK: 23/23 Fail: 0/23 Skip: 0/23
## Proposer Slashing
```diff
+ [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK

View File

@ -9,7 +9,7 @@
import
# Standard libraries
std/[deques, sets, intsets],
std/[deques, sets],
# Status libraries
chronicles,
# Internal
@ -17,7 +17,7 @@ import
../spec/datatypes/[phase0, altair, merge],
./blockchain_dag
export phase0, altair, merge, deques, intsets, sets, blockchain_dag
export phase0, altair, merge, deques, sets, blockchain_dag
logScope: topics = "exitpool"
@ -43,13 +43,13 @@ type
voluntary_exits*: Deque[SignedVoluntaryExit] ## \
## Not a function of chain DAG branch; just used as a FIFO queue for blocks
prior_seen_attester_slashed_indices*: IntSet ## \
prior_seen_attester_slashed_indices*: HashSet[uint64] ## \
## Records attester-slashed indices seen.
prior_seen_proposer_slashed_indices*: IntSet ## \
prior_seen_proposer_slashed_indices*: HashSet[uint64] ## \
## Records proposer-slashed indices seen.
prior_seen_voluntary_exit_indices*: IntSet ##\
prior_seen_voluntary_exit_indices*: HashSet[uint64] ##\
## Records voluntary exit indices seen.
dag*: ChainDAGRef
@ -79,18 +79,13 @@ func addExitMessage*(subpool: var auto, exitMessage, bound: auto) =
doAssert subpool.lenu64 <= bound
iterator getValidatorIndices(attester_slashing: AttesterSlashing): uint64 =
# TODO rely on sortedness and do this sans memory allocations, but it's only
# when producing a beacon block, which is rare bottlenecked elsewhere.
let
attestation_1_indices =
attester_slashing.attestation_1.attesting_indices.asSeq
attestation_2_indices =
attester_slashing.attestation_2.attesting_indices.asSeq
attester_slashed_indices =
toIntSet(attestation_1_indices) * toIntSet(attestation_2_indices)
let attestation_2_indices =
toHashSet(attester_slashing.attestation_2.attesting_indices.asSeq)
for validator_index in attester_slashed_indices:
yield validator_index.uint64
for validator_index in attester_slashing.attestation_1.attesting_indices.asSeq:
if validator_index notin attestation_2_indices:
continue
yield validator_index
iterator getValidatorIndices(proposer_slashing: ProposerSlashing): uint64 =
yield proposer_slashing.signed_header_1.message.proposer_index

View File

@ -8,7 +8,7 @@
{.push raises: [Defect].}
import
std/[intsets],
std/sequtils,
chronicles,
../extras,
../spec/[helpers, network, signatures, validator],
@ -173,9 +173,8 @@ func makeAttestationData*(
# https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#validator-assignments
iterator get_committee_assignments*(
epochRef: EpochRef, validator_indices: IntSet):
tuple[validatorIndices: IntSet,
committeeIndex: CommitteeIndex,
epochRef: EpochRef, validator_indices: HashSet[ValidatorIndex]):
tuple[committeeIndex: CommitteeIndex,
subnet_id: SubnetId, slot: Slot] =
let
committees_per_slot = get_committee_count_per_slot(epochRef)
@ -186,12 +185,10 @@ iterator get_committee_assignments*(
for index in 0'u64 ..< committees_per_slot:
let
idx = index.CommitteeIndex
includedIndices =
toIntSet(get_beacon_committee(epochRef, slot, idx)) *
validator_indices
if includedIndices.len > 0:
if anyIt(
get_beacon_committee(epochRef, slot, idx), it in validator_indices):
yield (
includedIndices, idx,
idx,
compute_subnet_for_attestation(committees_per_slot, slot, idx),
slot)

View File

@ -8,8 +8,6 @@
{.push raises: [Defect].}
import
# Standard library
std/[intsets],
# Status
chronicles, chronos, metrics,
stew/results,
@ -669,7 +667,7 @@ proc validateAttesterSlashing*(
attestation_2_indices =
attester_slashing.attestation_2.attesting_indices.asSeq
attester_slashed_indices =
toIntSet(attestation_1_indices) * toIntSet(attestation_2_indices)
toHashSet(attestation_1_indices) * toHashSet(attestation_2_indices)
if not disjoint(
attester_slashed_indices, pool.prior_seen_attester_slashed_indices):
@ -699,7 +697,7 @@ proc validateProposerSlashing*(
# [IGNORE] The proposer slashing is the first valid proposer slashing
# received for the proposer with index
# proposer_slashing.signed_header_1.message.proposer_index.
if proposer_slashing.signed_header_1.message.proposer_index.int in
if proposer_slashing.signed_header_1.message.proposer_index in
pool.prior_seen_proposer_slashed_indices:
return errIgnore(
"ProposerSlashing: proposer-slashed index already proposer-slashed")
@ -711,7 +709,7 @@ proc validateProposerSlashing*(
return err((ValidationResult.Reject, proposer_slashing_validity.error))
pool.prior_seen_proposer_slashed_indices.incl(
proposer_slashing.signed_header_1.message.proposer_index.int)
proposer_slashing.signed_header_1.message.proposer_index)
pool.proposer_slashings.addExitMessage(
proposer_slashing, PROPOSER_SLASHINGS_BOUND)
ok(true)
@ -729,7 +727,7 @@ proc validateVoluntaryExit*(
# Given that getStateField(pool.dag.headState, validators) is a seq,
# signed_voluntary_exit.message.validator_index.int is already valid, but
# check explicitly if one changes that data structure.
if signed_voluntary_exit.message.validator_index.int in
if signed_voluntary_exit.message.validator_index in
pool.prior_seen_voluntary_exit_indices:
return errIgnore("VoluntaryExit: validator index already voluntarily exited")
@ -742,7 +740,7 @@ proc validateVoluntaryExit*(
return err((ValidationResult.Reject, voluntary_exit_validity.error))
pool.prior_seen_voluntary_exit_indices.incl(
signed_voluntary_exit.message.validator_index.int)
signed_voluntary_exit.message.validator_index)
pool.voluntary_exits.addExitMessage(
signed_voluntary_exit, VOLUNTARY_EXITS_BOUND)

View File

@ -24,9 +24,6 @@
{.push raises: [Defect].}
# std/[intsets, json, strutils, tables],
# stew/byteutils,
import
std/[macros, typetraits, sets, hashes],
chronicles,

View File

@ -31,7 +31,7 @@ export
json_serialization
import
std/[macros, hashes, intsets, strutils, tables, typetraits],
std/[macros, hashes, strutils, tables, typetraits],
stew/[assign2, byteutils],
chronicles,
chronos/timer,
@ -694,15 +694,6 @@ template `==`*(x: uint64, y: ValidatorIndex): bool =
template `==`*(x: ValidatorIndex, y: uint64): bool =
uint64(x) == y
# TODO Nim 1.4, but not Nim 1.2, defines a function by this name, which works
# only on openArray[int]. They do the same thing, so either's fine, when both
# overloads match. The Nim 1.4 stdlib doesn't int-convert but it's a no-op in
# its case regardless.
func toIntSet*[T](x: openArray[T]): IntSet =
result = initIntSet()
for item in items(x):
result.incl(item.int)
template `==`*(x, y: CommitteeIndex): bool =
distinctBase(x) == distinctBase(y)

View File

@ -28,7 +28,7 @@ import ./base
export base
import
std/[macros, intsets, json, strutils, tables],
std/[macros, json, strutils, tables],
stew/[assign2, byteutils], chronicles,
json_serialization/types as jsonTypes

View File

@ -20,7 +20,7 @@
{.push raises: [Defect].}
import
std/[algorithm, intsets, options, sequtils, sets, tables],
std/[algorithm, options, sequtils, sets, tables],
chronicles, metrics,
../extras,
./datatypes/[phase0, altair, merge],
@ -213,9 +213,10 @@ proc check_attester_slashing*(
var slashed_indices: seq[ValidatorIndex]
for index in sorted(toSeq(intersection(
toIntSet(attestation_1.attesting_indices.asSeq),
toIntSet(attestation_2.attesting_indices.asSeq)).items), system.cmp):
let attesting_indices_2 = toHashSet(attestation_2.attesting_indices.asSeq)
for index in sorted(filterIt(
attestation_1.attesting_indices.asSeq, it in attesting_indices_2),
system.cmp):
if is_slashable_validator(
state.validators.asSeq()[index], get_current_epoch(state)):
slashed_indices.add index.ValidatorIndex

View File

@ -1,5 +1,5 @@
import
std/[sequtils, intsets, sets, tables],
std/[sequtils, sets, tables],
chronicles,
bearssl,
eth/p2p/discoveryv5/random2,
@ -167,14 +167,12 @@ proc updateActions*(tracker: var ActionTracker, epochRef: EpochRef) =
return
tracker.lastCalculatedEpoch = epoch
let
validatorIndices = toIntSet(toSeq(tracker.knownValidators.keys()))
let validatorIndices = toHashSet(toSeq(tracker.knownValidators.keys()))
# Update proposals
tracker.proposingSlots[epoch mod 2] = 0
for i, proposer in epochRef.beacon_proposers:
# TODO unsafe int conversion
if proposer.isSome and proposer.get().int in validatorIndices:
if proposer.isSome and proposer.get() in validatorIndices:
tracker.proposingSlots[epoch mod 2] =
tracker.proposingSlots[epoch mod 2] or (1'u32 shl i)
@ -183,7 +181,7 @@ proc updateActions*(tracker: var ActionTracker, epochRef: EpochRef) =
# The relevant bitmaps are 32 bits each.
static: doAssert SLOTS_PER_EPOCH <= 32
for (validatorIndices, committeeIndex, subnet_id, slot) in
for (committeeIndex, subnet_id, slot) in
get_committee_assignments(epochRef, validatorIndices):
doAssert compute_epoch_at_slot(slot) == epoch

View File

@ -9,7 +9,7 @@
import
# Standard library
os, sequtils, sets,
std/[os, sequtils, sets],
# Utilities
chronicles,
unittest2,

View File

@ -36,13 +36,6 @@ type
# Some have a signing_root field
signing_root {.defaultVal: "".}: string
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/validator.md#eth1block
Eth1Block = object
timestamp: uint64
deposit_root: Eth2Digest
deposit_count: uint64
# All other eth1 block fields
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)

View File

@ -40,6 +40,13 @@ type
rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
# https://github.com/ethereum/consensus-specs/blob/v1.1.3/specs/phase0/validator.md#eth1block
Eth1Block* = object
timestamp*: uint64
deposit_root*: Eth2Digest
deposit_count*: uint64
# All other eth1 block fields
const
FixturesDir* =
currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"

View File

@ -9,7 +9,6 @@
import
./test_fixture_operations,
./test_fixture_operations_execution_payload,
./test_fixture_sanity_blocks,
./test_fixture_sanity_slots,
./test_fixture_ssz_consensus_objects,

View File

@ -9,7 +9,7 @@
import
# Standard library
os,
std/[os, sequtils, sets, strutils],
# Utilities
chronicles,
unittest2,
@ -28,12 +28,18 @@ const
OpAttSlashingDir = OpDir/"attester_slashing"
OpBlockHeaderDir = OpDir/"block_header"
OpDepositsDir = OpDir/"deposit"
OpExecutionPayloadDir = OpDir/"execution_payload"
OpProposerSlashingDir = OpDir/"proposer_slashing"
OpSyncAggregateDir = OpDir/"sync_aggregate"
OpVoluntaryExitDir = OpDir/"voluntary_exit"
baseDescription = "Ethereum Foundation - Merge - Operations - "
doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
toHashSet([OpAttestationsDir, OpAttSlashingDir, OpBlockHeaderDir,
OpDepositsDir, OpExecutionPayloadDir, OpProposerSlashingDir,
OpSyncAggregateDir, OpVoluntaryExitDir])
proc runTest[T, U](
testSuiteDir: string, testSuiteName: string, applyFile: string,
applyProc: U, identifier: string) =
@ -116,6 +122,22 @@ suite baseDescription & "Deposit " & preset():
runTest[Deposit, typeof applyDeposit](
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
suite baseDescription & "Execution Payload " & preset():
for path in walkTests(OpExecutionPayloadDir):
proc applyExecutionPayload(
preState: var merge.BeaconState, executionPayload: ExecutionPayload):
Result[void, cstring] =
let payloadValid =
readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml").
contains("execution_valid: true")
func executePayload(_: ExecutionPayload): bool = payloadValid
process_execution_payload(
preState, executionPayload, executePayload)
runTest[ExecutionPayload, typeof applyExecutionPayload](
OpExecutionPayloadDir, "Execution Payload", "execution_payload",
applyExecutionPayload, path)
suite baseDescription & "Proposer Slashing " & preset():
proc applyProposerSlashing(
preState: var merge.BeaconState, proposerSlashing: ProposerSlashing):

View File

@ -1,68 +0,0 @@
# beacon_chain
# 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).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import
# Standard library
std/os, std/strutils,
# Utilities
stew/results,
# Beacon chain internals
../../../beacon_chain/spec/state_transition_block,
../../../beacon_chain/spec/datatypes/merge,
# Test utilities
../../testutil,
../fixtures_utils,
../../helpers/debug_state
const OpExecutionPayloadDir = SszTestsDir/const_preset/"merge"/"operations"/"execution_payload"/"pyspec_tests"
proc runTest(identifier: string) =
let testDir = OpExecutionPayloadDir / identifier
proc `testImpl _ voluntary_exit _ identifier`() =
let
prefix =
if existsFile(testDir/"post.ssz_snappy"):
"[Valid] "
else:
"[Invalid] "
payloadValid = readFile(
testDir/"execution.yaml").contains("execution_valid: true")
func executePayload(_: ExecutionPayload): bool = payloadValid
test prefix & identifier:
var
preState =
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, merge.BeaconState))
let
executionPayload = parseTest(
testDir/"execution_payload.ssz_snappy", SSZ, ExecutionPayload)
done = process_execution_payload(
preState[], executionPayload, executePayload)
if existsFile(testDir/"post.ssz_snappy"):
let postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, merge.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 _ voluntary_exit _ identifier`()
suite "Ethereum Foundation - Merge - Operations - Execution Payload " & preset():
for kind, path in walkDir(
OpExecutionPayloadDir, relative = true, checkDir = true):
runTest(path)

View File

@ -36,13 +36,6 @@ type
# Some have a signing_root field
signing_root {.defaultVal: "".}: string
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.3/specs/phase0/validator.md#eth1block
Eth1Block = object
timestamp: uint64
deposit_root: Eth2Digest
deposit_count: uint64
# All other eth1 block fields
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)

View File

@ -9,7 +9,7 @@
import
# Standard library
os, sequtils, sets,
std/[os, sequtils, sets],
# Utilities
chronicles,
unittest2,

View File

@ -36,13 +36,6 @@ type
# Some have a signing_root field
signing_root {.defaultVal: "".}: string
# https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#eth1block
Eth1Block = object
timestamp: uint64
deposit_root: Eth2Digest
deposit_count: uint64
# All other eth1 block fields
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)

View File

@ -9,8 +9,6 @@
# ---------------------------------------------------------------
import
# Standard library
intsets,
# Status
chronicles,
# Specs