Skip to content

Commit 2b0fa2f

Browse files
committed
Use Entrypoint type for ibc entrypoints
1 parent 486ee78 commit 2b0fa2f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

packages/vm/src/cache.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ where
290290
Ok(AnalysisReport {
291291
has_ibc_entry_points: REQUIRED_IBC_EXPORTS
292292
.iter()
293-
.all(|required| exports.contains(*required)),
293+
.all(|required| exports.contains(<&str>::from(required))),
294294
entrypoints,
295295
required_capabilities: required_capabilities_from_module(&module),
296296
})
@@ -1320,11 +1320,14 @@ mod tests {
13201320

13211321
let checksum2 = cache.save_wasm(IBC_CONTRACT).unwrap();
13221322
let report2 = cache.analyze(&checksum2).unwrap();
1323+
let mut ibc_contract_entrypoints =
1324+
HashSet::from([E::Instantiate, E::Migrate, E::Reply, E::Query]);
1325+
ibc_contract_entrypoints.extend(REQUIRED_IBC_EXPORTS);
13231326
assert_eq!(
13241327
report2,
13251328
AnalysisReport {
13261329
has_ibc_entry_points: true,
1327-
entrypoints: HashSet::from([E::Instantiate, E::Reply, E::Query]),
1330+
entrypoints: ibc_contract_entrypoints,
13281331
required_capabilities: HashSet::from_iter([
13291332
"iterator".to_string(),
13301333
"stargate".to_string()

packages/vm/src/static_analysis.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::collections::HashSet;
22

3-
use strum::{Display, EnumString};
3+
use strum::{Display, EnumString, IntoStaticStr};
44
use wasmer::wasmparser::ExternalKind;
55

66
use crate::parsed_wasm::ParsedWasm;
77

88
/// An enum containing all available contract entrypoints.
99
/// This also provides conversions to and from strings.
10-
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, EnumString, Display)]
10+
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, EnumString, Display, IntoStaticStr)]
1111
pub enum Entrypoint {
1212
#[strum(serialize = "instantiate")]
1313
Instantiate,
@@ -35,13 +35,13 @@ pub enum Entrypoint {
3535
IbcPacketTimeout,
3636
}
3737

38-
pub const REQUIRED_IBC_EXPORTS: &[&str] = &[
39-
"ibc_channel_open",
40-
"ibc_channel_connect",
41-
"ibc_channel_close",
42-
"ibc_packet_receive",
43-
"ibc_packet_ack",
44-
"ibc_packet_timeout",
38+
pub const REQUIRED_IBC_EXPORTS: &[Entrypoint] = &[
39+
Entrypoint::IbcChannelOpen,
40+
Entrypoint::IbcChannelConnect,
41+
Entrypoint::IbcChannelClose,
42+
Entrypoint::IbcPacketReceive,
43+
Entrypoint::IbcPacketAck,
44+
Entrypoint::IbcPacketTimeout,
4545
];
4646

4747
/// A trait that allows accessing shared functionality of `parity_wasm::elements::Module`
@@ -260,10 +260,15 @@ mod tests {
260260
}
261261

262262
#[test]
263-
fn entrypoint_display_works() {
263+
fn entrypoint_to_string_works() {
264264
assert_eq!(
265265
Entrypoint::IbcPacketTimeout.to_string(),
266266
"ibc_packet_timeout".to_string()
267267
);
268+
269+
assert_eq!(
270+
<&'static str>::from(Entrypoint::IbcPacketReceive),
271+
"ibc_packet_receive"
272+
);
268273
}
269274
}

0 commit comments

Comments
 (0)