pub const FORMAT_VERSION: u32 = 1;
pub const CERT_SCHEMA_VERSION: u32 = 4;
pub const ARTIFACT_CERTIFICATE_ROOT: &str = "AverCert.Artifact.certificate";
pub const CURRENT_WALL_ID: &str =
"sha256:4a017fbf1988fc0ac8ffa2b758c2b4b349f72cb023cf9c4d54fd1994da1b7a7a";
pub const WASM_GC_CAPABILITIES: &[(&str, &str)] = &[
("aver", "console_print"),
("aver", "console_error"),
("aver", "console_warn"),
("aver", "time_unix_ms"),
("aver", "request_method"),
("aver", "request_url"),
("aver", "request_query"),
("aver", "request_body"),
("aver", "request_headers_load"),
("aver", "response_text"),
("aver", "response_set_header"),
("aver", "http_send"),
("aver", "http_add_request_header"),
("aver", "http_clear_request_headers"),
("aver", "env_get"),
("aver", "env_set"),
("aver", "console_read_line"),
("aver", "args_len"),
("aver", "args_get"),
("aver", "random_float"),
("aver", "random_int"),
("aver", "time_sleep"),
("aver", "time_now"),
("aver", "float_sin"),
("aver", "float_cos"),
("aver", "float_atan2"),
("aver", "float_pow"),
("aver", "terminal_enable_raw_mode"),
("aver", "terminal_disable_raw_mode"),
("aver", "terminal_clear"),
("aver", "terminal_move_to"),
("aver", "terminal_print"),
("aver", "terminal_set_color"),
("aver", "terminal_reset_color"),
("aver", "terminal_read_key"),
("aver", "terminal_size"),
("aver", "terminal_hide_cursor"),
("aver", "terminal_show_cursor"),
("aver", "terminal_flush"),
("aver", "disk_read_text"),
("aver", "disk_write_text"),
("aver", "disk_append_text"),
("aver", "disk_exists"),
("aver", "disk_delete"),
("aver", "disk_delete_dir"),
("aver", "disk_list_dir"),
("aver", "disk_make_dir"),
("aver", "tcp_connect"),
("aver", "tcp_write_line"),
("aver", "tcp_write_bytes"),
("aver", "tcp_read_line"),
("aver", "tcp_read_bytes"),
("aver", "tcp_close"),
("aver", "tcp_send"),
("aver", "tcp_send_bytes"),
("aver", "tcp_ping"),
("aver", "http_get"),
("aver", "http_head"),
("aver", "http_delete"),
("aver", "http_post"),
("aver", "http_put"),
("aver", "http_patch"),
("aver", "record_enter_group"),
("aver", "record_set_branch"),
("aver", "record_exit_group"),
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn capability_pairs_are_unique() {
let unique = WASM_GC_CAPABILITIES
.iter()
.copied()
.collect::<std::collections::BTreeSet<_>>();
assert_eq!(unique.len(), WASM_GC_CAPABILITIES.len());
}
#[test]
fn format_spec_states_the_current_wall_identity_and_source_count() {
let spec = include_str!("../../docs/certificate-format.md");
assert!(
spec.contains(CURRENT_WALL_ID),
"certificate-format.md does not state the current wall id {CURRENT_WALL_ID}; \
update the wall identity printed in the spec"
);
let count_phrase = format!(
"{} embedded `.lean` wall sources",
crate::wall::SOURCES.len()
);
assert!(
spec.contains(&count_phrase),
"certificate-format.md does not state \"{count_phrase}\"; \
update the wall source count printed in the spec"
);
}
#[test]
fn format_spec_states_the_current_schema_version() {
let spec = include_str!("../../docs/certificate-format.md");
for phrase in [
format!("`{CERT_SCHEMA_VERSION}` (`CERT_SCHEMA_VERSION`)"),
format!("schema_version = {CERT_SCHEMA_VERSION}"),
] {
assert!(
spec.contains(&phrase),
"certificate-format.md does not state \"{phrase}\"; \
update the schema version printed in the spec"
);
}
}
#[test]
fn the_two_schema_version_constants_agree() {
let engine_src = include_str!("engine/mod.rs");
let expected = format!("pub const CERT_SCHEMA_VERSION: u32 = {CERT_SCHEMA_VERSION};");
assert!(
engine_src.contains(&expected),
"engine/mod.rs does not declare `{expected}`; the producer would emit a \
schema version the transport parser rejects"
);
}
#[test]
fn every_wall_contract_string_has_a_verbatim_producer_twin() {
let axes = include_str!("../assets/wall/current/ClaimAxes.lean");
let engine_src = include_str!("engine/mod.rs");
let mut seen = 0usize;
let mut lines = axes.lines();
while let Some(line) = lines.next() {
let trimmed = line.trim();
if !(trimmed.starts_with("def ") && trimmed.ends_with("Contract : String :=")) {
continue;
}
let literal = lines
.next()
.expect("a contract definition is followed by its literal")
.trim();
assert!(
literal.starts_with('"') && literal.ends_with('"'),
"expected a one-line string literal under `{trimmed}`, got: {literal}"
);
assert!(
engine_src.contains(literal),
"wall contract `{trimmed}` has no verbatim producer twin in \
engine/mod.rs: {literal}"
);
seen += 1;
}
assert!(
seen >= 12,
"only {seen} wall contract definitions were found; the scan shape has \
drifted and this test has stopped checking anything"
);
}
}