use bp_idn::types::RuntimePulse;
use codec::{Decode, DecodeWithMemTracking, Encode};
use frame_support::pallet_prelude::*;
use sp_consensus_randomness_beacon::types::{OpaqueSignature, RoundNumber};
#[derive(
Clone, Debug, Decode, DecodeWithMemTracking, PartialEq, Encode, MaxEncodedLen, TypeInfo,
)]
pub struct Accumulation {
pub signature: OpaqueSignature,
pub start: RoundNumber,
pub end: RoundNumber,
}
impl Accumulation {
pub fn new(signature: OpaqueSignature, start: RoundNumber, end: RoundNumber) -> Self {
Self { signature, start, end }
}
}
impl From<Accumulation> for RuntimePulse {
fn from(acc: Accumulation) -> Self {
RuntimePulse::new(acc.signature, acc.start, acc.end)
}
}
#[cfg(test)]
pub mod test {
use super::*;
use std::any::TypeId;
#[test]
fn test_accumulation_max_encoded_len() {
let max_len = Accumulation::max_encoded_len();
let signature_max_len = OpaqueSignature::max_encoded_len();
let round_number_max_len = u64::max_encoded_len();
let expected_max_len = signature_max_len + 2 * round_number_max_len;
assert_eq!(max_len, expected_max_len);
}
#[test]
fn test_accumulation_type_info() {
let type_id = TypeId::of::<Accumulation>();
assert_eq!(type_id, TypeId::of::<Accumulation>());
let type_name = core::any::type_name::<Accumulation>();
assert_eq!(type_name, "pallet_randomness_beacon::types::Accumulation");
}
}