@@ -19,7 +19,9 @@ 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:: {
23
+ Entrypoint , ExportInfo , REQUIRED_IBC_EXPORTS , REQUIRED_IBC_V2_EXPORT ,
24
+ } ;
23
25
use crate :: wasm_backend:: { compile, make_compiling_engine} ;
24
26
25
27
const STATE_DIR : & str = "state" ;
@@ -100,6 +102,9 @@ pub struct AnalysisReport {
100
102
/// `true` if and only if all [`REQUIRED_IBC_EXPORTS`] exist as exported functions.
101
103
/// This does not guarantee they are functional or even have the correct signatures.
102
104
pub has_ibc_entry_points : bool ,
105
+ /// `true` if and only if all [`REQUIRED_IBC_V2_EXPORT`] exist as exported functions.
106
+ /// This does not guarantee they are functional or even have the correct signatures.
107
+ pub has_ibc_v2_entry_points : bool ,
103
108
/// A set of all entrypoints that are exported by the contract.
104
109
pub entrypoints : BTreeSet < Entrypoint > ,
105
110
/// The set of capabilities the contract requires.
@@ -337,6 +342,7 @@ where
337
342
has_ibc_entry_points : REQUIRED_IBC_EXPORTS
338
343
. iter ( )
339
344
. all ( |required| exports. contains ( required. as_ref ( ) ) ) ,
345
+ has_ibc_v2_entry_points : exports. contains ( REQUIRED_IBC_V2_EXPORT . as_ref ( ) ) ,
340
346
entrypoints,
341
347
required_capabilities : required_capabilities_from_module ( & module)
342
348
. into_iter ( )
@@ -624,6 +630,7 @@ mod tests {
624
630
625
631
static CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/hackatom.wasm" ) ;
626
632
static IBC_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/ibc_reflect.wasm" ) ;
633
+ static IBC_V2_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/ibcv2.wasm" ) ;
627
634
static EMPTY_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/empty.wasm" ) ;
628
635
// Invalid because it doesn't contain required memory and exports
629
636
static INVALID_CONTRACT_WAT : & str = r#"(module
@@ -658,6 +665,17 @@ mod tests {
658
665
}
659
666
}
660
667
668
+ fn make_ibc_v2_testing_options ( ) -> CacheOptions {
669
+ let mut capabilities = default_capabilities ( ) ;
670
+ capabilities. insert ( "ibcv2" . into ( ) ) ;
671
+ CacheOptions {
672
+ base_dir : TempDir :: new ( ) . unwrap ( ) . into_path ( ) ,
673
+ available_capabilities : capabilities,
674
+ memory_cache_size_bytes : TESTING_MEMORY_CACHE_SIZE ,
675
+ instance_memory_limit_bytes : TESTING_MEMORY_LIMIT ,
676
+ }
677
+ }
678
+
661
679
/// Takes an instance and executes it
662
680
fn test_hackatom_instance_execution < S , Q > ( instance : & mut Instance < MockApi , S , Q > )
663
681
where
@@ -1444,6 +1462,7 @@ mod tests {
1444
1462
report1,
1445
1463
AnalysisReport {
1446
1464
has_ibc_entry_points: false ,
1465
+ has_ibc_v2_entry_points: false ,
1447
1466
entrypoints: BTreeSet :: from( [
1448
1467
E :: Instantiate ,
1449
1468
E :: Migrate ,
@@ -1465,6 +1484,7 @@ mod tests {
1465
1484
report2,
1466
1485
AnalysisReport {
1467
1486
has_ibc_entry_points: true ,
1487
+ has_ibc_v2_entry_points: false ,
1468
1488
entrypoints: ibc_contract_entrypoints,
1469
1489
required_capabilities: BTreeSet :: from_iter( [
1470
1490
"iterator" . to_string( ) ,
@@ -1480,6 +1500,7 @@ mod tests {
1480
1500
report3,
1481
1501
AnalysisReport {
1482
1502
has_ibc_entry_points: false ,
1503
+ has_ibc_v2_entry_points: false ,
1483
1504
entrypoints: BTreeSet :: new( ) ,
1484
1505
required_capabilities: BTreeSet :: from( [ "iterator" . to_string( ) ] ) ,
1485
1506
contract_migrate_version: None ,
@@ -1499,11 +1520,32 @@ mod tests {
1499
1520
report4,
1500
1521
AnalysisReport {
1501
1522
has_ibc_entry_points: false ,
1523
+ has_ibc_v2_entry_points: false ,
1502
1524
entrypoints: BTreeSet :: new( ) ,
1503
1525
required_capabilities: BTreeSet :: from( [ "iterator" . to_string( ) ] ) ,
1504
1526
contract_migrate_version: Some ( 21 ) ,
1505
1527
}
1506
1528
) ;
1529
+
1530
+ let cache: Cache < MockApi , MockStorage , MockQuerier > =
1531
+ unsafe { Cache :: new ( make_ibc_v2_testing_options ( ) ) . unwrap ( ) } ;
1532
+ let checksum5 = cache. store_code ( IBC_V2_CONTRACT , true , true ) . unwrap ( ) ;
1533
+ let report5 = cache. analyze ( & checksum5) . unwrap ( ) ;
1534
+ let mut ibc_v2_contract_entrypoints = BTreeSet :: from ( [ E :: Instantiate , E :: Query ] ) ;
1535
+ ibc_v2_contract_entrypoints. extend ( [ REQUIRED_IBC_V2_EXPORT ] ) ;
1536
+ assert_eq ! (
1537
+ report5,
1538
+ AnalysisReport {
1539
+ has_ibc_entry_points: false ,
1540
+ has_ibc_v2_entry_points: true ,
1541
+ entrypoints: ibc_v2_contract_entrypoints,
1542
+ required_capabilities: BTreeSet :: from_iter( [
1543
+ "iterator" . to_string( ) ,
1544
+ "ibcv2" . to_string( )
1545
+ ] ) ,
1546
+ contract_migrate_version: None ,
1547
+ }
1548
+ ) ;
1507
1549
}
1508
1550
1509
1551
#[ test]
0 commit comments