Skip to content

Commit c023ca5

Browse files
committed
test(host): cover recursive public catalog traversal
1 parent 6d1a875 commit c023ca5

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

‎tests/typed_host_no_dynamic_contract_tests.rs‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
use std::collections::BTreeSet;
88

99
use vm::{
10-
HostApiCatalog, HostTypeSchema, http_host_catalog, jit_host_catalog, sqlite_host_catalog,
11-
standard_host_catalog,
10+
HostApiCatalog, HostStructField, HostTypeSchema, http_host_catalog, jit_host_catalog,
11+
sqlite_host_catalog, standard_host_catalog,
1212
};
1313

14-
fn assert_no_public_dynamic_schema(catalog_name: &str, catalog: &HostApiCatalog) {
14+
fn assert_no_public_dynamic_root(path: &str, schema: &HostTypeSchema) {
1515
fn visit(path: &str, schema: &HostTypeSchema, seen: &mut BTreeSet<String>) {
1616
match schema {
1717
HostTypeSchema::Map(_) | HostTypeSchema::Unknown => {
@@ -45,31 +45,53 @@ fn assert_no_public_dynamic_schema(catalog_name: &str, catalog: &HostApiCatalog)
4545
}
4646
}
4747

48+
visit(path, schema, &mut BTreeSet::new());
49+
}
50+
51+
fn assert_no_public_dynamic_schema(catalog_name: &str, catalog: &HostApiCatalog) {
4852
for schema in catalog.structs() {
4953
for field in &schema.fields {
50-
visit(
54+
assert_no_public_dynamic_root(
5155
&format!("{catalog_name}::{}.{}", schema.name, field.name),
5256
&field.ty,
53-
&mut BTreeSet::new(),
5457
);
5558
}
5659
}
5760
for function in catalog.functions() {
5861
for param in &function.params {
59-
visit(
62+
assert_no_public_dynamic_root(
6063
&format!("{catalog_name}::{}({})", function.name, param.name),
6164
&param.ty,
62-
&mut BTreeSet::new(),
6365
);
6466
}
65-
visit(
67+
assert_no_public_dynamic_root(
6668
&format!("{catalog_name}::{} return", function.name),
6769
&function.return_type,
68-
&mut BTreeSet::new(),
6970
);
7071
}
7172
}
7273

74+
fn recursive_named_schema() -> HostTypeSchema {
75+
HostTypeSchema::named_struct(
76+
"RecursiveNode",
77+
vec![
78+
HostStructField::new("value", HostTypeSchema::Int),
79+
HostStructField::new(
80+
"next",
81+
HostTypeSchema::Optional(Box::new(HostTypeSchema::named_struct(
82+
"RecursiveNode",
83+
Vec::new(),
84+
))),
85+
),
86+
],
87+
)
88+
}
89+
90+
#[test]
91+
fn recursive_named_struct_walk_stops_at_repeated_named_type() {
92+
assert_no_public_dynamic_root("recursive::node", &recursive_named_schema());
93+
}
94+
7395
#[test]
7496
fn affected_public_host_catalogs_have_no_reachable_map_or_unknown() {
7597
assert_no_public_dynamic_schema("http", &http_host_catalog());

0 commit comments

Comments
 (0)