Skip to content

Commit

Permalink
Fix the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Jan 11, 2024
1 parent 3a45b23 commit 3d96a08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
23 changes: 14 additions & 9 deletions pallets/gear/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
Expand All @@ -56,16 +56,21 @@ where
) -> Result<GasInfo, Vec<u8>> {
Self::enable_lazy_pages();

let account = source.cast();
let origin = origin.cast();
let value = value.unique_saturated_into();

let balance = CurrencyOf::<T>::free_balance(&account);
let max_balance: BalanceOf<T> = <T as pallet_gear_bank::Config>::GasMultiplier::get()
.gas_to_value(initial_gas)
+ value.unique_saturated_into();
CurrencyOf::<T>::deposit_creating(&account, max_balance.saturating_sub(balance));
let origin_balance = CurrencyOf::<T>::free_balance(&origin);

let who = frame_support::dispatch::RawOrigin::Signed(account);
let value: BalanceOf<T> = value.unique_saturated_into();
let value_for_gas =
<T as pallet_gear_bank::Config>::GasMultiplier::get().gas_to_value(initial_gas);

let required_balance = CurrencyOf::<T>::minimum_balance()
.saturating_add(value_for_gas)
.saturating_add(value);

CurrencyOf::<T>::deposit_creating(&origin, required_balance.saturating_sub(origin_balance));

let who = frame_support::dispatch::RawOrigin::Signed(origin);

QueueOf::<T>::clear();

Expand Down
1 change: 0 additions & 1 deletion pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ use utils::*;
type Gas = <<Test as Config>::GasProvider as common::GasProvider>::GasTree;

#[test]
#[should_panic]
fn calculate_gas_zero_balance() {
init_logger();
new_test_ext().execute_with(|| {
Expand Down

0 comments on commit 3d96a08

Please sign in to comment.