mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 20:02:43 +00:00
EIP-3076 tests - complete database (#4958)
* EIP-3076 interchange tests: Add `should_succeed_complete` boolean. This new added `should_succeed_complete` boolean means the test should succeed using complete anti-slashing DB, while the untouched `should_succeed` boolean is still implicitely reserved for minimal anti-slashing DB. Note: This commit only adds the new `should_succeed_complete` boolean, and copy the value from `should_succeed` without any meaning regarding the value this boolean should take. * `TestEIP3076SpecTests`: Modify two tests Those two tests are modified in a way they both comply with minimal AND complete anti-slashing DB. * Disallow false positives and differentiate more minimal vs complete cases * Fix my own typos * Update to v5.3.0 tag --------- Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -33,6 +33,7 @@ pub struct TestBlock {
|
||||
pub slot: Slot,
|
||||
pub signing_root: Hash256,
|
||||
pub should_succeed: bool,
|
||||
pub should_succeed_complete: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
@@ -43,6 +44,7 @@ pub struct TestAttestation {
|
||||
pub target_epoch: Epoch,
|
||||
pub signing_root: Hash256,
|
||||
pub should_succeed: bool,
|
||||
pub should_succeed_complete: bool,
|
||||
}
|
||||
|
||||
impl MultiTestCase {
|
||||
@@ -68,10 +70,6 @@ impl MultiTestCase {
|
||||
let slashing_db_file = dir.path().join("slashing_protection.sqlite");
|
||||
let slashing_db = SlashingDatabase::create(&slashing_db_file).unwrap();
|
||||
|
||||
// Now that we are using implicit minification on import, we must always allow
|
||||
// false positives.
|
||||
let allow_false_positives = true;
|
||||
|
||||
for test_case in &self.steps {
|
||||
// If the test case is marked as containing slashable data, then the spec allows us to
|
||||
// fail to import the file. However, we minify on import and ignore slashable data, so
|
||||
@@ -124,7 +122,7 @@ impl MultiTestCase {
|
||||
i, self.name, safe
|
||||
);
|
||||
}
|
||||
Err(e) if block.should_succeed && !allow_false_positives => {
|
||||
Err(e) if block.should_succeed => {
|
||||
panic!(
|
||||
"block {} from `{}` failed when it should have succeeded: {:?}",
|
||||
i, self.name, e
|
||||
@@ -147,7 +145,7 @@ impl MultiTestCase {
|
||||
i, self.name, safe
|
||||
);
|
||||
}
|
||||
Err(e) if att.should_succeed && !allow_false_positives => {
|
||||
Err(e) if att.should_succeed => {
|
||||
panic!(
|
||||
"attestation {} from `{}` failed when it should have succeeded: {:?}",
|
||||
i, self.name, e
|
||||
@@ -181,53 +179,65 @@ impl TestCase {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_blocks(self, blocks: impl IntoIterator<Item = (usize, u64, bool)>) -> Self {
|
||||
self.with_signing_root_blocks(
|
||||
blocks
|
||||
.into_iter()
|
||||
.map(|(index, slot, should_succeed)| (index, slot, 0, should_succeed)),
|
||||
)
|
||||
pub fn with_blocks(self, blocks: impl IntoIterator<Item = (usize, u64, bool, bool)>) -> Self {
|
||||
self.with_signing_root_blocks(blocks.into_iter().map(
|
||||
|(index, slot, should_succeed, should_succeed_complete)| {
|
||||
(index, slot, 0, should_succeed, should_succeed_complete)
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn with_signing_root_blocks(
|
||||
mut self,
|
||||
blocks: impl IntoIterator<Item = (usize, u64, u64, bool)>,
|
||||
blocks: impl IntoIterator<Item = (usize, u64, u64, bool, bool)>,
|
||||
) -> Self {
|
||||
self.blocks.extend(
|
||||
blocks
|
||||
.into_iter()
|
||||
.map(|(pk, slot, signing_root, should_succeed)| TestBlock {
|
||||
self.blocks.extend(blocks.into_iter().map(
|
||||
|(pk, slot, signing_root, should_succeed, should_succeed_complete)| {
|
||||
assert!(
|
||||
!should_succeed || should_succeed_complete,
|
||||
"if should_succeed is true then should_succeed_complete must also be true"
|
||||
);
|
||||
TestBlock {
|
||||
pubkey: pubkey(pk),
|
||||
slot: Slot::new(slot),
|
||||
signing_root: Hash256::from_low_u64_be(signing_root),
|
||||
should_succeed,
|
||||
}),
|
||||
);
|
||||
should_succeed_complete,
|
||||
}
|
||||
},
|
||||
));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_attestations(
|
||||
self,
|
||||
attestations: impl IntoIterator<Item = (usize, u64, u64, bool)>,
|
||||
attestations: impl IntoIterator<Item = (usize, u64, u64, bool, bool)>,
|
||||
) -> Self {
|
||||
self.with_signing_root_attestations(
|
||||
attestations
|
||||
.into_iter()
|
||||
.map(|(id, source, target, succeed)| (id, source, target, 0, succeed)),
|
||||
)
|
||||
self.with_signing_root_attestations(attestations.into_iter().map(
|
||||
|(id, source, target, succeed, succeed_complete)| {
|
||||
(id, source, target, 0, succeed, succeed_complete)
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn with_signing_root_attestations(
|
||||
mut self,
|
||||
attestations: impl IntoIterator<Item = (usize, u64, u64, u64, bool)>,
|
||||
attestations: impl IntoIterator<Item = (usize, u64, u64, u64, bool, bool)>,
|
||||
) -> Self {
|
||||
self.attestations.extend(attestations.into_iter().map(
|
||||
|(pk, source, target, signing_root, should_succeed)| TestAttestation {
|
||||
pubkey: pubkey(pk),
|
||||
source_epoch: Epoch::new(source),
|
||||
target_epoch: Epoch::new(target),
|
||||
signing_root: Hash256::from_low_u64_be(signing_root),
|
||||
should_succeed,
|
||||
|(pk, source, target, signing_root, should_succeed, should_succeed_complete)| {
|
||||
assert!(
|
||||
!should_succeed || should_succeed_complete,
|
||||
"if should_succeed is true then should_succeed_complete must also be true"
|
||||
);
|
||||
TestAttestation {
|
||||
pubkey: pubkey(pk),
|
||||
source_epoch: Epoch::new(source),
|
||||
target_epoch: Epoch::new(target),
|
||||
signing_root: Hash256::from_low_u64_be(signing_root),
|
||||
should_succeed,
|
||||
should_succeed_complete,
|
||||
}
|
||||
},
|
||||
));
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user