v0.1.0-pre.062
This commit is contained in:
66
kb-lib/tests/operation_naming_matrix.rs
Normal file
66
kb-lib/tests/operation_naming_matrix.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
// file: kb-lib/tests/operation_naming_matrix.rs
|
||||
// version: 2
|
||||
|
||||
//! Integration guard for the persisted operation naming contract.
|
||||
|
||||
#[test]
|
||||
fn operation_naming_matrix_is_machine_readable_and_uses_canonical_dot_hierarchy()
|
||||
-> std::result::Result<(), std::string::String> {
|
||||
let matrix_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../test-fixtures/contract-matrices/OPERATION_NAMING_MATRIX.json");
|
||||
let matrix_text = match std::fs::read_to_string(matrix_path) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(std::format!(
|
||||
"operation naming matrix must be readable: {error}"
|
||||
));
|
||||
},
|
||||
};
|
||||
let matrix: serde_json::Value = match serde_json::from_str(matrix_text.as_str()) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(std::format!(
|
||||
"operation naming matrix must be valid JSON: {error}"
|
||||
));
|
||||
},
|
||||
};
|
||||
let entries = match matrix["entries"].as_array() {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => {
|
||||
return std::result::Result::Err(std::string::String::from(
|
||||
"operation naming matrix must expose entries",
|
||||
));
|
||||
},
|
||||
};
|
||||
assert!(!entries.is_empty());
|
||||
let obsolete_prefixes = [
|
||||
"solana_core.",
|
||||
"solana_native_",
|
||||
"spl_memo",
|
||||
"spl_token.",
|
||||
"spl_token_2022.",
|
||||
"spl_associated_token_account.",
|
||||
"spl_elgamal_registry.",
|
||||
"metadata_metaplex_token_metadata.",
|
||||
];
|
||||
for entry in entries {
|
||||
for field in [
|
||||
"processorName",
|
||||
"surfaceCode",
|
||||
"operationCode",
|
||||
"eventCode",
|
||||
"decoderName",
|
||||
"executorName",
|
||||
] {
|
||||
let std::option::Option::Some(value) = entry[field].as_str() else {
|
||||
continue;
|
||||
};
|
||||
assert!(!value.is_empty());
|
||||
assert!(
|
||||
!obsolete_prefixes.iter().any(|prefix| return value.starts_with(prefix)),
|
||||
"obsolete persisted identifier in {field}: {value}"
|
||||
);
|
||||
}
|
||||
}
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
Reference in New Issue
Block a user