diff --git a/core/lib/basic_types/src/tee_types.rs b/core/lib/basic_types/src/tee_types.rs index c9be9b6e99d8..d49f2f183885 100644 --- a/core/lib/basic_types/src/tee_types.rs +++ b/core/lib/basic_types/src/tee_types.rs @@ -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"), + } + } +} + +#[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 = 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"); + } +} diff --git a/core/lib/prover_interface/tests/job_serialization.rs b/core/lib/prover_interface/tests/job_serialization.rs index a2d55a140655..a2aee0c2733e 100644 --- a/core/lib/prover_interface/tests/job_serialization.rs +++ b/core/lib/prover_interface/tests/job_serialization.rs @@ -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::(tee_proof_str).unwrap(); let tee_proof_expected = SubmitTeeProofRequest(Box::new(L1BatchTeeProofForL1 { diff --git a/core/node/proof_data_handler/src/tests.rs b/core/node/proof_data_handler/src/tests.rs index 5d7569d5720c..6ab7e4dec436 100644 --- a/core/node/proof_data_handler/src/tests.rs +++ b/core/node/proof_data_handler/src/tests.rs @@ -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() @@ -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::(tee_proof_request_str).unwrap();