-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcases.rs
More file actions
182 lines (169 loc) · 5.92 KB
/
cases.rs
File metadata and controls
182 lines (169 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
use super::*;
use rayon::prelude::*;
use std::fmt::{Debug, Display, Formatter};
use std::path::{Path, PathBuf};
use types::ForkName;
mod bls_aggregate_sigs;
mod bls_aggregate_verify;
mod bls_batch_verify;
mod bls_eth_aggregate_pubkeys;
mod bls_eth_fast_aggregate_verify;
mod bls_fast_aggregate_verify;
mod bls_sign_msg;
mod bls_verify_msg;
mod common;
mod compute_columns_for_custody_groups;
mod epoch_processing;
mod fork;
mod fork_choice;
mod genesis_initialization;
mod genesis_validity;
mod get_custody_groups;
mod gossip_validation;
mod kzg_blob_to_kzg_commitment;
mod kzg_compute_blob_kzg_proof;
mod kzg_compute_cells;
mod kzg_compute_cells_and_kzg_proofs;
mod kzg_compute_kzg_proof;
mod kzg_recover_cells_and_kzg_proofs;
mod kzg_verify_blob_kzg_proof;
mod kzg_verify_blob_kzg_proof_batch;
mod kzg_verify_cell_kzg_proof_batch;
mod kzg_verify_kzg_proof;
mod light_client_verify_is_better_update;
mod merkle_proof_validity;
mod operations;
mod rewards;
mod sanity_blocks;
mod sanity_slots;
mod shuffling;
mod ssz_generic;
mod ssz_static;
mod transition;
pub use self::fork_choice::*;
pub use bls_aggregate_sigs::*;
pub use bls_aggregate_verify::*;
pub use bls_batch_verify::*;
pub use bls_eth_aggregate_pubkeys::*;
pub use bls_eth_fast_aggregate_verify::*;
pub use bls_fast_aggregate_verify::*;
pub use bls_sign_msg::*;
pub use bls_verify_msg::*;
pub use common::SszStaticType;
pub use compute_columns_for_custody_groups::*;
pub use epoch_processing::*;
pub use fork::ForkTest;
pub use genesis_initialization::*;
pub use genesis_validity::*;
pub use get_custody_groups::*;
pub use gossip_validation::*;
pub use kzg_blob_to_kzg_commitment::*;
pub use kzg_compute_blob_kzg_proof::*;
pub use kzg_compute_cells::*;
pub use kzg_compute_cells_and_kzg_proofs::*;
pub use kzg_compute_kzg_proof::*;
pub use kzg_recover_cells_and_kzg_proofs::*;
pub use kzg_verify_blob_kzg_proof::*;
pub use kzg_verify_blob_kzg_proof_batch::*;
pub use kzg_verify_cell_kzg_proof_batch::*;
pub use kzg_verify_kzg_proof::*;
pub use light_client_verify_is_better_update::*;
pub use merkle_proof_validity::*;
pub use operations::*;
pub use rewards::RewardsTest;
pub use sanity_blocks::*;
pub use sanity_slots::*;
pub use shuffling::*;
pub use ssz_generic::*;
pub use ssz_static::*;
pub use transition::TransitionTest;
/// Used for running feature tests for future forks that have not yet been added to `ForkName`.
/// This runs tests in the directory named by the feature instead of the fork name. This has been
/// the pattern used in the `consensus-spec-tests` repository:
/// `consensus-spec-tests/tests/general/[feature_name]/[runner_name].`
/// e.g. consensus-spec-tests/tests/general/peerdas/ssz_static
///
/// The feature tests can be run with one of the following methods:
/// 1. `handler.run_for_feature(feature_name)` for new tests that are not on existing fork, i.e. a
/// new handler. This will be temporary and the test will need to be updated to use
/// `handle.run()` once the feature is incorporated into a fork.
/// 2. `handler.run()` for tests that are already on existing forks, but with new test vectors for
/// the feature. In this case the `handler.is_enabled_for_feature` will need to be implemented
/// to return `true` for the feature in order for the feature test vector to be tested.
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum FeatureName {
// Placeholder for future feature-gated forks
// Add new feature-gated forks here before they are incorporated into a main fork
#[doc(hidden)]
__Placeholder,
}
impl FeatureName {
pub fn list_all() -> Vec<FeatureName> {
vec![]
}
/// `ForkName` to use when running the feature tests.
pub fn fork_name(&self) -> ForkName {
match self {
FeatureName::__Placeholder => unreachable!("Placeholder variant should never be used"),
}
}
}
impl Display for FeatureName {
fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
FeatureName::__Placeholder => unreachable!("Placeholder variant should never be used"),
}
}
}
pub trait LoadCase: Sized {
/// Load the test case from a test case directory.
fn load_from_dir(_path: &Path, _fork_name: ForkName) -> Result<Self, Error>;
}
pub trait Case: Debug + Sync {
/// An optional field for implementing a custom description.
///
/// Defaults to "no description".
fn description(&self) -> String {
"no description".to_string()
}
/// Whether or not this test exists for the given `fork_name`.
///
/// Returns `true` by default.
fn is_enabled_for_fork(_fork_name: ForkName) -> bool {
true
}
/// Whether or not this test exists for the given `feature_name`. This is intended to be used
/// for features that have not been added to a fork yet, and there is usually a separate folder
/// for the feature in the `consensus-spec-tests` repository.
///
/// Returns `false` by default.
fn is_enabled_for_feature(_feature_name: FeatureName) -> bool {
false
}
/// Execute a test and return the result.
///
/// `case_index` reports the index of the case in the set of test cases. It is not strictly
/// necessary, but it's useful when troubleshooting specific failing tests.
fn result(&self, case_index: usize, fork_name: ForkName) -> Result<(), Error>;
}
#[derive(Debug)]
pub struct Cases<T> {
pub test_cases: Vec<(PathBuf, T)>,
}
impl<T: Case> Cases<T> {
pub fn test_results(&self, fork_name: ForkName, use_rayon: bool) -> Vec<CaseResult> {
if use_rayon {
self.test_cases
.into_par_iter()
.enumerate()
.map(|(i, (path, tc))| CaseResult::new(i, path, tc, tc.result(i, fork_name)))
.collect()
} else {
self.test_cases
.iter()
.enumerate()
.map(|(i, (path, tc))| CaseResult::new(i, path, tc, tc.result(i, fork_name)))
.collect()
}
}
}