From 02e63cb98686f0ec53cf172285abfca15f7b828f Mon Sep 17 00:00:00 2001 From: ksolana <110843012+ksolana@users.noreply.github.com> Date: Mon, 4 Mar 2024 06:49:19 -0800 Subject: [PATCH] Bring move-stdlib/src/natives/unit_test.rs on par with sui version Partially fixes #411 Diff between: https://github.com/MystenLabs/sui/blob/main/external-crates/move/crates/move-stdlib/src/natives/unit_test.rs https://github.com/anza-xyz/move/blob/llvm-sys/language/move-stdlib/src/natives/unit_test.rs --- language/move-stdlib/src/natives/mod.rs | 3 ++ language/move-stdlib/src/natives/unit_test.rs | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/language/move-stdlib/src/natives/mod.rs b/language/move-stdlib/src/natives/mod.rs index fe97636884..7a6c8af348 100644 --- a/language/move-stdlib/src/natives/mod.rs +++ b/language/move-stdlib/src/natives/mod.rs @@ -97,6 +97,9 @@ impl GasParameters { base_cost: 0.into(), unit_cost: 0.into(), }, + poison: unit_test::PoisonGasParameters { + base_cost: 0.into(), + }, }, } } diff --git a/language/move-stdlib/src/natives/unit_test.rs b/language/move-stdlib/src/natives/unit_test.rs index 31fe78d549..6f1c8838b9 100644 --- a/language/move-stdlib/src/natives/unit_test.rs +++ b/language/move-stdlib/src/natives/unit_test.rs @@ -63,19 +63,48 @@ pub fn make_native_create_signers_for_testing( ) } +#[derive(Debug, Clone)] +pub struct PoisonGasParameters { + pub base_cost: InternalGas, +} + +fn native_poison( + gas_params: &PoisonGasParameters, + _context: &mut NativeContext, + ty_args: Vec, + args: VecDeque, +) -> PartialVMResult { + debug_assert!(ty_args.is_empty()); + debug_assert!(args.is_empty()); + let cost = gas_params.base_cost; + Ok(NativeResult::ok(cost, smallvec![])) +} + +pub fn make_native_poison(gas_params: PoisonGasParameters) -> NativeFunction { + Arc::new( + move |context, ty_args, args| -> PartialVMResult { + native_poison(&gas_params, context, ty_args, args) + }, + ) +} + /*************************************************************************************************** * module **************************************************************************************************/ #[derive(Debug, Clone)] pub struct GasParameters { pub create_signers_for_testing: CreateSignersForTestingGasParameters, + pub poison: PoisonGasParameters, } pub fn make_all(gas_params: GasParameters) -> impl Iterator { - let natives = [( - "create_signers_for_testing", - make_native_create_signers_for_testing(gas_params.create_signers_for_testing), - )]; + let natives = [ + ( + "create_signers_for_testing", + make_native_create_signers_for_testing(gas_params.create_signers_for_testing), + ), + ("poison", make_native_poison(gas_params.poison)), + ]; make_module_natives(natives) }