3030
3131use cosmwasm_std:: testing:: mock_env;
3232use cosmwasm_std:: {
33- coins, from_binary, log, AllBalanceResponse , Api , ApiError , BankMsg , CosmosMsg , HumanAddr ,
34- ReadonlyStorage ,
33+ coins, from_binary, log, AllBalanceResponse , Api , ApiError , BankMsg , HandleResponse , HumanAddr ,
34+ InitResponse , NoMsg , ReadonlyStorage ,
3535} ;
3636use cosmwasm_vm:: from_slice;
3737use cosmwasm_vm:: testing:: {
38- handle, init, mock_instance, mock_instance_with_balances, query, test_io,
38+ handle, init, mock_instance, mock_instance_with_balances, query, test_io, HandleResult ,
39+ InitResult ,
3940} ;
4041
4142use hackatom:: contract:: { HandleMsg , InitMsg , QueryMsg , State , CONFIG_KEY } ;
@@ -59,7 +60,7 @@ fn proper_initialization() {
5960 beneficiary,
6061 } ;
6162 let env = mock_env ( & deps. api , "creator" , & coins ( 1000 , "earth" ) ) ;
62- let res = init ( & mut deps, env, msg) . unwrap ( ) ;
63+ let res: InitResponse = init ( & mut deps, env, msg) . unwrap ( ) ;
6364 assert_eq ! ( 0 , res. messages. len( ) ) ;
6465
6566 // it worked, let's check the state
@@ -87,7 +88,7 @@ fn init_and_query() {
8788 beneficiary,
8889 } ;
8990 let env = mock_env ( & deps. api , creator. as_str ( ) , & coins ( 1000 , "earth" ) ) ;
90- let res = init ( & mut deps, env, msg) . unwrap ( ) ;
91+ let res: InitResponse = init ( & mut deps, env, msg) . unwrap ( ) ;
9192 assert_eq ! ( 0 , res. messages. len( ) ) ;
9293
9394 // now let's query
@@ -128,7 +129,7 @@ fn fails_on_bad_init() {
128129 let mut deps = mock_instance ( WASM , & [ ] ) ;
129130 let env = mock_env ( & deps. api , "creator" , & coins ( 1000 , "earth" ) ) ;
130131 // bad init returns parse error (pass wrong type - this connection is not enforced)
131- let res = init ( & mut deps, env, HandleMsg :: Release { } ) ;
132+ let res: InitResult = init ( & mut deps, env, HandleMsg :: Release { } ) ;
132133 match res. unwrap_err ( ) {
133134 ApiError :: ParseErr { .. } => { }
134135 _ => panic ! ( "Expected parse error" ) ,
@@ -148,21 +149,22 @@ fn proper_handle() {
148149 beneficiary : beneficiary. clone ( ) ,
149150 } ;
150151 let init_env = mock_env ( & deps. api , "creator" , & coins ( 1000 , "earth" ) ) ;
151- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
152+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
152153 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
153154
154155 // beneficiary can release it
155156 let handle_env = mock_env ( & deps. api , verifier. as_str ( ) , & coins ( 15 , "earth" ) ) ;
156- let handle_res = handle ( & mut deps, handle_env, HandleMsg :: Release { } ) . unwrap ( ) ;
157+ let handle_res: HandleResponse = handle ( & mut deps, handle_env, HandleMsg :: Release { } ) . unwrap ( ) ;
157158 assert_eq ! ( 1 , handle_res. messages. len( ) ) ;
158159 let msg = handle_res. messages . get ( 0 ) . expect ( "no message" ) ;
159160 assert_eq ! (
160161 msg,
161- & CosmosMsg :: Bank ( BankMsg :: Send {
162+ & BankMsg :: Send {
162163 from_address: HumanAddr ( "cosmos2contract" . to_string( ) ) ,
163164 to_address: beneficiary,
164165 amount: coins( 1015 , "earth" ) ,
165- } ) ,
166+ }
167+ . into( ) ,
166168 ) ;
167169 assert_eq ! (
168170 handle_res. log,
@@ -184,12 +186,12 @@ fn failed_handle() {
184186 beneficiary : beneficiary. clone ( ) ,
185187 } ;
186188 let init_env = mock_env ( & deps. api , creator. as_str ( ) , & coins ( 1000 , "earth" ) ) ;
187- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
189+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
188190 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
189191
190192 // beneficiary cannot release it
191193 let handle_env = mock_env ( & deps. api , beneficiary. as_str ( ) , & [ ] ) ;
192- let handle_res = handle ( & mut deps, handle_env, HandleMsg :: Release { } ) ;
194+ let handle_res: HandleResult = handle ( & mut deps, handle_env, HandleMsg :: Release { } ) ;
193195 match handle_res. unwrap_err ( ) {
194196 ApiError :: Unauthorized { } => { }
195197 _ => panic ! ( "Expect unauthorized error" ) ,
@@ -247,13 +249,13 @@ mod singlepass_tests {
247249
248250 let ( init_msg, creator) = make_init_msg ( ) ;
249251 let init_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
250- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
252+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
251253 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
252254
253255 let handle_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
254256 // panic inside contract should not panic out here
255257 // Note: we need to use the production-call, not the testing call (which unwraps any vm error)
256- let handle_res = call_handle (
258+ let handle_res = call_handle :: < _ , _ , _ , NoMsg > (
257259 & mut deps,
258260 & handle_env,
259261 & to_vec ( & HandleMsg :: Panic { } ) . unwrap ( ) ,
@@ -267,12 +269,12 @@ mod singlepass_tests {
267269
268270 let ( init_msg, creator) = make_init_msg ( ) ;
269271 let init_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
270- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
272+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
271273 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
272274
273275 let handle_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
274276 // Note: we need to use the production-call, not the testing call (which unwraps any vm error)
275- let handle_res = call_handle (
277+ let handle_res = call_handle :: < _ , _ , _ , NoMsg > (
276278 & mut deps,
277279 & handle_env,
278280 & to_vec ( & HandleMsg :: CpuLoop { } ) . unwrap ( ) ,
@@ -287,12 +289,12 @@ mod singlepass_tests {
287289
288290 let ( init_msg, creator) = make_init_msg ( ) ;
289291 let init_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
290- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
292+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
291293 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
292294
293295 let handle_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
294296 // Note: we need to use the production-call, not the testing call (which unwraps any vm error)
295- let handle_res = call_handle (
297+ let handle_res = call_handle :: < _ , _ , _ , NoMsg > (
296298 & mut deps,
297299 & handle_env,
298300 & to_vec ( & HandleMsg :: StorageLoop { } ) . unwrap ( ) ,
@@ -307,12 +309,12 @@ mod singlepass_tests {
307309
308310 let ( init_msg, creator) = make_init_msg ( ) ;
309311 let init_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
310- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
312+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
311313 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
312314
313315 let handle_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
314316 // Note: we need to use the production-call, not the testing call (which unwraps any vm error)
315- let handle_res = call_handle (
317+ let handle_res = call_handle :: < _ , _ , _ , NoMsg > (
316318 & mut deps,
317319 & handle_env,
318320 & to_vec ( & HandleMsg :: MemoryLoop { } ) . unwrap ( ) ,
@@ -330,13 +332,13 @@ mod singlepass_tests {
330332
331333 let ( init_msg, creator) = make_init_msg ( ) ;
332334 let init_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
333- let init_res = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
335+ let init_res: InitResponse = init ( & mut deps, init_env, init_msg) . unwrap ( ) ;
334336 assert_eq ! ( 0 , init_res. messages. len( ) ) ;
335337
336338 let handle_env = mock_env ( & deps. api , creator. as_str ( ) , & [ ] ) ;
337339 let gas_before = deps. get_gas ( ) ;
338340 // Note: we need to use the production-call, not the testing call (which unwraps any vm error)
339- let handle_res = call_handle (
341+ let handle_res = call_handle :: < _ , _ , _ , NoMsg > (
340342 & mut deps,
341343 & handle_env,
342344 & to_vec ( & HandleMsg :: AllocateLargeMemory { } ) . unwrap ( ) ,
@@ -349,8 +351,8 @@ mod singlepass_tests {
349351 // Gas consumtion is relatively small
350352 // Note: the exact gas usage depends on the Rust version used to compile WASM,
351353 // which we only fix when using cosmwasm-opt, not integration tests.
352- assert ! ( gas_used > 28000 ) ;
353- assert ! ( gas_used < 32000 ) ;
354+ assert ! ( gas_used > 26000 , "{}" , gas_used ) ;
355+ assert ! ( gas_used < 30000 , "{}" , gas_used ) ;
354356
355357 // Used between 100 and 102 MiB of memory
356358 assert ! ( deps. get_memory_size( ) > 100 * 1024 * 1024 ) ;
0 commit comments