67 lines
2.3 KiB
Rust
67 lines
2.3 KiB
Rust
// file: ks-lib/tests/operation_naming_matrix.rs
|
|
// version: 3
|
|
|
|
//! 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(());
|
|
}
|