@@ -19,7 +19,7 @@ use crate::instance::{Instance, InstanceOptions};
19
19
use crate :: modules:: { CachedModule , FileSystemCache , InMemoryCache , PinnedMemoryCache } ;
20
20
use crate :: parsed_wasm:: ParsedWasm ;
21
21
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 } ;
23
23
use crate :: wasm_backend:: { compile, make_compiling_engine} ;
24
24
25
25
const STATE_DIR : & str = "state" ;
@@ -100,6 +100,9 @@ pub struct AnalysisReport {
100
100
/// `true` if and only if all [`REQUIRED_IBC_EXPORTS`] exist as exported functions.
101
101
/// This does not guarantee they are functional or even have the correct signatures.
102
102
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 ,
103
106
/// A set of all entrypoints that are exported by the contract.
104
107
pub entrypoints : BTreeSet < Entrypoint > ,
105
108
/// The set of capabilities the contract requires.
@@ -337,6 +340,7 @@ where
337
340
has_ibc_entry_points : REQUIRED_IBC_EXPORTS
338
341
. iter ( )
339
342
. all ( |required| exports. contains ( required. as_ref ( ) ) ) ,
343
+ has_ibc2_entry_points : exports. contains ( REQUIRED_IBC2_EXPORT . as_ref ( ) ) ,
340
344
entrypoints,
341
345
required_capabilities : required_capabilities_from_module ( & module)
342
346
. into_iter ( )
@@ -624,6 +628,7 @@ mod tests {
624
628
625
629
static CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/hackatom.wasm" ) ;
626
630
static IBC_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/ibc_reflect.wasm" ) ;
631
+ static IBC2_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/ibc2.wasm" ) ;
627
632
static EMPTY_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/empty.wasm" ) ;
628
633
// Invalid because it doesn't contain required memory and exports
629
634
static INVALID_CONTRACT_WAT : & str = r#"(module
@@ -658,6 +663,17 @@ mod tests {
658
663
}
659
664
}
660
665
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
+
661
677
/// Takes an instance and executes it
662
678
fn test_hackatom_instance_execution < S , Q > ( instance : & mut Instance < MockApi , S , Q > )
663
679
where
@@ -1444,6 +1460,7 @@ mod tests {
1444
1460
report1,
1445
1461
AnalysisReport {
1446
1462
has_ibc_entry_points: false ,
1463
+ has_ibc2_entry_points: false ,
1447
1464
entrypoints: BTreeSet :: from( [
1448
1465
E :: Instantiate ,
1449
1466
E :: Migrate ,
@@ -1465,6 +1482,7 @@ mod tests {
1465
1482
report2,
1466
1483
AnalysisReport {
1467
1484
has_ibc_entry_points: true ,
1485
+ has_ibc2_entry_points: false ,
1468
1486
entrypoints: ibc_contract_entrypoints,
1469
1487
required_capabilities: BTreeSet :: from_iter( [
1470
1488
"iterator" . to_string( ) ,
@@ -1480,6 +1498,7 @@ mod tests {
1480
1498
report3,
1481
1499
AnalysisReport {
1482
1500
has_ibc_entry_points: false ,
1501
+ has_ibc2_entry_points: false ,
1483
1502
entrypoints: BTreeSet :: new( ) ,
1484
1503
required_capabilities: BTreeSet :: from( [ "iterator" . to_string( ) ] ) ,
1485
1504
contract_migrate_version: None ,
@@ -1499,11 +1518,32 @@ mod tests {
1499
1518
report4,
1500
1519
AnalysisReport {
1501
1520
has_ibc_entry_points: false ,
1521
+ has_ibc2_entry_points: false ,
1502
1522
entrypoints: BTreeSet :: new( ) ,
1503
1523
required_capabilities: BTreeSet :: from( [ "iterator" . to_string( ) ] ) ,
1504
1524
contract_migrate_version: Some ( 21 ) ,
1505
1525
}
1506
1526
) ;
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
+ ) ;
1507
1547
}
1508
1548
1509
1549
#[ test]
0 commit comments