From 3d96a088a7888f2eb8f713d36eb92243cef8514e Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Fri, 12 Jan 2024 03:46:54 +0400 Subject: [PATCH] Fix the bug --- pallets/gear/src/runtime_api.rs | 23 ++++++++++++++--------- pallets/gear/src/tests.rs | 1 - 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pallets/gear/src/runtime_api.rs b/pallets/gear/src/runtime_api.rs index e9630b34191..3c72d7ad103 100644 --- a/pallets/gear/src/runtime_api.rs +++ b/pallets/gear/src/runtime_api.rs @@ -45,7 +45,7 @@ where #[allow(clippy::too_many_arguments)] pub(crate) fn calculate_gas_info_impl( - source: H256, + origin: H256, kind: HandleKind, initial_gas: u64, payload: Vec, @@ -56,16 +56,21 @@ where ) -> Result> { Self::enable_lazy_pages(); - let account = source.cast(); + let origin = origin.cast(); + let value = value.unique_saturated_into(); - let balance = CurrencyOf::::free_balance(&account); - let max_balance: BalanceOf = ::GasMultiplier::get() - .gas_to_value(initial_gas) - + value.unique_saturated_into(); - CurrencyOf::::deposit_creating(&account, max_balance.saturating_sub(balance)); + let origin_balance = CurrencyOf::::free_balance(&origin); - let who = frame_support::dispatch::RawOrigin::Signed(account); - let value: BalanceOf = value.unique_saturated_into(); + let value_for_gas = + ::GasMultiplier::get().gas_to_value(initial_gas); + + let required_balance = CurrencyOf::::minimum_balance() + .saturating_add(value_for_gas) + .saturating_add(value); + + CurrencyOf::::deposit_creating(&origin, required_balance.saturating_sub(origin_balance)); + + let who = frame_support::dispatch::RawOrigin::Signed(origin); QueueOf::::clear(); diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index faf795a83f0..f8330ea9224 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -86,7 +86,6 @@ use utils::*; type Gas = <::GasProvider as common::GasProvider>::GasTree; #[test] -#[should_panic] fn calculate_gas_zero_balance() { init_logger(); new_test_ext().execute_with(|| {