transition deposit operation fixtures to 0.9.0 (#515)

* transition deposit operations fixture to 0.9.0

* mark slash_validator(...) as 0.9.0

* switch remaining non-ref objects to ref objects to maybe avoid crashes in CI

* remove unused helpers/debug_state imports
This commit is contained in:
Dustin Brody 2019-11-06 15:02:06 +00:00 committed by GitHub
parent 9b39c792d0
commit 0073555752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 16 deletions

View File

@ -146,7 +146,7 @@ func initiate_validator_exit*(state: var BeaconState,
validator.withdrawable_epoch =
validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#slash_validator
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#slash_validator
func slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex,
stateCache: var StateCache) =
# Slash the validator with index ``index``.

View File

@ -237,6 +237,64 @@ type
voluntary_exits*: seq[VoluntaryExit]
transfers*: seq[Transfer]
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#beaconstate
BeaconStateNew* = object
# Versioning
genesis_time*: uint64
slot*: Slot
fork*: Fork
# History
latest_block_header*: BeaconBlockHeader ##\
## `latest_block_header.state_root == ZERO_HASH` temporarily
block_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
## Needed to process attestations, older to newer
state_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
historical_roots*: seq[Eth2Digest] ##\
## model List with HISTORICAL_ROOTS_LIMIT limit as seq
## TODO bound explicitly somewhere
# Eth1
eth1_data*: Eth1Data
eth1_data_votes*: seq[Eth1Data] ##\
## As with `hitorical_roots`, this is a `List`. TODO bound explicitly.
eth1_deposit_index*: uint64
# Registry
validators*: seq[Validator]
balances*: seq[uint64] ##\
## Validator balances in Gwei!
## Also more `List`s which need to be bounded explicitly at
## VALIDATOR_REGISTRY_LIMIT
# Randomness
randao_mixes*: array[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
# Slashings
slashings*: array[EPOCHS_PER_SLASHINGS_VECTOR, uint64] ##\
## Per-epoch sums of slashed effective balances
# Attestations
previous_epoch_attestations*: seq[PendingAttestation]
current_epoch_attestations*: seq[PendingAttestation]
# Finality
justification_bits*: uint8 ##\
## Bit set for every recent justified epoch
## Model a Bitvector[4] as a one-byte uint, which should remain consistent
## with ssz/hashing.
previous_justified_checkpoint*: Checkpoint ##\
## Previous epoch snapshot
current_justified_checkpoint*: Checkpoint
finalized_checkpoint*: Checkpoint
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#beaconstate
BeaconState* = object
# Versioning
@ -527,6 +585,54 @@ proc `$`*(x: ValidatorIndex): auto = $(x.int64)
ethTimeUnit Slot
ethTimeUnit Epoch
func GetOldBeaconState*(newState: BeaconStateNew): BeaconState =
BeaconState(
genesis_time: newState.genesis_time,
slot: newState.slot,
fork: newState.fork,
latest_block_header: newState.latest_block_header,
block_roots: newState.block_roots,
state_roots: newState.state_roots,
historical_roots: newState.historical_roots,
eth1_data: newState.eth1_data,
eth1_data_votes: newState.eth1_data_votes,
eth1_deposit_index: newState.eth1_deposit_index,
validators: newState.validators,
balances: newState.balances,
randao_mixes: newState.randao_mixes,
slashings: newState.slashings,
previous_epoch_attestations: newState.previous_epoch_attestations,
current_epoch_attestations: newState.current_epoch_attestations,
justification_bits: newState.justification_bits,
previous_justified_checkpoint: newState.previous_justified_checkpoint,
current_justified_checkpoint: newState.current_justified_checkpoint,
finalized_checkpoint: newState.finalized_checkpoint
)
func GetNewBeaconState*(oldState: BeaconState): BeaconStateNew =
BeaconStateNew(
genesis_time: oldState.genesis_time,
slot: oldState.slot,
fork: oldState.fork,
latest_block_header: oldState.latest_block_header,
block_roots: oldState.block_roots,
state_roots: oldState.state_roots,
historical_roots: oldState.historical_roots,
eth1_data: oldState.eth1_data,
eth1_data_votes: oldState.eth1_data_votes,
eth1_deposit_index: oldState.eth1_deposit_index,
validators: oldState.validators,
balances: oldState.balances,
randao_mixes: oldState.randao_mixes,
slashings: oldState.slashings,
previous_epoch_attestations: oldState.previous_epoch_attestations,
current_epoch_attestations: oldState.current_epoch_attestations,
justification_bits: oldState.justification_bits,
previous_justified_checkpoint: oldState.previous_justified_checkpoint,
current_justified_checkpoint: oldState.current_justified_checkpoint,
finalized_checkpoint: oldState.finalized_checkpoint
)
Json.useCustomSerialization(BeaconState.justification_bits):
read:
let s = reader.readValue(string)

View File

@ -14,8 +14,7 @@ import
# Test utilities
../testutil,
./fixtures_utils,
../helpers/debug_state,
../mocking/mock_blocks
../helpers/debug_state
const OperationsAttestationsDir = SszTestsDir/const_preset/"phase0"/"operations"/"attestation"/"pyspec_tests"

View File

@ -14,8 +14,7 @@ import
# Test utilities
../testutil,
./fixtures_utils,
../helpers/debug_state,
../mocking/mock_blocks
../helpers/debug_state
const OpBlockHeaderDir = SszTestsDir/const_preset/"phase0"/"operations"/"block_header"/"pyspec_tests"

View File

@ -14,10 +14,9 @@ import
# Test utilities
../testutil,
./fixtures_utils,
../helpers/debug_state,
../mocking/mock_blocks
../helpers/debug_state
const OperationsDepositsDir = SszTestsDir/const_preset/"phase0"/"operations"/"deposit"/"pyspec_tests"
const OperationsDepositsDir = FixturesDir/"tests-v0.9.0"/const_preset/"phase0"/"operations"/"deposit"/"pyspec_tests"
template runTest(testName: string, identifier: untyped) =
# We wrap the tests in a proc to avoid running out of globals
@ -39,24 +38,29 @@ template runTest(testName: string, identifier: untyped) =
prefix = "[Invalid] "
test prefix & testName & " (" & astToStr(identifier) & ")":
var stateRef, postRef: ref BeaconState
var stateRef, postRef: ref BeaconStateNew
var sr_pre, sr_post: ref BeaconState
var depositRef: ref Deposit
new depositRef
new stateRef
new sr_pre
new sr_post
depositRef[] = parseTest(testDir/"deposit.ssz", SSZ, Deposit)
stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconState)
stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconStateNew)
sr_pre[] = GetOldBeaconState(stateRef[])
if existsFile(testDir/"post.ssz"):
new postRef
postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconState)
postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconStateNew)
sr_post[] = GetOldBeaconState(postRef[])
if postRef.isNil:
expect(AssertionError):
let done = process_deposit(stateRef[], depositRef[], flags)
let done = process_deposit(sr_pre[], depositRef[], flags)
else:
let done = process_deposit(stateRef[], depositRef[], flags)
reportDiff(stateRef, postRef)
let done = process_deposit(sr_pre[], depositRef[], flags)
reportDiff(sr_pre, sr_post)
`testImpl _ operations_deposits _ identifier`()

View File

@ -14,8 +14,7 @@ import
# Test utilities
../testutil,
./fixtures_utils,
../helpers/debug_state,
../mocking/mock_blocks
../helpers/debug_state
const SanityBlocksDir = SszTestsDir/const_preset/"phase0"/"sanity"/"blocks"/"pyspec_tests"