Skip to content

Commit ca491ed

Browse files
committed
tests for FreezeRef operation
1 parent e5550ac commit ca491ed

File tree

1 file changed

+40
-0
lines changed
  • crates/move-bytecode-verifier/src/type_safety_tests

1 file changed

+40
-0
lines changed

crates/move-bytecode-verifier/src/type_safety_tests/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,43 @@ fn test_move_loc_ok() {
10281028
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
10291029
assert!(result.is_ok());
10301030
}
1031+
1032+
1033+
#[test]
1034+
fn test_freeze_ref_correct_type() {
1035+
let code = vec![Bytecode::MutBorrowLoc(0), Bytecode::FreezeRef];
1036+
let module = make_module_with_local(code, SignatureToken::U64);
1037+
let fun_context = get_fun_context(&module);
1038+
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1039+
assert!(result.is_ok());
1040+
}
1041+
1042+
#[test]
1043+
fn test_freeze_ref_wrong_type() {
1044+
let code = vec![Bytecode::ImmBorrowLoc(0), Bytecode::FreezeRef];
1045+
let module = make_module_with_local(code, SignatureToken::U64);
1046+
let fun_context = get_fun_context(&module);
1047+
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1048+
assert_eq!(
1049+
result.unwrap_err().major_status(),
1050+
StatusCode::FREEZEREF_TYPE_MISMATCH_ERROR
1051+
);
1052+
1053+
let code = vec![Bytecode::LdTrue, Bytecode::FreezeRef];
1054+
let module = make_module_with_local(code, SignatureToken::U64);
1055+
let fun_context = get_fun_context(&module);
1056+
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1057+
assert_eq!(
1058+
result.unwrap_err().major_status(),
1059+
StatusCode::FREEZEREF_TYPE_MISMATCH_ERROR
1060+
);
1061+
}
1062+
1063+
#[test]
1064+
#[should_panic]
1065+
fn test_freeze_ref_no_arg() {
1066+
let code = vec![Bytecode::FreezeRef];
1067+
let module = make_module_with_local(code, SignatureToken::U64);
1068+
let fun_context = get_fun_context(&module);
1069+
let _result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1070+
}

0 commit comments

Comments
 (0)