2019-04-02 14:50:24 +00:00
|
|
|
import
|
|
|
|
# Status libs
|
2019-07-07 09:53:58 +00:00
|
|
|
stew/byteutils,
|
2019-04-02 14:50:24 +00:00
|
|
|
eth/common, serialization, json_serialization,
|
|
|
|
# Beacon chain internals
|
2019-06-17 09:29:23 +00:00
|
|
|
../../beacon_chain/spec/datatypes
|
2019-04-02 14:50:24 +00:00
|
|
|
|
2019-06-17 09:29:23 +00:00
|
|
|
export # Workaround:
|
|
|
|
# - https://github.com/status-im/nim-serialization/issues/4
|
|
|
|
# - https://github.com/status-im/nim-serialization/issues/5
|
|
|
|
# - https://github.com/nim-lang/Nim/issues/11225
|
|
|
|
serialization.readValue
|
2019-04-02 14:50:24 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
# TODO: use ref object to avoid allocating
|
|
|
|
# so much on the stack - pending https://github.com/status-im/nim-json-serialization/issues/3
|
2019-06-17 09:29:23 +00:00
|
|
|
|
2019-04-02 14:50:24 +00:00
|
|
|
TestConstants* = object
|
2019-05-10 08:14:01 +00:00
|
|
|
# TODO - 0.5.1 constants
|
2019-04-02 14:50:24 +00:00
|
|
|
SHARD_COUNT*: int
|
|
|
|
TARGET_COMMITTEE_SIZE*: int
|
|
|
|
MAX_BALANCE_CHURN_QUOTIENT*: int
|
2019-07-01 07:53:42 +00:00
|
|
|
MAX_VALIDATORS_PER_COMMITTEE*: int
|
2019-04-29 16:48:30 +00:00
|
|
|
MIN_PER_EPOCH_CHURN_LIMIT*: int
|
2019-04-02 14:50:24 +00:00
|
|
|
SHUFFLE_ROUND_COUNT*: int
|
|
|
|
DEPOSIT_CONTRACT_TREE_DEPTH*: int
|
|
|
|
MIN_DEPOSIT_AMOUNT*: uint64
|
2019-04-29 16:48:30 +00:00
|
|
|
MAX_EFFECTIVE_BALANCE*: uint64
|
2019-04-02 14:50:24 +00:00
|
|
|
EJECTION_BALANCE*: uint64
|
|
|
|
GENESIS_FORK_VERSION*: uint32
|
|
|
|
GENESIS_SLOT*: Slot
|
|
|
|
GENESIS_EPOCH*: Epoch
|
|
|
|
GENESIS_START_SHARD*: uint64
|
2019-06-14 16:21:04 +00:00
|
|
|
BLS_WITHDRAWAL_PREFIX*: array[1, byte]
|
2019-04-02 14:50:24 +00:00
|
|
|
SECONDS_PER_SLOT*: uint64
|
|
|
|
MIN_ATTESTATION_INCLUSION_DELAY*: uint64
|
|
|
|
SLOTS_PER_EPOCH*: int
|
|
|
|
MIN_SEED_LOOKAHEAD*: int
|
|
|
|
ACTIVATION_EXIT_DELAY*: int
|
|
|
|
EPOCHS_PER_ETH1_VOTING_PERIOD*: uint64
|
|
|
|
SLOTS_PER_HISTORICAL_ROOT*: int
|
|
|
|
MIN_VALIDATOR_WITHDRAWABILITY_DELAY*: uint64
|
|
|
|
PERSISTENT_COMMITTEE_PERIOD*: uint64
|
|
|
|
LATEST_RANDAO_MIXES_LENGTH*: int
|
More 0.8.0 updates (#311)
* replace BeaconState.finalized_{epoch,root} with BeaconState.finalized_checkpoint; rename get_delayed_activation_exit_epoch(...) to compute_activation_exit_epoch(...) and mark as 0.8.0; update get_churn_limit(...)/get_validator_churn_limit(...) to 0.8.0; update process_registry_updates(...) to 0.8.0
* update process_crosslinks(...) to 0.8.0; mark compute_start_slot_of_epoch(...) and get_committee_count(...) as 0.8.0
* mark Fork, is_slashable_validator(...), and get_beacon_proposer_index(...) as 0.8.0
* rename LATEST_SLASHED_EXIT_LENGTH to EPOCHS_PER_SLASHINGS_VECTOR; update process_slashings(...) to 0.8.0; remove pointless type conversion warning in get_previous_epoch(...)
* convert remaining references to finalized_epoch to finalized_checkpoint.epoch
* update slash_validator(...) to 0.8.0; mark inital value, Gwei, and time constants as 0.8.0; mark hash(...) and processBlockHeader(...) as 0.8.0
* rename WHISTLEBLOWING_REWARD_QUOTIENT to WHISTLEBLOWER_REWARD_QUOTIENT; rename LATEST_ACTIVE_INDEX_ROOTS_LENGTH to EPOCHS_PER_HISTORICAL_VECTOR (randao will also get merged into this); remove get_active_index_root(...); mark time parameter, signature domain types, and max operations per block constants as 0.8.0; update rewards and penalties constants to 0.8.0
* update is_valid_indexed_attestation(...) to 0.8.0; mark process_slot(...) as 0.8.0
* replace BeaconState.{current,previous}_justified_{epoch,root} with BeaconState.{current,previous}_justified_checkpoint
2019-07-05 08:30:05 +00:00
|
|
|
EPOCHS_PER_HISTORICAL_VECTOR*: int
|
|
|
|
EPOCHS_PER_SLASHINGS_VECTOR*: int
|
0.7.0 updates which don't change semantics; mostly comment changes (#281)
* 0.7.0 updates which don't change semantics; mostly comment changes
* mark get_attesting_indices, bls_verify, ProposerSlashing, BeaconBlockBody, deposit contract constants, state list length constants, compute_committee, get_crosslink_committee, is_slashable_attestation_data, processAttesterSlashings as 0.7.0; rename BASE_REWARD_QUOTIENT to BASE_REWARD_FACTOR
* complete marking unchanged-in-0.7.0 datatypes as such; a few more have trivial field renamings, etc
2019-06-13 07:40:58 +00:00
|
|
|
BASE_REWARD_FACTOR*: uint64
|
More 0.8.0 updates (#311)
* replace BeaconState.finalized_{epoch,root} with BeaconState.finalized_checkpoint; rename get_delayed_activation_exit_epoch(...) to compute_activation_exit_epoch(...) and mark as 0.8.0; update get_churn_limit(...)/get_validator_churn_limit(...) to 0.8.0; update process_registry_updates(...) to 0.8.0
* update process_crosslinks(...) to 0.8.0; mark compute_start_slot_of_epoch(...) and get_committee_count(...) as 0.8.0
* mark Fork, is_slashable_validator(...), and get_beacon_proposer_index(...) as 0.8.0
* rename LATEST_SLASHED_EXIT_LENGTH to EPOCHS_PER_SLASHINGS_VECTOR; update process_slashings(...) to 0.8.0; remove pointless type conversion warning in get_previous_epoch(...)
* convert remaining references to finalized_epoch to finalized_checkpoint.epoch
* update slash_validator(...) to 0.8.0; mark inital value, Gwei, and time constants as 0.8.0; mark hash(...) and processBlockHeader(...) as 0.8.0
* rename WHISTLEBLOWING_REWARD_QUOTIENT to WHISTLEBLOWER_REWARD_QUOTIENT; rename LATEST_ACTIVE_INDEX_ROOTS_LENGTH to EPOCHS_PER_HISTORICAL_VECTOR (randao will also get merged into this); remove get_active_index_root(...); mark time parameter, signature domain types, and max operations per block constants as 0.8.0; update rewards and penalties constants to 0.8.0
* update is_valid_indexed_attestation(...) to 0.8.0; mark process_slot(...) as 0.8.0
* replace BeaconState.{current,previous}_justified_{epoch,root} with BeaconState.{current,previous}_justified_checkpoint
2019-07-05 08:30:05 +00:00
|
|
|
WHISTLEBLOWER_REWARD_QUOTIENT*: uint64
|
2019-04-29 16:48:30 +00:00
|
|
|
PROPOSER_REWARD_QUOTIENT*: uint64
|
2019-04-02 14:50:24 +00:00
|
|
|
INACTIVITY_PENALTY_QUOTIENT*: uint64
|
0.6.2 updates (#275)
* update process_justification_and_finalization to 0.6.2; mark AttesterSlashing as 0.6.2
* replace get_effective_balance(...) with state.validator_registry[idx].effective_balance; rm get_effective_balance, process_ejections, should_update_validator_registry, update_validator_registry, and update_registry_and_shuffling_data; update get_total_balance to 0.6.2; implement process_registry_updates
* rm exit_validator; implement is_slashable_attestation_data; partly update processAttesterSlashings
* mark HistoricalBatch and Eth1Data as 0.6.2; implement get_shard_delta(...); replace 0.5 finish_epoch_update with 0.6 process_final_updates
* mark increase_balance, decrease_balance, get_delayed_activation_exit_epoch, bls_aggregate_pubkeys, bls_verify_multiple, Attestation, Transfer, slot_to_epoch, Crosslink, get_current_epoch, int_to_bytes*, various constants, processEth1Data, processTransfers, and verifyStateRoot as 0.6.2; rm is_double_vote and is_surround_vote
* mark get_bitfield_bit, verify_bitfield, ProposerSlashing, DepositData, VoluntaryExit, PendingAttestation, Fork, integer_squareroot, get_epoch_start_slot, is_active_validator, generate_seed, some constants to 0.6.2; rename MIN_PENALTY_QUOTIENT to MIN_SLASHING_PENALTY_QUOTIENT
* rm get_previous_total_balance, get_current_epoch_boundary_attestations, get_previous_epoch_boundary_attestations, and get_previous_epoch_matching_head_attestations
* update BeaconState to 0.6.2; simplify legacy get_crosslink_committees_at_slot infrastructure a bit by noting that registry_change is always false; reimplment 0.5 get_crosslink_committees_at_slot in terms of 0.6 get_crosslink_committee
* mark process_deposit(...), get_block_root_at_slot(...), get_block_root(...), Deposit, BeaconBlockHeader, BeaconBlockBody, hash(...), get_active_index_root(...), various constants, get_shard_delta(...), get_epoch_start_shard(...), get_crosslink_committee(...), processRandao(...), processVoluntaryExits(...), cacheState(...) as 0.6.2
* rm removed-since-0.5 split(...), is_power_of_2(...), get_shuffling(...); rm 0.5 versions of get_active_validator_indices and get_epoch_committee_count; add a few tests for integer_squareroot
* mark bytes_to_int(...) and advanceState(...) as 0.6.2
* rm 0.5 get_attesting_indices; update get_attesting_balance to 0.6.2
* another tiny commit to poke AppVeyor to maybe not timeout at connecting to GitHub partway through CI: mark get_churn_limit(...), initiate_validator_exit(...), and Validator as 0.6.2
* mark get_attestation_slot(...), AttestationDataAndCustodyBit, and BeaconBlock as 0.6.2
2019-06-03 10:31:04 +00:00
|
|
|
MIN_SLASHING_PENALTY_QUOTIENT*: int
|
2019-04-02 14:50:24 +00:00
|
|
|
MAX_PROPOSER_SLASHINGS*: int
|
|
|
|
MAX_ATTESTER_SLASHINGS*: int
|
|
|
|
MAX_ATTESTATIONS*: int
|
|
|
|
MAX_DEPOSITS*: int
|
|
|
|
MAX_VOLUNTARY_EXITS*: int
|
|
|
|
MAX_TRANSFERS*: int
|
2019-07-01 07:53:42 +00:00
|
|
|
DOMAIN_BEACON_PROPOSER*: DomainType
|
|
|
|
DOMAIN_RANDAO*: DomainType
|
|
|
|
DOMAIN_ATTESTATION*: DomainType
|
|
|
|
DOMAIN_DEPOSIT*: DomainType
|
|
|
|
DOMAIN_VOLUNTARY_EXIT*: DomainType
|
|
|
|
DOMAIN_TRANSFER*: DomainType
|
2019-04-02 14:50:24 +00:00
|
|
|
|
2019-05-23 07:41:17 +00:00
|
|
|
Tests*[T] = object
|
2019-05-10 08:14:01 +00:00
|
|
|
title*: string
|
|
|
|
summary*: string
|
|
|
|
forks_timeline*: string
|
|
|
|
forks*: seq[string]
|
|
|
|
config*: string
|
|
|
|
runner*: string
|
|
|
|
handler*: string
|
2019-05-23 07:41:17 +00:00
|
|
|
test_cases*: seq[T]
|
2019-05-10 08:14:01 +00:00
|
|
|
|
2019-04-02 14:50:24 +00:00
|
|
|
# #######################
|
|
|
|
# Default init
|
|
|
|
proc default*(T: typedesc): T = discard
|
|
|
|
|
|
|
|
# #######################
|
|
|
|
# JSON deserialization
|
|
|
|
|
|
|
|
proc readValue*[N: static int](r: var JsonReader, a: var array[N, byte]) {.inline.} =
|
|
|
|
# Needed for;
|
2019-06-14 16:21:04 +00:00
|
|
|
# - BLS_WITHDRAWAL_PREFIX
|
2019-04-29 16:10:01 +00:00
|
|
|
# - Fork datatypes
|
2019-04-02 14:50:24 +00:00
|
|
|
# TODO: are all bytes and bytearray serialized as hex?
|
|
|
|
# if so export that to nim-eth
|
|
|
|
hexToByteArray(r.readValue(string), a)
|
|
|
|
|
2019-05-10 08:14:01 +00:00
|
|
|
proc readValue*(r: var JsonReader, a: var ValidatorIndex) {.inline.} =
|
|
|
|
a = r.readValue(uint32)
|
|
|
|
|
2019-05-23 07:41:17 +00:00
|
|
|
proc readValue*(r: var JsonReader, a: var seq[byte]) {.inline.} =
|
|
|
|
## Custom deserializer for seq[byte]
|
|
|
|
a = hexToSeqByte(r.readValue(string))
|
|
|
|
|
2019-06-17 09:29:23 +00:00
|
|
|
proc parseTests*(jsonPath: string, T: typedesc): Tests[T] =
|
2019-04-02 14:50:24 +00:00
|
|
|
try:
|
2019-06-17 09:29:23 +00:00
|
|
|
debugEcho " [Debug] Loading file: \"", jsonPath, '\"'
|
|
|
|
result = Json.loadFile(jsonPath, Tests[T])
|
2019-04-02 14:50:24 +00:00
|
|
|
except SerializationError as err:
|
|
|
|
writeStackTrace()
|
|
|
|
stderr.write "Json load issue for file \"", jsonPath, "\"\n"
|
|
|
|
stderr.write err.formatMsg(jsonPath), "\n"
|
2019-04-29 16:10:01 +00:00
|
|
|
quit 1
|
|
|
|
|
|
|
|
# #######################
|
|
|
|
# Mocking helpers
|
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/75f0af45bb0613bb406fc72d10266cee4cfb402a/tests/phase0/helpers.py#L107
|
|
|
|
|
|
|
|
proc build_empty_block_for_next_slot*(state: BeaconState): BeaconBlock =
|
|
|
|
## TODO: why can the official spec get away with a simple proc
|
|
|
|
|
|
|
|
# result.slot = state.slot + 1
|
|
|
|
# var previous_block_header = state.latest_block_header
|
|
|
|
# if previous_block_header.state_root == ZERO_HASH:
|
|
|
|
# previous_block_header.state_root = state.hash_tree_root()
|
2019-05-09 12:27:37 +00:00
|
|
|
# result.previous_block_root = signing_root(previous_block_header)
|
2019-04-29 16:10:01 +00:00
|
|
|
|
|
|
|
## TODO: `makeBlock` from testutil.nim
|
|
|
|
## doesn't work either due to use of fake private keys
|
|
|
|
|
|
|
|
# let prev_root = block:
|
|
|
|
# if state.latest_block_header.state_root == ZERO_HASH:
|
|
|
|
# state.hash_tree_root()
|
|
|
|
# else: state.latest_block_header.state_root
|
|
|
|
# result = makeBlock(
|
|
|
|
# state,
|
|
|
|
# prev_root,
|
|
|
|
# BeaconBlockBody()
|
|
|
|
# )
|
2019-06-17 09:29:23 +00:00
|
|
|
{.error: "Not implemented".}
|