Unfinished progress

This commit is contained in:
Paul Hauner 2019-03-04 14:24:29 +11:00
parent 0e1a14a628
commit 4a57aec472
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
3 changed files with 54 additions and 6 deletions

View File

@ -19,6 +19,7 @@ pub mod exit;
pub mod fork; pub mod fork;
pub mod free_attestation; pub mod free_attestation;
pub mod pending_attestation; pub mod pending_attestation;
pub mod proposal;
pub mod proposal_signed_data; pub mod proposal_signed_data;
pub mod proposer_slashing; pub mod proposer_slashing;
pub mod readers; pub mod readers;
@ -57,6 +58,7 @@ pub use crate::exit::Exit;
pub use crate::fork::Fork; pub use crate::fork::Fork;
pub use crate::free_attestation::FreeAttestation; pub use crate::free_attestation::FreeAttestation;
pub use crate::pending_attestation::PendingAttestation; pub use crate::pending_attestation::PendingAttestation;
pub use crate::proposal::Proposal;
pub use crate::proposal_signed_data::ProposalSignedData; pub use crate::proposal_signed_data::ProposalSignedData;
pub use crate::proposer_slashing::ProposerSlashing; pub use crate::proposer_slashing::ProposerSlashing;
pub use crate::slashable_attestation::SlashableAttestation; pub use crate::slashable_attestation::SlashableAttestation;

View File

@ -0,0 +1,46 @@
use crate::test_utils::TestRandom;
use crate::{Hash256, Slot};
use bls::Signature;
use rand::RngCore;
use serde_derive::Serialize;
use ssz_derive::{Decode, Encode, TreeHash};
use test_random_derive::TestRandom;
#[derive(Debug, PartialEq, Clone, Serialize, Encode, Decode, TreeHash, TestRandom)]
pub struct Proposal {
pub slot: Slot,
/// Shard number (spec.beacon_chain_shard_number for beacon chain)
pub shard: u64,
pub block_root: Hash256,
pub signature: Signature,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use ssz::{ssz_encode, Decodable, TreeHash};
#[test]
pub fn test_ssz_round_trip() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Proposal::random_for_test(&mut rng);
let bytes = ssz_encode(&original);
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
assert_eq!(original, decoded);
}
#[test]
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Proposal::random_for_test(&mut rng);
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
// https://github.com/sigp/lighthouse/issues/170
}
}

View File

@ -1,6 +1,5 @@
use super::ProposalSignedData; use super::Proposal;
use crate::test_utils::TestRandom; use crate::test_utils::TestRandom;
use bls::Signature;
use rand::RngCore; use rand::RngCore;
use serde_derive::Serialize; use serde_derive::Serialize;
use ssz_derive::{Decode, Encode, TreeHash}; use ssz_derive::{Decode, Encode, TreeHash};
@ -10,13 +9,14 @@ mod builder;
pub use builder::ProposerSlashingBuilder; pub use builder::ProposerSlashingBuilder;
/// Two conflicting proposals from the same proposer (validator).
///
/// Spec v0.4.0
#[derive(Debug, PartialEq, Clone, Serialize, Encode, Decode, TreeHash, TestRandom)] #[derive(Debug, PartialEq, Clone, Serialize, Encode, Decode, TreeHash, TestRandom)]
pub struct ProposerSlashing { pub struct ProposerSlashing {
pub proposer_index: u64, pub proposer_index: u64,
pub proposal_data_1: ProposalSignedData, pub proposer_1: Proposal,
pub proposal_signature_1: Signature, pub proposer_2: Proposal,
pub proposal_data_2: ProposalSignedData,
pub proposal_signature_2: Signature,
} }
#[cfg(test)] #[cfg(test)]