Skip to content

Commit e5550ac

Browse files
committed
tests for CopyLoc and MoveLoc instructions
1 parent 11ad166 commit e5550ac

File tree

1 file changed

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

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,3 +995,36 @@ fn test_borrow_loc_reference() {
995995
}
996996
}
997997
}
998+
999+
1000+
#[test]
1001+
fn test_copy_loc_ok() {
1002+
let code = vec![Bytecode::CopyLoc(0)];
1003+
let module = make_module_with_local(code, SignatureToken::U64);
1004+
let fun_context = get_fun_context(&module);
1005+
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1006+
assert!(result.is_ok());
1007+
}
1008+
1009+
#[test]
1010+
fn test_copy_loc_no_copy() {
1011+
let code = vec![Bytecode::CopyLoc(0)];
1012+
let mut module = make_module_with_local(code, SignatureToken::Struct(StructHandleIndex(0)));
1013+
add_simple_struct_with_abilities(&mut module, AbilitySet::EMPTY);
1014+
let fun_context = get_fun_context(&module);
1015+
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1016+
assert_eq!(
1017+
result.unwrap_err().major_status(),
1018+
StatusCode::COPYLOC_WITHOUT_COPY_ABILITY
1019+
);
1020+
}
1021+
1022+
1023+
#[test]
1024+
fn test_move_loc_ok() {
1025+
let code = vec![Bytecode::MoveLoc(0)];
1026+
let module = make_module_with_local(code, SignatureToken::U64);
1027+
let fun_context = get_fun_context(&module);
1028+
let result = type_safety::verify(&module, &fun_context, &mut DummyMeter);
1029+
assert!(result.is_ok());
1030+
}

0 commit comments

Comments
 (0)