|
| 1 | +//! Pre hex encoded StmTypes for testing. |
| 2 | +
|
| 3 | +/// A list of pre json hex encoded [MithrilStm:StmSig](type@mithril_stm::stm::StmSig) |
| 4 | +pub fn single_signature<'a>() -> [&'a str; 3] { |
| 5 | + [ |
| 6 | + "7b227369676d61223a5b3133302c3137372c31352c3232392c32342c3235312c3234372c3137312c3139362c32313\ |
| 7 | + 02c3134332c3131332c38362c3138392c39322c35362c3131322c33332c3139332c3231322c35342c3231342c32382\ |
| 8 | + c3231362c3232372c3137332c3130302c3132372c3137382c34302c39382c38372c32392c3138312c3235352c31313\ |
| 9 | + 12c3135372c3232342c3233352c34362c3130302c3136392c3233322c3138392c3235322c38322c3133392c33365d2\ |
| 10 | + c22696e6465786573223a5b302c312c332c342c362c382c392c31302c31312c31322c31342c31382c32312c32322c3\ |
| 11 | + 2332c32352c32362c32372c33302c33332c33342c33382c34312c34332c35302c35382c35392c36302c36312c36322\ |
| 12 | + c36372c36392c37312c37332c37352c37362c37372c38312c38322c38332c38342c39302c39312c39322c39332c393\ |
| 13 | + 72c39385d2c227369676e65725f696e646578223a327d", |
| 14 | + "7b227369676d61223a5b3136362c3130352c39352c32382c31312c3139372c32352c31372c3132392c3231312c313\ |
| 15 | + 6312c35322c3231372c3232382c3136362c38342c37312c39342c3133312c3133312c32332c35302c3131342c31383\ |
| 16 | + 82c32322c3133372c3231342c37372c3234332c3233382c3136332c3130322c34392c36342c32332c38322c3139312\ |
| 17 | + c3235312c3132302c34312c3230352c3131302c3232352c3138342c38352c32342c382c3130325d2c22696e6465786\ |
| 18 | + 573223a5b352c382c392c31322c31332c31352c32302c32312c32332c32352c32392c33312c33342c33362c33392c3\ |
| 19 | + 4302c34332c34342c34352c34382c35352c35372c36312c36362c36382c37312c37322c37332c37342c37382c37392\ |
| 20 | + c38302c38322c38332c38382c39312c39322c39342c39352c39362c3130322c3130352c3130362c3130382c3131302\ |
| 21 | + c3131322c3131332c3131352c3131372c3131392c3132322c3132332c3132352c3132382c3132392c3133332c31333\ |
| 22 | + 72c3133392c3134302c3134312c3134322c3134342c3134362c3134372c3134382c3134392c3135312c3135322c313\ |
| 23 | + 5342c3135392c3136302c3136312c3136322c3136332c3136342c3136362c3136372c3136382c3137302c3137322c3\ |
| 24 | + 137342c3137372c3137382c3137392c3138302c3138322c3138342c3138372c3138382c3138392c3139312c3139332\ |
| 25 | + c3139352c3139372c3230302c3230322c3230352c3230362c3230382c3230395d2c227369676e65725f696e6465782\ |
| 26 | + 23a307d", |
| 27 | + "7b227369676d61223a5b3133312c3133342c3235322c3138372c31352c3135362c352c3130352c31372c3235322c3\ |
| 28 | + 137372c3231382c3132372c3133342c36312c3235352c3232382c33332c3136382c33312c3131362c3131332c31383\ |
| 29 | + 02c3232362c3232392c32312c3137302c35392c322c3138332c3232322c38312c3235302c31332c3139332c31332c3\ |
| 30 | + 234362c3232392c3137302c3130352c3138352c3136342c38382c392c3136302c35322c3130332c32315d2c22696e6\ |
| 31 | + 465786573223a5b302c312c322c342c352c362c372c382c392c31322c31342c32342c32382c32392c33312c33332c3\ |
| 32 | + 3352c33362c33382c34302c34312c34322c34332c34372c34392c35302c35312c35322c35342c35352c35362c35372\ |
| 33 | + c35382c35392c36302c36312c36322c36342c36362c36372c36382c36392c37312c37322c37342c37362c37372c373\ |
| 34 | + 82c37392c38302c38312c38322c38332c38342c38362c38392c39302c39312c39332c39352c39362c39372c39382c3\ |
| 35 | + 130302c3130312c3130352c3130362c3130382c3130392c3131302c3131312c3131322c3131332c3131382c3131392\ |
| 36 | + c3132302c3132312c3132322c3132332c3132342c3132352c3132362c3132372c3132382c3133302c3133322c31333\ |
| 37 | + 62c3134302c3134322c3134332c3134342c3134352c3134392c3135312c3135342c3135362c3135372c3135382c313\ |
| 38 | + 5392c3136302c3136312c3136322c3136332c3136342c3136362c3136372c3136382c3136392c3137302c3137312c3\ |
| 39 | + 137322c3137332c3137342c3137382c3137392c3138302c3138312c3138322c3138332c3138342c3138352c3138362\ |
| 40 | + c3138392c3139302c3139312c3139322c3139332c3139352c3139362c3139392c3230312c3230322c3230332c32303\ |
| 41 | + 42c3230352c3230362c3230385d2c227369676e65725f696e646578223a317d", |
| 42 | + ] |
| 43 | +} |
| 44 | + |
| 45 | +#[cfg(test)] |
| 46 | +mod test { |
| 47 | + use super::*; |
| 48 | + use mithril_stm::stm::StmSig; |
| 49 | + use serde::{de::DeserializeOwned, Serialize}; |
| 50 | + use std::any::type_name; |
| 51 | + |
| 52 | + use crate::crypto_helper::key_decode_hex; |
| 53 | + |
| 54 | + fn assert_encoded_are_still_matching_concrete_type<T: Serialize + DeserializeOwned>( |
| 55 | + encoded_types: &[&str], |
| 56 | + ) { |
| 57 | + let errors: Vec<String> = encoded_types |
| 58 | + .iter() |
| 59 | + .filter_map(|encoded_type| match key_decode_hex::<T>(encoded_type) { |
| 60 | + Ok(_) => None, |
| 61 | + Err(error_src) => { |
| 62 | + let error = format!( |
| 63 | + "* The encoded key does not match anymore the structure of the type: {}\ |
| 64 | + \n ** encoded_string: {encoded_type}\ |
| 65 | + \n ** error: {error_src}", |
| 66 | + type_name::<T>() |
| 67 | + ); |
| 68 | + |
| 69 | + Some(error) |
| 70 | + } |
| 71 | + }) |
| 72 | + .collect(); |
| 73 | + |
| 74 | + assert!( |
| 75 | + errors.is_empty(), |
| 76 | + "At least one of the encoded values could not be decoded:\n{}", |
| 77 | + errors.join("\n") |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + #[test] |
| 82 | + fn assert_encoded_single_signatures_are_still_matching_concrete_type() { |
| 83 | + assert_encoded_are_still_matching_concrete_type::<StmSig>(&single_signature()); |
| 84 | + } |
| 85 | +} |
0 commit comments