@@ -331,6 +331,69 @@ mod tests {
331331 }
332332 }
333333
334+ #[ test]
335+ fn wasm_msg_serializes_to_correct_json ( ) {
336+ // Instantiate with admin
337+ let msg = WasmMsg :: Instantiate {
338+ admin : Some ( "king" . to_string ( ) ) ,
339+ code_id : 7897 ,
340+ msg : br#"{"claim":{}}"# . into ( ) ,
341+ funds : vec ! [ ] ,
342+ label : "my instance" . to_string ( ) ,
343+ } ;
344+ let json = to_binary ( & msg) . unwrap ( ) ;
345+ assert_eq ! (
346+ String :: from_utf8_lossy( & json) ,
347+ r#"{"instantiate":{"admin":"king","code_id":7897,"msg":"eyJjbGFpbSI6e319","funds":[],"label":"my instance"}}"# ,
348+ ) ;
349+
350+ // Instantiate without admin
351+ let msg = WasmMsg :: Instantiate {
352+ admin : None ,
353+ code_id : 7897 ,
354+ msg : br#"{"claim":{}}"# . into ( ) ,
355+ funds : vec ! [ ] ,
356+ label : "my instance" . to_string ( ) ,
357+ } ;
358+ let json = to_binary ( & msg) . unwrap ( ) ;
359+ assert_eq ! (
360+ String :: from_utf8_lossy( & json) ,
361+ r#"{"instantiate":{"admin":null,"code_id":7897,"msg":"eyJjbGFpbSI6e319","funds":[],"label":"my instance"}}"# ,
362+ ) ;
363+
364+ // Instantiate with funds
365+ let msg = WasmMsg :: Instantiate {
366+ admin : None ,
367+ code_id : 7897 ,
368+ msg : br#"{"claim":{}}"# . into ( ) ,
369+ funds : vec ! [ coin( 321 , "stones" ) ] ,
370+ label : "my instance" . to_string ( ) ,
371+ } ;
372+ let json = to_binary ( & msg) . unwrap ( ) ;
373+ assert_eq ! (
374+ String :: from_utf8_lossy( & json) ,
375+ r#"{"instantiate":{"admin":null,"code_id":7897,"msg":"eyJjbGFpbSI6e319","funds":[{"denom":"stones","amount":"321"}],"label":"my instance"}}"# ,
376+ ) ;
377+
378+ // Instantiate2
379+ #[ cfg( feature = "cosmwasm_1_2" ) ]
380+ {
381+ let msg = WasmMsg :: Instantiate2 {
382+ admin : None ,
383+ code_id : 7897 ,
384+ label : "my instance" . to_string ( ) ,
385+ msg : br#"{"claim":{}}"# . into ( ) ,
386+ funds : vec ! [ coin( 321 , "stones" ) ] ,
387+ salt : Binary :: from_base64 ( "UkOVazhiwoo=" ) . unwrap ( ) ,
388+ } ;
389+ let json = to_binary ( & msg) . unwrap ( ) ;
390+ assert_eq ! (
391+ String :: from_utf8_lossy( & json) ,
392+ r#"{"instantiate2":{"admin":null,"code_id":7897,"label":"my instance","msg":"eyJjbGFpbSI6e319","funds":[{"denom":"stones","amount":"321"}],"salt":"UkOVazhiwoo="}}"# ,
393+ ) ;
394+ }
395+ }
396+
334397 #[ test]
335398 fn wasm_msg_debug_decodes_binary_string_when_possible ( ) {
336399 #[ cosmwasm_schema:: cw_serde]
0 commit comments