Fix SigVerifiedOp SSZ implementation (#6035)

* Fix SigVerifiedOp SSZ implementation
This commit is contained in:
Michael Sproul
2024-07-03 08:54:44 +10:00
committed by GitHub
parent 2a13b4f3fa
commit 937f8b2d01
6 changed files with 135 additions and 71 deletions

View File

@@ -3,6 +3,7 @@ use crate::indexed_attestation::{
};
use crate::{test_utils::TestRandom, EthSpec};
use derivative::Derivative;
use rand::{Rng, RngCore};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use superstruct::superstruct;
@@ -160,6 +161,16 @@ impl<E: EthSpec> AttesterSlashing<E> {
}
}
impl<E: EthSpec> TestRandom for AttesterSlashing<E> {
fn random_for_test(rng: &mut impl RngCore) -> Self {
if rng.gen_bool(0.5) {
AttesterSlashing::Base(AttesterSlashingBase::random_for_test(rng))
} else {
AttesterSlashing::Electra(AttesterSlashingElectra::random_for_test(rng))
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -2,6 +2,7 @@ use crate::*;
use rand::RngCore;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use smallvec::{smallvec, SmallVec};
use std::marker::PhantomData;
use std::sync::Arc;
@@ -118,6 +119,21 @@ where
}
}
impl<U, const N: usize> TestRandom for SmallVec<[U; N]>
where
U: TestRandom,
{
fn random_for_test(rng: &mut impl RngCore) -> Self {
let mut output = smallvec![];
for _ in 0..(usize::random_for_test(rng) % 4) {
output.push(<U>::random_for_test(rng));
}
output
}
}
macro_rules! impl_test_random_for_u8_array {
($len: expr) => {
impl TestRandom for [u8; $len] {