-
Notifications
You must be signed in to change notification settings - Fork 28
Spec tests Framework #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spec tests Framework #247
Changes from all commits
5672e63
4d4fe42
b15d65a
ad6c2ac
a188950
0b3e4e3
abda862
55cec77
fc838e4
e620aa0
55ff4b9
86d0df2
00934b4
a5d48be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "anchor/spec_tests/src/ssv-spec"] | ||
| path = anchor/spec_tests/src/ssv-spec | ||
| url = https://github.com/ssvlabs/ssv-spec.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [package] | ||
| name = "spec_tests" | ||
| version = "0.1.0" | ||
| edition = { workspace = true } | ||
| authors = ["Sigma Prime <contact@sigmaprime.io>"] | ||
|
|
||
| [dependencies] | ||
| serde = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| walkdir = "2.5.0" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||||
| #![allow(dead_code)] | ||||||
|
|
||||||
| mod qbft; | ||||||
| use std::{collections::HashMap, fs, path::Path, sync::LazyLock}; | ||||||
|
|
||||||
| use qbft::QbftSpecTestType; | ||||||
| use serde::de::DeserializeOwned; | ||||||
| use walkdir::WalkDir; | ||||||
|
|
||||||
| use crate::qbft::*; | ||||||
|
|
||||||
| // All Spec Test Variants. Maps to an inner variant type that describes specific tests | ||||||
| #[derive(Eq, PartialEq, Hash)] | ||||||
| enum SpecTestType { | ||||||
| Qbft(QbftSpecTestType), | ||||||
| } | ||||||
|
|
||||||
| // Impl display for path construction. Do not change | ||||||
| impl SpecTestType { | ||||||
| fn path(&self) -> &'static Path { | ||||||
| match self { | ||||||
| SpecTestType::Qbft(_) => Path::new("src/ssv-spec/qbft/spectest/generate/tests"), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Core trait to orchestrate setting up and running spec tests. The spec tests are broken up into | ||||||
| // different categories with different file strucutres. For each file structure, implementing the | ||||||
| // required functions allows for a smooth testing process | ||||||
| trait SpecTest { | ||||||
| // Retrieve the name of the test | ||||||
| fn name(&self) -> &str; | ||||||
|
|
||||||
| // Setup a runner for the test. This will configure and construct eveything required to | ||||||
| // execute the test | ||||||
| fn setup(&mut self); | ||||||
|
|
||||||
| // Run the test and verify that the output is what we were expecting. | ||||||
| fn run(&self) -> bool; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could split it into
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I want to head in this direction but im holding off for now because I am not sure how the structure of this would work. Need to dig deeper into the other tests first. Might be a case of setting up tests and then refactoring to an assertion func too |
||||||
|
|
||||||
| // Return the type of this test. Used as a Key for the loaders and path construction | ||||||
| fn test_type() -> SpecTestType | ||||||
| where | ||||||
| Self: Sized; | ||||||
| } | ||||||
|
|
||||||
| // Abstract away repeated logic for registering a test type with the loader | ||||||
| macro_rules! register_test_loaders { | ||||||
| ($($test_type:ty),* $(,)?) => { | ||||||
| LazyLock::new(|| { | ||||||
| let mut loaders = HashMap::new(); | ||||||
| $( | ||||||
| register_test::<$test_type>(&mut loaders); | ||||||
| )* | ||||||
| loaders | ||||||
| }) | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| type Loaders = HashMap<SpecTestType, fn(&str) -> Box<dyn SpecTest>>; | ||||||
| static TEST_LOADERS: LazyLock<Loaders> = register_test_loaders!(TimeoutTest); | ||||||
|
||||||
| static TEST_LOADERS: LazyLock<Loaders> = register_test_loaders!(TimeoutTest); | |
| static TEST_LOADERS: LazyLock<Loaders> = register_test_loaders!(TimeoutTest, ProposalTest, CommitTest); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{QbftSpecTestType, SpecTest, SpecTestType}; | ||
|
|
||
| impl SpecTest for ControllerTest { | ||
| fn name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| fn run(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn setup(&mut self) {} | ||
|
|
||
| fn test_type() -> SpecTestType { | ||
| SpecTestType::Qbft(QbftSpecTestType::Controller) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct ControllerTest { | ||
| pub name: String, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{QbftSpecTestType, SpecTest, SpecTestType}; | ||
|
|
||
| impl SpecTest for CreateMessageTest { | ||
| fn name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| fn run(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn setup(&mut self) {} | ||
|
|
||
| fn test_type() -> SpecTestType { | ||
| SpecTestType::Qbft(QbftSpecTestType::CreateMessage) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct CreateMessageTest { | ||
| pub name: String, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{QbftSpecTestType, SpecTest, SpecTestType}; | ||
|
|
||
| impl SpecTest for MessageProcessingTest { | ||
| fn name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| fn run(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn setup(&mut self) {} | ||
|
|
||
| fn test_type() -> SpecTestType { | ||
| SpecTestType::Qbft(QbftSpecTestType::MessageProcessing) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct MessageProcessingTest { | ||
| pub name: String, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // QBFT test variants | ||
| // Modules contain parsing logic | ||
| mod controller; | ||
| mod create_message; | ||
| mod message_processing; | ||
| mod qbft_message; | ||
| mod round_robin; | ||
| mod timeout; | ||
|
|
||
| pub use timeout::TimeoutTest; | ||
|
|
||
| #[derive(Eq, PartialEq, Hash)] | ||
| pub(crate) enum QbftSpecTestType { | ||
| Timeout, | ||
| QbftMessage, | ||
| MessageProcessing, | ||
| CreateMessage, | ||
| Controller, | ||
| RoundRobin, | ||
| } | ||
|
|
||
| // Contains specific identifier for the test file | ||
| impl std::fmt::Display for QbftSpecTestType { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| match self { | ||
| QbftSpecTestType::Timeout => write!(f, "timeout"), | ||
| QbftSpecTestType::QbftMessage => write!(f, "MsgSpecTest"), | ||
| QbftSpecTestType::MessageProcessing => write!(f, "MsgProcessingSpecTest"), | ||
| QbftSpecTestType::CreateMessage => write!(f, "CreateMsgSpecTest"), | ||
| QbftSpecTestType::Controller => write!(f, "ControllerSpecTest"), | ||
| QbftSpecTestType::RoundRobin => write!(f, "RoundRobinSpecTest"), | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{QbftSpecTestType, SpecTest, SpecTestType}; | ||
|
|
||
| impl SpecTest for QbftMessageTest { | ||
| fn name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| fn run(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn setup(&mut self) {} | ||
|
|
||
| fn test_type() -> SpecTestType { | ||
| SpecTestType::Qbft(QbftSpecTestType::QbftMessage) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct QbftMessageTest { | ||
| name: String, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::{QbftSpecTestType, SpecTest, SpecTestType}; | ||
|
|
||
| impl SpecTest for RoundRobinTest { | ||
| fn name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| fn run(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn setup(&mut self) {} | ||
|
|
||
| fn test_type() -> SpecTestType { | ||
| SpecTestType::Qbft(QbftSpecTestType::RoundRobin) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct RoundRobinTest { | ||
| name: String, | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| use serde::{Deserialize, Serialize}; | ||||||
|
|
||||||
| use crate::{QbftSpecTestType, SpecTest, SpecTestType}; | ||||||
|
|
||||||
| impl SpecTest for TimeoutTest { | ||||||
| fn name(&self) -> &str { | ||||||
| &self.name | ||||||
| } | ||||||
|
|
||||||
| fn run(&self) -> bool { | ||||||
| true | ||||||
| } | ||||||
|
|
||||||
| fn setup(&mut self) {} | ||||||
|
|
||||||
| fn test_type() -> SpecTestType { | ||||||
| SpecTestType::Qbft(QbftSpecTestType::Timeout) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[derive(Debug, Serialize, Deserialize)] | ||||||
| pub struct TimeoutTest { | ||||||
| name: String, | ||||||
|
||||||
| name: String, | |
| pub name: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a property in the variant?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean, do you mean on the trait? or the inner enum variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the enum variant