Skip to content

Commit 95ea20c

Browse files
lpahlavilwshang
andauthored
fix: check-endpoints handles all exported functions (#95)
* XC-391: Add missing endpoint types * XC-391: Rename `Callback` to `Custom` * XC-391: Add CHANGELOG entry * XC-391: Refactor `CanisterEndpoint` * update changelog --------- Co-authored-by: Linwei Shang <linwei.shang@dfinity.org>
1 parent b381a37 commit 95ea20c

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [unreleased]
88

9+
* Fix: `check-endpoints` now correctly handles all exported functions, not just those prefixed with `canister_`.
10+
911
## [0.9.7] - 2025-09-26
1012

1113
* Add `check-endpoints` command to `ic-wasm`.

src/check_endpoints/mod.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,37 @@ pub enum CanisterEndpoint {
1717
Query(String),
1818
#[display("canister_composite_query:{0}")]
1919
CompositeQuery(String),
20-
#[display("canister_heartbeat")]
21-
Heartbeat,
22-
#[display("canister_global_timer")]
23-
GlobalTimer,
24-
#[display("canister_init")]
25-
Init,
26-
#[display("canister_post_upgrade")]
27-
PostUpgrade,
28-
#[display("canister_pre_upgrade")]
29-
PreUpgrade,
20+
#[display("{0}")]
21+
Entrypoint(String),
3022
}
3123

3224
impl TryFrom<&ExportedMethodInfo> for CanisterEndpoint {
3325
type Error = anyhow::Error;
3426

3527
fn try_from(method: &ExportedMethodInfo) -> Result<Self, Self::Error> {
3628
type EndpointConstructor = fn(&str) -> CanisterEndpoint;
37-
let mappings: &[(&str, EndpointConstructor)] = &[
38-
("canister_query", |s| CanisterEndpoint::Query(s.to_string())),
29+
const MAPPINGS: &[(&str, EndpointConstructor)] = &[
3930
("canister_update", |s| {
4031
CanisterEndpoint::Update(s.to_string())
4132
}),
33+
("canister_query", |s| CanisterEndpoint::Query(s.to_string())),
4234
("canister_composite_query", |s| {
4335
CanisterEndpoint::CompositeQuery(s.to_string())
4436
}),
45-
("canister_heartbeat", |_| CanisterEndpoint::Heartbeat),
46-
("canister_global_timer", |_| CanisterEndpoint::GlobalTimer),
47-
("canister_init", |_| CanisterEndpoint::Init),
48-
("canister_post_upgrade", |_| CanisterEndpoint::PostUpgrade),
49-
("canister_pre_upgrade", |_| CanisterEndpoint::PreUpgrade),
5037
];
5138

52-
for (candid_prefix, constructor) in mappings {
39+
for (candid_prefix, constructor) in MAPPINGS {
5340
if let Some(rest) = method.name.strip_prefix(candid_prefix) {
5441
return Ok(constructor(rest.trim()));
5542
}
5643
}
5744

58-
Err(anyhow!(
59-
"Invalid exported method in canister WASM: '{}'",
60-
method.name
61-
))
45+
let trimmed = method.name.trim();
46+
if !trimmed.is_empty() {
47+
Ok(CanisterEndpoint::Entrypoint(trimmed.to_string()))
48+
} else {
49+
Err(anyhow!("Exported method in canister WASM has empty name"))
50+
}
6251
}
6352
}
6453

tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ fn check_endpoints() {
455455
.arg("check-endpoints")
456456
.assert()
457457
.stderr(
458-
"ERROR: The following endpoint is unexpected in the WASM exports section: canister_update:__motoko_async_helper\n\
458+
"ERROR: The following endpoint is unexpected in the WASM exports section: canister_update:__motoko_async_helper\n\
459459
ERROR: The following endpoint is unexpected in the WASM exports section: canister_query:__get_candid_interface_tmp_hack\n\
460460
ERROR: The following endpoint is unexpected in the WASM exports section: canister_query:__motoko_stable_var_info\n\
461461
ERROR: The following endpoint is unexpected in the WASM exports section: canister_global_timer\n\

0 commit comments

Comments
 (0)