Skip to content

Commit

Permalink
Bring move-stdlib/src/natives/unit_test.rs on par with sui version
Browse files Browse the repository at this point in the history
  • Loading branch information
ksolana committed Mar 4, 2024
1 parent 5acd116 commit 02e63cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions language/move-stdlib/src/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ impl GasParameters {
base_cost: 0.into(),
unit_cost: 0.into(),
},
poison: unit_test::PoisonGasParameters {
base_cost: 0.into(),
},
},
}
}
Expand Down
37 changes: 33 additions & 4 deletions language/move-stdlib/src/natives/unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>,
args: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
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<NativeResult> {
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<Item = (String, NativeFunction)> {
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)
}

0 comments on commit 02e63cb

Please sign in to comment.