@@ -29,9 +29,17 @@ pub fn instantiate(
29
29
. query_wasm_code_info ( msg. triplestore_config . code_id . u64 ( ) ) ?;
30
30
let salt = Binary :: from ( msg. name . as_bytes ( ) ) ;
31
31
32
- let triplestore_address = deps
33
- . api
34
- . addr_humanize ( & instantiate2_address ( & checksum, & creator, & salt) ?) ?;
32
+ /// Necessary stuff for testing purposes, see: https://github.com/CosmWasm/cosmwasm/issues/1648
33
+ #[ allow( unused) ]
34
+ let triplestore_address = instantiate2_address ( & checksum, & creator, & salt) ?;
35
+ let triplestore_address = {
36
+ #[ cfg( not( test) ) ]
37
+ {
38
+ deps. api . addr_humanize ( & triplestore_address) ?
39
+ }
40
+ #[ cfg( test) ]
41
+ cosmwasm_std:: Addr :: unchecked ( "predicted address" )
42
+ } ;
35
43
36
44
DATAVERSE . save (
37
45
deps. storage ,
@@ -75,4 +83,73 @@ pub fn query(_deps: Deps<'_>, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
75
83
pub mod query { }
76
84
77
85
#[ cfg( test) ]
78
- mod tests { }
86
+ mod tests {
87
+ use super :: * ;
88
+ use crate :: msg:: TripleStoreConfig ;
89
+ use cosmwasm_std:: testing:: { mock_dependencies, mock_env, mock_info} ;
90
+ use cosmwasm_std:: {
91
+ Attribute , ContractResult , HexBinary , SubMsg , SystemError , SystemResult , Uint128 , Uint64 ,
92
+ WasmQuery ,
93
+ } ;
94
+ use okp4_cognitarium:: msg:: StoreLimitsInputBuilder ;
95
+
96
+ #[ test]
97
+ fn proper_instantiate ( ) {
98
+ let mut deps = mock_dependencies ( ) ;
99
+ deps. querier . update_wasm ( |query| match query {
100
+ WasmQuery :: CodeInfo { code_id, .. } => {
101
+ let resp = CodeInfoResponse :: new (
102
+ code_id. clone ( ) ,
103
+ "creator" . to_string ( ) ,
104
+ HexBinary :: from_hex (
105
+ "3B94AAF0B7D804B5B458DED0D20CACF95D2A1C8DF78ED3C89B61291760454AEC" ,
106
+ )
107
+ . unwrap ( ) ,
108
+ ) ;
109
+ SystemResult :: Ok ( ContractResult :: Ok ( to_binary ( & resp) . unwrap ( ) ) )
110
+ }
111
+ _ => SystemResult :: Err ( SystemError :: Unknown { } ) ,
112
+ } ) ;
113
+
114
+ let store_limits = StoreLimitsInputBuilder :: default ( )
115
+ . max_byte_size ( Uint128 :: from ( 50000u128 ) )
116
+ . build ( )
117
+ . unwrap ( ) ;
118
+
119
+ let msg = InstantiateMsg {
120
+ name : "my-dataverse" . to_string ( ) ,
121
+ triplestore_config : TripleStoreConfig {
122
+ code_id : Uint64 :: from ( 17u64 ) ,
123
+ limits : store_limits. clone ( ) ,
124
+ } ,
125
+ } ;
126
+
127
+ let res = instantiate ( deps. as_mut ( ) , mock_env ( ) , mock_info ( "creator" , & [ ] ) , msg) . unwrap ( ) ;
128
+
129
+ assert_eq ! (
130
+ res. attributes,
131
+ vec![ Attribute :: new( "triplestore_address" , "predicted address" ) ]
132
+ ) ;
133
+ assert_eq ! (
134
+ res. messages,
135
+ vec![ SubMsg :: new( WasmMsg :: Instantiate2 {
136
+ admin: Some ( "cosmos2contract" . to_string( ) ) ,
137
+ code_id: 17 ,
138
+ label: "my-dataverse_triplestore" . to_string( ) ,
139
+ msg: to_binary( & okp4_cognitarium:: msg:: InstantiateMsg {
140
+ limits: store_limits,
141
+ } )
142
+ . unwrap( ) ,
143
+ funds: vec![ ] ,
144
+ salt: Binary :: from( "my-dataverse" . as_bytes( ) ) ,
145
+ } ) ]
146
+ ) ;
147
+ assert_eq ! (
148
+ DATAVERSE . load( & deps. storage) . unwrap( ) ,
149
+ Dataverse {
150
+ name: "my-dataverse" . to_string( ) ,
151
+ triplestore_address: "predicted address" . to_string( ) ,
152
+ }
153
+ )
154
+ }
155
+ }
0 commit comments