Skip to content
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

fix(tee): lowercase enum TEE types #2798

Merged
merged 10 commits into from
Sep 5, 2024
Merged
46 changes: 43 additions & 3 deletions core/lib/basic_types/src/tee_types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
use std::fmt;

use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};

#[derive(Debug, Clone, Copy, PartialEq, EnumString, Display, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum TeeType {
#[strum(serialize = "sgx")]
Sgx,
}

impl fmt::Display for TeeType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TeeType::Sgx => write!(f, "sgx"),
}
}
}
pbeza marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(test)]
mod tests {
use serde_json;

use super::*;

#[test]
fn test_serialize_teetype() {
let json_str = "\"sgx\"";
let tee_type: TeeType = serde_json::from_str(json_str).unwrap();
assert_eq!(tee_type, TeeType::Sgx);

for json_str in &["\"Sgx\"", "\"SGX\""] {
let result: Result<TeeType, _> = serde_json::from_str(json_str);
assert!(result.is_err());
}
}

#[test]
fn test_deserialize_teetype() {
let tee_type = TeeType::Sgx;
let json_str = serde_json::to_string(&tee_type).unwrap();
assert_eq!(json_str, "\"sgx\"");
}

#[test]
fn test_display_teetype() {
assert_eq!(TeeType::Sgx.to_string(), "sgx");
}
}
2 changes: 1 addition & 1 deletion core/lib/prover_interface/tests/job_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn test_tee_proof_request_serialization() {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ],
"tee_type": "Sgx"
"tee_type": "sgx"
}"#;
let tee_proof_result = serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_str).unwrap();
let tee_proof_expected = SubmitTeeProofRequest(Box::new(L1BatchTeeProofForL1 {
Expand Down
4 changes: 2 additions & 2 deletions core/node/proof_data_handler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn request_tee_proof_inputs() {
},
L1BatchCommitmentMode::Rollup,
);
let req_body = Body::from(serde_json::to_vec(&json!({ "tee_type": "Sgx" })).unwrap());
let req_body = Body::from(serde_json::to_vec(&json!({ "tee_type": "sgx" })).unwrap());
let response = app
.oneshot(
Request::builder()
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn submit_tee_proof() {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ],
"tee_type": "Sgx"
"tee_type": "sgx"
}"#;
let tee_proof_request =
serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_request_str).unwrap();
Expand Down
Loading