sui_move_natives_v2/
test_utils.rs1use crate::{legacy_test_cost, types::is_otw_struct};
5use move_binary_format::errors::PartialVMResult;
6use move_core_types::{gas_algebra::InternalGas, runtime_value::MoveTypeLayout};
7use move_vm_runtime::native_functions::NativeContext;
8use move_vm_types::{
9 loaded_data::runtime_types::Type, natives::function::NativeResult, values::Value,
10};
11use smallvec::smallvec;
12use std::collections::VecDeque;
13
14pub fn destroy(
15 _context: &mut NativeContext,
16 _ty_args: Vec<Type>,
17 mut args: VecDeque<Value>,
18) -> PartialVMResult<NativeResult> {
19 args.pop_back();
20 Ok(NativeResult::ok(legacy_test_cost(), smallvec![]))
21}
22
23pub fn create_one_time_witness(
24 context: &mut NativeContext,
25 mut ty_args: Vec<Type>,
26 args: VecDeque<Value>,
27) -> PartialVMResult<NativeResult> {
28 debug_assert!(ty_args.len() == 1);
29 debug_assert!(args.is_empty());
30
31 let ty = ty_args.pop().unwrap();
32 let type_tag = context.type_to_type_tag(&ty)?;
33 let type_layout = context.type_to_type_layout(&ty)?;
34
35 let Some(MoveTypeLayout::Struct(struct_layout)) = type_layout else {
36 return Ok(NativeResult::err(InternalGas::new(1), 0));
37 };
38
39 let hardened_check = context.runtime_limits_config().hardened_otw_check;
40 if is_otw_struct(&struct_layout, &type_tag, hardened_check) {
41 Ok(NativeResult::ok(
42 legacy_test_cost(),
43 smallvec![Value::struct_(move_vm_types::values::Struct::pack(vec![
44 Value::bool(true)
45 ]))],
46 ))
47 } else {
48 Ok(NativeResult::err(InternalGas::new(1), 1))
49 }
50}