Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed May 22, 2024
1 parent 558a73b commit 51355e8
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 37 deletions.
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,9 @@ pub fn generate_rand_block_and_blobs<E: EthSpec>(
num_blobs: NumBlobs,
rng: &mut impl Rng,
) -> (SignedBeaconBlock<E, FullPayload<E>>, Vec<BlobSidecar<E>>) {
println!("randomly generating the beacon block is the trickt part. probably beacuse attestations im guessing?");
let inner = map_fork_name!(fork_name, BeaconBlock, <_>::random_for_test(rng));

let mut block = SignedBeaconBlock::from_block(inner, types::Signature::random_for_test(rng));
let mut blob_sidecars = vec![];

Expand Down Expand Up @@ -2697,7 +2699,6 @@ pub fn generate_rand_block_and_blobs<E: EthSpec>(
};
let (bundle, transactions) =
execution_layer::test_utils::generate_blobs::<E>(num_blobs).unwrap();

payload.execution_payload.transactions = <_>::default();
for tx in Vec::from(transactions) {
payload.execution_payload.transactions.push(tx).unwrap();
Expand Down
2 changes: 0 additions & 2 deletions beacon_node/beacon_chain/tests/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ impl GossipTester {
/*
* Batch verification
*/
println!("desc {}", desc);
let mut results = self
.harness
.chain
Expand Down Expand Up @@ -772,7 +771,6 @@ async fn aggregated_gossip_verification() {
}
},
|_, err| {
println!("{:?}", err);
assert!(matches!(
err,
// Naively we should think this condition would trigger this error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ where
let message = slot.signing_root(domain);
let signature = signed_aggregate_and_proof.message().selection_proof();
let validator_index = signed_aggregate_and_proof.message().aggregator_index();
println!("validator index, {}", validator_index);
Ok(SignatureSet::single_pubkey(
signature,
get_pubkey(validator_index as usize).ok_or(Error::ValidatorUnknown(validator_index))?,
Expand Down
18 changes: 0 additions & 18 deletions consensus/types/src/attestation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::slot_data::SlotData;
use crate::{test_utils::TestRandom, Hash256, Slot};
use derivative::Derivative;
use rand::RngCore;
use safe_arith::ArithError;
use serde::{Deserialize, Serialize};
use ssz::Decode;
Expand Down Expand Up @@ -95,23 +94,6 @@ impl<E: EthSpec> Decode for Attestation<E> {
}
}

// TODO(electra): think about how to handle fork variants here
impl<E: EthSpec> TestRandom for Attestation<E> {
fn random_for_test(rng: &mut impl RngCore) -> Self {
let aggregation_bits: BitList<E::MaxValidatorsPerCommittee> = BitList::random_for_test(rng);
// let committee_bits: BitList<E::MaxCommitteesPerSlot> = BitList::random_for_test(rng);
let data = AttestationData::random_for_test(rng);
let signature = AggregateSignature::random_for_test(rng);

Self::Base(AttestationBase {
aggregation_bits,
// committee_bits,
data,
signature,
})
}
}

impl<E: EthSpec> Hash for Attestation<E> {
fn hash<H>(&self, state: &mut H)
where
Expand Down
15 changes: 0 additions & 15 deletions consensus/types/src/indexed_attestation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{test_utils::TestRandom, AggregateSignature, AttestationData, EthSpec, VariableList};
use core::slice::Iter;
use derivative::Derivative;
use rand::RngCore;
use serde::{Deserialize, Serialize};
use ssz::Decode;
use ssz::Encode;
Expand Down Expand Up @@ -190,20 +189,6 @@ impl<E: EthSpec> Decode for IndexedAttestation<E> {
}
}

impl<E: EthSpec> TestRandom for IndexedAttestation<E> {
fn random_for_test(rng: &mut impl RngCore) -> Self {
let attesting_indices = VariableList::random_for_test(rng);
let data = AttestationData::random_for_test(rng);
let signature = AggregateSignature::random_for_test(rng);

Self::Base(IndexedAttestationBase {
attesting_indices,
data,
signature,
})
}
}

/// Implementation of non-crypto-secure `Hash`, for use with `HashMap` and `HashSet`.
///
/// Guarantees `att1 == att2 -> hash(att1) == hash(att2)`.
Expand Down
3 changes: 3 additions & 0 deletions consensus/types/src/test_utils/test_random/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ impl<N: Unsigned + Clone> TestRandom for BitList<N> {

impl<N: Unsigned + Clone> TestRandom for BitVector<N> {
fn random_for_test(rng: &mut impl RngCore) -> Self {
println!("check {}", N::to_usize());
let mut raw_bytes = smallvec![0; std::cmp::max(1, (N::to_usize() + 7) / 8)];
rng.fill_bytes(&mut raw_bytes);
println!("raw bytes {:?}", raw_bytes);
println!("{:?}", raw_bytes);
Self::from_bytes(raw_bytes).expect("we generate a valid BitVector")
}
}

0 comments on commit 51355e8

Please sign in to comment.