Skip to content

Commit

Permalink
Boilerplate for handlers. Create (wip) BlobToKzgCommitmentTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoAlice committed Mar 29, 2024
1 parent f9d36ba commit 834e5eb
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions spec-tests/runners/kzg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
use crate::{test_case::TestCase, test_utils::Error};
use crate::{
test_case::TestCase,
test_utils::{load_yaml, Error},
};
use ethereum_consensus::deneb::{
mainnet as spec,
polynomial_commitments::{blob_to_kzg_commitment, KzgCommitment, KzgSettings},
};
use serde::Deserialize;
use serde_with::{serde_as, DefaultOnError};

pub fn dispatch(_test: &TestCase) -> Result<(), Error> {
todo!()
pub fn dispatch(test: &TestCase) -> Result<(), Error> {
let meta = &test.meta;
let path = &test.data_path;
match meta.handler.0.as_str() {
"blob_to_kzg_commitment" => {
let test_case = BlobToKzgCommitmentTestCase::from(path);
test_case.run();
Ok(())
}
"compute_kzg_proof" => {
todo!()
}
"verify_kzg_proof" => {
todo!()
}
"compute_blob_kzg_proof" => {
todo!()
}
"verify_blob_kzg_proof" => {
todo!()
}
"verify_blob_kzg_proof_batch" => {
todo!()
}
}
}

#[serde_as]
#[derive(Debug, Deserialize)]
struct BlobToKzgCommitmentInput {
#[serde_as(deserialize_as = "DefaultOnError")]
blob: spec::Blob,
#[serde_as(deserialize_as = "DefaultOnError")]
kzg_settings: KzgSettings,
}

#[derive(Debug, Deserialize)]
pub struct BlobToKzgCommitmentTestCase {
input: BlobToKzgCommitmentInput,
output: KzgCommitment,
}

impl BlobToKzgCommitmentTestCase {
pub fn from(test_case_path: &str) -> Self {
let path = test_case_path.to_string() + "/data.yaml";
load_yaml(&path)
}

pub fn run(&self) -> bool {
blob_to_kzg_commitment(&self.input.blob, &self.input.kzg_settings).is_ok()
}
}

1 comment on commit 834e5eb

@EchoAlice
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions for PR:

  1. Should i modify input here to include kzg settings, or keep input same as spec and introduce KzgSettings internally within run()?
  2. Is it ok to use .run() on a test case instead of some sort of .execute()? You said to not implement the execute trait, but am unsure whether you want to completely omit all functionality it provides.
  3. Default and Deserialize traits aren't defined for KzgSettings. This is needed for load_yaml(). Should i implement these traits? Or am i missing something?

Please sign in to comment.