Skip to content

Commit e50d39d

Browse files
authored
Merge pull request #2402 from CosmWasm/jawoznia/feat/ibcv2_analysis_report
Add info about ibc_v2 entrypoint to AnalysisReport (#2401)
2 parents e240f16 + 8d12645 commit e50d39d

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
- run:
172172
name: "contracts/ibc2: integration-test"
173173
working_directory: ~/project/contracts/ibc2
174-
command: cargo wasm --locked
174+
command: cargo wasm --locked && cargo integration-test --locked
175175
- run:
176176
name: "contracts/queue: integration-test"
177177
working_directory: ~/project/contracts/queue

packages/vm/src/cache.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::instance::{Instance, InstanceOptions};
1919
use crate::modules::{CachedModule, FileSystemCache, InMemoryCache, PinnedMemoryCache};
2020
use crate::parsed_wasm::ParsedWasm;
2121
use crate::size::Size;
22-
use crate::static_analysis::{Entrypoint, ExportInfo, REQUIRED_IBC_EXPORTS};
22+
use crate::static_analysis::{Entrypoint, ExportInfo, REQUIRED_IBC2_EXPORT, REQUIRED_IBC_EXPORTS};
2323
use crate::wasm_backend::{compile, make_compiling_engine};
2424

2525
const STATE_DIR: &str = "state";
@@ -100,6 +100,9 @@ pub struct AnalysisReport {
100100
/// `true` if and only if all [`REQUIRED_IBC_EXPORTS`] exist as exported functions.
101101
/// This does not guarantee they are functional or even have the correct signatures.
102102
pub has_ibc_entry_points: bool,
103+
/// `true` if and only if all [`REQUIRED_IBC2_EXPORT`] exist as exported functions.
104+
/// This does not guarantee they are functional or even have the correct signatures.
105+
pub has_ibc2_entry_points: bool,
103106
/// A set of all entrypoints that are exported by the contract.
104107
pub entrypoints: BTreeSet<Entrypoint>,
105108
/// The set of capabilities the contract requires.
@@ -337,6 +340,7 @@ where
337340
has_ibc_entry_points: REQUIRED_IBC_EXPORTS
338341
.iter()
339342
.all(|required| exports.contains(required.as_ref())),
343+
has_ibc2_entry_points: exports.contains(REQUIRED_IBC2_EXPORT.as_ref()),
340344
entrypoints,
341345
required_capabilities: required_capabilities_from_module(&module)
342346
.into_iter()
@@ -624,6 +628,7 @@ mod tests {
624628

625629
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
626630
static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
631+
static IBC2_CONTRACT: &[u8] = include_bytes!("../testdata/ibc2.wasm");
627632
static EMPTY_CONTRACT: &[u8] = include_bytes!("../testdata/empty.wasm");
628633
// Invalid because it doesn't contain required memory and exports
629634
static INVALID_CONTRACT_WAT: &str = r#"(module
@@ -658,6 +663,17 @@ mod tests {
658663
}
659664
}
660665

666+
fn make_ibc2_testing_options() -> CacheOptions {
667+
let mut capabilities = default_capabilities();
668+
capabilities.insert("ibc2".into());
669+
CacheOptions {
670+
base_dir: TempDir::new().unwrap().into_path(),
671+
available_capabilities: capabilities,
672+
memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE,
673+
instance_memory_limit_bytes: TESTING_MEMORY_LIMIT,
674+
}
675+
}
676+
661677
/// Takes an instance and executes it
662678
fn test_hackatom_instance_execution<S, Q>(instance: &mut Instance<MockApi, S, Q>)
663679
where
@@ -1444,6 +1460,7 @@ mod tests {
14441460
report1,
14451461
AnalysisReport {
14461462
has_ibc_entry_points: false,
1463+
has_ibc2_entry_points: false,
14471464
entrypoints: BTreeSet::from([
14481465
E::Instantiate,
14491466
E::Migrate,
@@ -1465,6 +1482,7 @@ mod tests {
14651482
report2,
14661483
AnalysisReport {
14671484
has_ibc_entry_points: true,
1485+
has_ibc2_entry_points: false,
14681486
entrypoints: ibc_contract_entrypoints,
14691487
required_capabilities: BTreeSet::from_iter([
14701488
"iterator".to_string(),
@@ -1480,6 +1498,7 @@ mod tests {
14801498
report3,
14811499
AnalysisReport {
14821500
has_ibc_entry_points: false,
1501+
has_ibc2_entry_points: false,
14831502
entrypoints: BTreeSet::new(),
14841503
required_capabilities: BTreeSet::from(["iterator".to_string()]),
14851504
contract_migrate_version: None,
@@ -1499,11 +1518,32 @@ mod tests {
14991518
report4,
15001519
AnalysisReport {
15011520
has_ibc_entry_points: false,
1521+
has_ibc2_entry_points: false,
15021522
entrypoints: BTreeSet::new(),
15031523
required_capabilities: BTreeSet::from(["iterator".to_string()]),
15041524
contract_migrate_version: Some(21),
15051525
}
15061526
);
1527+
1528+
let cache: Cache<MockApi, MockStorage, MockQuerier> =
1529+
unsafe { Cache::new(make_ibc2_testing_options()).unwrap() };
1530+
let checksum5 = cache.store_code(IBC2_CONTRACT, true, true).unwrap();
1531+
let report5 = cache.analyze(&checksum5).unwrap();
1532+
let mut ibc2_contract_entrypoints = BTreeSet::from([E::Instantiate, E::Query]);
1533+
ibc2_contract_entrypoints.extend([REQUIRED_IBC2_EXPORT]);
1534+
assert_eq!(
1535+
report5,
1536+
AnalysisReport {
1537+
has_ibc_entry_points: false,
1538+
has_ibc2_entry_points: true,
1539+
entrypoints: ibc2_contract_entrypoints,
1540+
required_capabilities: BTreeSet::from_iter([
1541+
"iterator".to_string(),
1542+
"ibc2".to_string()
1543+
]),
1544+
contract_migrate_version: None,
1545+
}
1546+
);
15071547
}
15081548

15091549
#[test]

packages/vm/src/static_analysis.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub const REQUIRED_IBC_EXPORTS: &[Entrypoint] = &[
5858
Entrypoint::IbcPacketTimeout,
5959
];
6060

61+
pub const REQUIRED_IBC2_EXPORT: &Entrypoint = &Entrypoint::Ibc2PacketReceive;
62+
6163
/// A trait that allows accessing shared functionality of `parity_wasm::elements::Module`
6264
/// and `wasmer::Module` in a shared fashion.
6365
pub trait ExportInfo {

0 commit comments

Comments
 (0)