use wasm_capability_contract::CapabilityScope;
fn round_trip(scope: &CapabilityScope) -> CapabilityScope {
let json =
serde_json::to_string(scope).unwrap_or_else(|e| panic!("serialize must succeed: {e}"));
serde_json::from_str(&json).unwrap_or_else(|e| panic!("deserialize must succeed: {e}"))
}
#[test]
fn test_capability_scope_json_round_trip_preserves_allowed_entries() {
let original = CapabilityScope {
allowed: vec![
"api.example.com".to_string(),
"other.example.com".to_string(),
],
};
assert_eq!(round_trip(&original), original);
}
#[test]
fn test_capability_scope_json_round_trip_preserves_empty_allowed() {
let original = CapabilityScope { allowed: vec![] };
assert_eq!(round_trip(&original), original);
}
#[test]
fn test_capability_scope_json_round_trip_preserves_wildcard_entry_as_plain_data() {
let original = CapabilityScope {
allowed: vec!["*".to_string()],
};
assert_eq!(round_trip(&original), original);
}