@@ -294,3 +294,80 @@ fn test_arithmetic_too_few_args() {
294
294
let _result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
295
295
}
296
296
}
297
+
298
+
299
+ #[ test]
300
+ fn test_shl_shr_correct_types ( ) {
301
+ for instr in vec ! [
302
+ Bytecode :: Shl ,
303
+ Bytecode :: Shr ,
304
+ ] {
305
+ for push_ty_instr in vec ! [
306
+ Bytecode :: LdU8 ( 42 ) ,
307
+ Bytecode :: LdU16 ( 257 ) ,
308
+ Bytecode :: LdU32 ( 89 ) ,
309
+ Bytecode :: LdU64 ( 94 ) ,
310
+ Bytecode :: LdU128 ( Box :: new( 9999 ) ) ,
311
+ Bytecode :: LdU256 ( Box :: new( U256 :: from( 745_u32 ) ) ) ,
312
+ ] {
313
+ let code = vec ! [ push_ty_instr. clone( ) , Bytecode :: LdU8 ( 2 ) , instr. clone( ) ] ;
314
+ let module = make_module ( code) ;
315
+ let fun_context = get_fun_context ( & module) ;
316
+ let result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
317
+ assert ! ( result. is_ok( ) ) ;
318
+ }
319
+ }
320
+ }
321
+
322
+ #[ test]
323
+ fn test_shl_shr_first_operand_wrong_type ( ) {
324
+ for instr in vec ! [
325
+ Bytecode :: Shl ,
326
+ Bytecode :: Shr ,
327
+ ] {
328
+ let code = vec ! [ Bytecode :: LdTrue , Bytecode :: LdU8 ( 2 ) , instr. clone( ) ] ;
329
+ let module = make_module ( code) ;
330
+ let fun_context = get_fun_context ( & module) ;
331
+ let result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
332
+ assert_eq ! (
333
+ result. unwrap_err( ) . major_status( ) ,
334
+ StatusCode :: INTEGER_OP_TYPE_MISMATCH_ERROR
335
+ ) ;
336
+ }
337
+ }
338
+
339
+ #[ test]
340
+ fn test_shl_shr_second_operand_wrong_type ( ) {
341
+ for instr in vec ! [
342
+ Bytecode :: Shl ,
343
+ Bytecode :: Shr ,
344
+ ] {
345
+ let code = vec ! [ Bytecode :: LdU32 ( 42 ) , Bytecode :: LdU16 ( 2 ) , instr. clone( ) ] ;
346
+ let module = make_module ( code) ;
347
+ let fun_context = get_fun_context ( & module) ;
348
+ let result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
349
+ assert_eq ! (
350
+ result. unwrap_err( ) . major_status( ) ,
351
+ StatusCode :: INTEGER_OP_TYPE_MISMATCH_ERROR
352
+ ) ;
353
+ }
354
+ }
355
+
356
+ #[ test]
357
+ #[ should_panic]
358
+ fn test_shl_shr_too_few_args ( ) {
359
+ for instr in vec ! [
360
+ Bytecode :: Shl ,
361
+ Bytecode :: Shr ,
362
+ ] {
363
+ let code = vec ! [ Bytecode :: LdU16 ( 42 ) , instr. clone( ) ] ;
364
+ let module = make_module ( code) ;
365
+ let fun_context = get_fun_context ( & module) ;
366
+ let _result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
367
+
368
+ let code = vec ! [ instr. clone( ) ] ;
369
+ let module = make_module ( code) ;
370
+ let fun_context = get_fun_context ( & module) ;
371
+ let _result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
372
+ }
373
+ }
0 commit comments