Adds a std::default::Default
implementation for ValidatorRecord
Updates the test generation so that it uses sane values for some marker values like `FAR_FUTURE_SLOT`
This commit is contained in:
parent
16cc8556e8
commit
4d3d351b67
@ -4,6 +4,7 @@ use crate::test_utils::TestRandom;
|
|||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use ssz::{Decodable, DecodeError, Encodable, SszStream};
|
use ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||||
use std::convert;
|
use std::convert;
|
||||||
|
use std::default;
|
||||||
|
|
||||||
const STATUS_FLAG_INITIATED_EXIT: u8 = 1;
|
const STATUS_FLAG_INITIATED_EXIT: u8 = 1;
|
||||||
const STATUS_FLAG_WITHDRAWABLE: u8 = 2;
|
const STATUS_FLAG_WITHDRAWABLE: u8 = 2;
|
||||||
@ -41,6 +42,26 @@ pub struct ValidatorRecord {
|
|||||||
pub penultimate_custody_reseed_slot: u64,
|
pub penultimate_custody_reseed_slot: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl default::Default for ValidatorRecord {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
pubkey: PublicKey::default(),
|
||||||
|
withdrawal_credentials: Hash256::default(),
|
||||||
|
randao_commitment: Hash256::default(),
|
||||||
|
randao_layers: 0,
|
||||||
|
activation_slot: std::u64::MAX,
|
||||||
|
exit_slot: std::u64::MAX,
|
||||||
|
withdrawal_slot: std::u64::MAX,
|
||||||
|
penalized_slot: std::u64::MAX,
|
||||||
|
exit_count: 0,
|
||||||
|
status_flags: None,
|
||||||
|
custody_commitment: Hash256::default(),
|
||||||
|
latest_custody_reseed_slot: 0, // NOTE: is `GENESIS_SLOT`
|
||||||
|
penultimate_custody_reseed_slot: 0, // NOTE: is `GENESIS_SLOT`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Encodable for StatusFlags {
|
impl Encodable for StatusFlags {
|
||||||
fn ssz_append(&self, s: &mut SszStream) {
|
fn ssz_append(&self, s: &mut SszStream) {
|
||||||
let byte: u8 = match self {
|
let byte: u8 = match self {
|
||||||
@ -142,15 +163,12 @@ impl<T: RngCore> TestRandom<T> for ValidatorRecord {
|
|||||||
withdrawal_credentials: <_>::random_for_test(rng),
|
withdrawal_credentials: <_>::random_for_test(rng),
|
||||||
randao_commitment: <_>::random_for_test(rng),
|
randao_commitment: <_>::random_for_test(rng),
|
||||||
randao_layers: <_>::random_for_test(rng),
|
randao_layers: <_>::random_for_test(rng),
|
||||||
activation_slot: <_>::random_for_test(rng),
|
|
||||||
exit_slot: <_>::random_for_test(rng),
|
|
||||||
withdrawal_slot: <_>::random_for_test(rng),
|
|
||||||
penalized_slot: <_>::random_for_test(rng),
|
|
||||||
exit_count: <_>::random_for_test(rng),
|
exit_count: <_>::random_for_test(rng),
|
||||||
status_flags: Some(<_>::random_for_test(rng)),
|
status_flags: Some(<_>::random_for_test(rng)),
|
||||||
custody_commitment: <_>::random_for_test(rng),
|
custody_commitment: <_>::random_for_test(rng),
|
||||||
latest_custody_reseed_slot: <_>::random_for_test(rng),
|
latest_custody_reseed_slot: <_>::random_for_test(rng),
|
||||||
penultimate_custody_reseed_slot: <_>::random_for_test(rng),
|
penultimate_custody_reseed_slot: <_>::random_for_test(rng),
|
||||||
|
..Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::SecretKey;
|
use super::SecretKey;
|
||||||
use bls_aggregates::PublicKey as RawPublicKey;
|
use bls_aggregates::PublicKey as RawPublicKey;
|
||||||
use ssz::{decode_ssz_list, Decodable, DecodeError, Encodable, SszStream};
|
use ssz::{decode_ssz_list, Decodable, DecodeError, Encodable, SszStream};
|
||||||
|
use std::default;
|
||||||
|
|
||||||
/// A single BLS signature.
|
/// A single BLS signature.
|
||||||
///
|
///
|
||||||
@ -20,6 +21,13 @@ impl PublicKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl default::Default for PublicKey {
|
||||||
|
fn default() -> Self {
|
||||||
|
let secret_key = SecretKey::random();
|
||||||
|
PublicKey::from_secret_key(&secret_key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Encodable for PublicKey {
|
impl Encodable for PublicKey {
|
||||||
fn ssz_append(&self, s: &mut SszStream) {
|
fn ssz_append(&self, s: &mut SszStream) {
|
||||||
s.append_vec(&self.0.as_bytes());
|
s.append_vec(&self.0.as_bytes());
|
||||||
|
Loading…
Reference in New Issue
Block a user