Diff reduction in tests

This commit is contained in:
dapplion
2024-06-18 19:11:09 +02:00
parent 6f0b78426a
commit 444cd625ef
2 changed files with 38 additions and 73 deletions

View File

@@ -1354,25 +1354,15 @@ where
let fork_name = self.spec.fork_name_at_slot::<E>(slot); let fork_name = self.spec.fork_name_at_slot::<E>(slot);
let aggregate = if fork_name.electra_enabled() { let aggregate = if fork_name.electra_enabled() {
self.chain self.chain.get_aggregated_attestation_electra(
.get_aggregated_attestation_electra(
slot, slot,
&attestation.data().tree_hash_root(), &attestation.data().tree_hash_root(),
bc.index, bc.index,
) )
.unwrap()
.unwrap_or_else(|| {
committee_attestations.iter().skip(1).fold(
attestation.clone(),
|mut agg, (att, _)| {
agg.aggregate(att.to_ref());
agg
},
)
})
} else { } else {
self.chain self.chain
.get_aggregated_attestation_base(attestation.data()) .get_aggregated_attestation_base(attestation.data())
}
.unwrap() .unwrap()
.unwrap_or_else(|| { .unwrap_or_else(|| {
committee_attestations.iter().skip(1).fold( committee_attestations.iter().skip(1).fold(
@@ -1382,8 +1372,7 @@ where
agg agg
}, },
) )
}) });
};
// If the chain is able to produce an aggregate, use that. Otherwise, build an // If the chain is able to produce an aggregate, use that. Otherwise, build an
// aggregate locally. // aggregate locally.
@@ -1518,10 +1507,7 @@ where
let fork_name = self.spec.fork_name_at_slot::<E>(Slot::new(0)); let fork_name = self.spec.fork_name_at_slot::<E>(Slot::new(0));
let mut attestation_1 = if fork_name.electra_enabled() { let data = AttestationData {
IndexedAttestation::Electra(IndexedAttestationElectra {
attesting_indices: VariableList::new(validator_indices).unwrap(),
data: AttestationData {
slot: Slot::new(0), slot: Slot::new(0),
index: 0, index: 0,
beacon_block_root: Hash256::zero(), beacon_block_root: Hash256::zero(),
@@ -1533,25 +1519,17 @@ where
root: Hash256::zero(), root: Hash256::zero(),
epoch: source1.unwrap_or(Epoch::new(0)), epoch: source1.unwrap_or(Epoch::new(0)),
}, },
}, };
let mut attestation_1 = if fork_name.electra_enabled() {
IndexedAttestation::Electra(IndexedAttestationElectra {
attesting_indices: VariableList::new(validator_indices).unwrap(),
data,
signature: AggregateSignature::infinity(), signature: AggregateSignature::infinity(),
}) })
} else { } else {
IndexedAttestation::Base(IndexedAttestationBase { IndexedAttestation::Base(IndexedAttestationBase {
attesting_indices: VariableList::new(validator_indices).unwrap(), attesting_indices: VariableList::new(validator_indices).unwrap(),
data: AttestationData { data,
slot: Slot::new(0),
index: 0,
beacon_block_root: Hash256::zero(),
target: Checkpoint {
root: Hash256::zero(),
epoch: target1.unwrap_or(fork.epoch),
},
source: Checkpoint {
root: Hash256::zero(),
epoch: source1.unwrap_or(Epoch::new(0)),
},
},
signature: AggregateSignature::infinity(), signature: AggregateSignature::infinity(),
}) })
}; };

View File

@@ -190,30 +190,17 @@ async fn produces_attestations() {
.produce_unaggregated_attestation(slot, index) .produce_unaggregated_attestation(slot, index)
.expect("should produce attestation"); .expect("should produce attestation");
match &attestation { let (aggregation_bits_len, aggregation_bits_zero) = match &attestation {
Attestation::Base(att) => { Attestation::Base(att) => {
assert_eq!( (att.aggregation_bits.len(), att.aggregation_bits.is_zero())
att.aggregation_bits.len(),
committee_len,
"bad committee len"
);
assert!(
att.aggregation_bits.is_zero(),
"some committee bits are set"
);
} }
Attestation::Electra(att) => { Attestation::Electra(att) => {
assert_eq!( (att.aggregation_bits.len(), att.aggregation_bits.is_zero())
att.aggregation_bits.len(),
committee_len,
"bad committee len"
);
assert!(
att.aggregation_bits.is_zero(),
"some committee bits are set"
);
}
} }
};
assert_eq!(aggregation_bits_len, committee_len, "bad committee len");
assert!(aggregation_bits_zero, "some committee bits are set");
let data = attestation.data(); let data = attestation.data();
assert_eq!( assert_eq!(