Skip to content

Commit 5f356ab

Browse files
committed
Use BTreeSet in AnalysisReport
1 parent ae737eb commit 5f356ab

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

packages/vm/src/cache.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use std::collections::{BTreeSet, HashSet};
22
use std::fs::{self, File, OpenOptions};
33
use std::io::{Read, Write};
44
use std::marker::PhantomData;
@@ -122,9 +122,9 @@ pub struct AnalysisReport {
122122
/// This does not guarantee they are functional or even have the correct signatures.
123123
pub has_ibc_entry_points: bool,
124124
/// A set of all entrypoints that are exported by the contract.
125-
pub entrypoints: HashSet<Entrypoint>,
125+
pub entrypoints: BTreeSet<Entrypoint>,
126126
/// The set of capabilities the contract requires.
127-
pub required_capabilities: HashSet<String>,
127+
pub required_capabilities: BTreeSet<String>,
128128
}
129129

130130
impl<A, S, Q> Cache<A, S, Q>
@@ -292,7 +292,9 @@ where
292292
.iter()
293293
.all(|required| exports.contains(required.as_ref())),
294294
entrypoints,
295-
required_capabilities: required_capabilities_from_module(&module),
295+
required_capabilities: required_capabilities_from_module(&module)
296+
.into_iter()
297+
.collect(),
296298
})
297299
}
298300

@@ -1307,28 +1309,28 @@ mod tests {
13071309
report1,
13081310
AnalysisReport {
13091311
has_ibc_entry_points: false,
1310-
entrypoints: HashSet::from([
1312+
entrypoints: BTreeSet::from([
13111313
E::Instantiate,
13121314
E::Migrate,
13131315
E::Sudo,
13141316
E::Execute,
13151317
E::Query
13161318
]),
1317-
required_capabilities: HashSet::new(),
1319+
required_capabilities: BTreeSet::new(),
13181320
}
13191321
);
13201322

13211323
let checksum2 = cache.save_wasm(IBC_CONTRACT).unwrap();
13221324
let report2 = cache.analyze(&checksum2).unwrap();
13231325
let mut ibc_contract_entrypoints =
1324-
HashSet::from([E::Instantiate, E::Migrate, E::Reply, E::Query]);
1326+
BTreeSet::from([E::Instantiate, E::Migrate, E::Reply, E::Query]);
13251327
ibc_contract_entrypoints.extend(REQUIRED_IBC_EXPORTS);
13261328
assert_eq!(
13271329
report2,
13281330
AnalysisReport {
13291331
has_ibc_entry_points: true,
13301332
entrypoints: ibc_contract_entrypoints,
1331-
required_capabilities: HashSet::from_iter([
1333+
required_capabilities: BTreeSet::from_iter([
13321334
"iterator".to_string(),
13331335
"stargate".to_string()
13341336
]),
@@ -1341,8 +1343,8 @@ mod tests {
13411343
report3,
13421344
AnalysisReport {
13431345
has_ibc_entry_points: false,
1344-
entrypoints: HashSet::new(),
1345-
required_capabilities: HashSet::from(["iterator".to_string()]),
1346+
entrypoints: BTreeSet::new(),
1347+
required_capabilities: BTreeSet::from(["iterator".to_string()]),
13461348
}
13471349
);
13481350
}

packages/vm/src/static_analysis.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ pub enum Entrypoint {
3535
IbcPacketTimeout,
3636
}
3737

38+
// sort entrypoints by their &str representation
39+
impl PartialOrd for Entrypoint {
40+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
41+
self.as_ref().partial_cmp(other.as_ref())
42+
}
43+
}
44+
impl Ord for Entrypoint {
45+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
46+
self.as_ref().cmp(other.as_ref())
47+
}
48+
}
49+
3850
pub const REQUIRED_IBC_EXPORTS: &[Entrypoint] = &[
3951
Entrypoint::IbcChannelOpen,
4052
Entrypoint::IbcChannelConnect,

0 commit comments

Comments
 (0)