@@ -327,31 +327,39 @@ async fn test_json_parsing(api_version: Version, gas_used: u64) {
327327 )
328328 . await ;
329329
330+ // Parse valid JSON and get it back
331+ let s = "\" foo\" " ; // Valid because there are quotes around `foo`
332+ let bytes: & [ u8 ] = s. as_ref ( ) ;
333+ let return_value: AscPtr < AscString > = module. invoke_export1 ( "handleJsonError" , bytes) ;
334+
335+ let output: String = module. asc_get ( return_value) . unwrap ( ) ;
336+ assert_eq ! ( output, "OK: foo, ERROR: false" ) ;
337+ assert_eq ! ( module. gas_used( ) , gas_used) ;
338+
330339 // Parse invalid JSON and handle the error gracefully
331340 let s = "foo" ; // Invalid because there are no quotes around `foo`
332341 let bytes: & [ u8 ] = s. as_ref ( ) ;
333342 let return_value: AscPtr < AscString > = module. invoke_export1 ( "handleJsonError" , bytes) ;
334343 let output: String = module. asc_get ( return_value) . unwrap ( ) ;
335344 assert_eq ! ( output, "ERROR: true" ) ;
336345
337- // Parse valid JSON and get it back
338- let s = "\" foo \" " ; // Valid because there are quotes around `foo`
346+ // Parse JSON that's too long and handle the error gracefully
347+ let s = format ! ( "\" f{} \" " , "o" . repeat ( 10_000_000 ) ) ;
339348 let bytes: & [ u8 ] = s. as_ref ( ) ;
340349 let return_value: AscPtr < AscString > = module. invoke_export1 ( "handleJsonError" , bytes) ;
341350
342351 let output: String = module. asc_get ( return_value) . unwrap ( ) ;
343- assert_eq ! ( output, "OK: foo, ERROR: false" ) ;
344- assert_eq ! ( module. gas_used( ) , gas_used) ;
352+ assert_eq ! ( output, "ERROR: true" ) ;
345353}
346354
347355#[ tokio:: test]
348356async fn json_parsing_v0_0_4 ( ) {
349- test_json_parsing ( API_VERSION_0_0_4 , 2722284 ) . await ;
357+ test_json_parsing ( API_VERSION_0_0_4 , 4373087 ) . await ;
350358}
351359
352360#[ tokio:: test]
353361async fn json_parsing_v0_0_5 ( ) {
354- test_json_parsing ( API_VERSION_0_0_5 , 3862933 ) . await ;
362+ test_json_parsing ( API_VERSION_0_0_5 , 5153540 ) . await ;
355363}
356364
357365async fn test_ipfs_cat ( api_version : Version ) {
0 commit comments