Skip to content

Commit

Permalink
fix: changes for errors from merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Orris committed Dec 4, 2023
1 parent 50d5089 commit 568582b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pallets/capacity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use crate::Pallet as Capacity;

use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_support::assert_ok;
use frame_support::{assert_ok, BoundedVec};
use frame_system::RawOrigin;
use parity_scale_codec::alloc::vec::Vec;

Expand Down
10 changes: 4 additions & 6 deletions pallets/capacity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl<T: Config> Pallet<T> {
.active
.checked_add(&unlock_chunks_total::<T>(&unlocks))
.ok_or(ArithmeticError::Overflow)?;
T::Currency::set_freeze(&FreezeReason::Staked, staker, total_to_lock);
T::Currency::set_freeze(&FreezeReason::Staked.into(), staker, total_to_lock)?;
Self::set_staking_account(staker, staking_account);
Ok(())
}
Expand All @@ -522,8 +522,6 @@ impl<T: Config> Pallet<T> {
} else {
StakingAccountLedger::<T>::insert(staker, staking_account);
}

Ok(())
}

/// Sets target account details.
Expand Down Expand Up @@ -581,7 +579,7 @@ impl<T: Config> Pallet<T> {
staker: &T::AccountId,
proposed_amount: BalanceOf<T>,
) -> BalanceOf<T> {
let account_balance = T::Currency::free_balance(&staker);
let account_balance = T::Currency::balance(&staker);
account_balance
.saturating_sub(T::MinimumTokenBalance::get())
.min(proposed_amount)
Expand All @@ -608,9 +606,9 @@ impl<T: Config> Pallet<T> {
let staking_account = Self::get_staking_account_for(staker).unwrap_or_default();
let total_locked = staking_account.active.saturating_add(total_unlocking);
if total_locked.is_zero() {
T::Currency::remove_lock(STAKING_ID, &staker);
T::Currency::thaw(&FreezeReason::Staked.into(), staker)?;
} else {
T::Currency::set_lock(STAKING_ID, &staker, total_locked, WithdrawReasons::all());
T::Currency::set_freeze(&FreezeReason::Staked.into(), staker, total_locked)?;
}
Ok(amount_withdrawn)
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/capacity/src/tests/other_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use common_primitives::{capacity::Nontransferable, msa::MessageSourceId};

use crate::{
BalanceOf, CapacityDetails, Config, CurrentEpoch, CurrentEpochInfo, EpochInfo, FreezeReason,
StakingAccountDetails, StakingTargetDetails,
StakingDetails, StakingTargetDetails,
};

use super::{mock::*, testing_utils::*};
Expand Down
7 changes: 2 additions & 5 deletions pallets/capacity/src/tests/stake_and_deposit_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::{mock::*, testing_utils::*};
use crate::{
BalanceOf, CapacityDetails, Config, Error, Event, FreezeReason, StakingDetails,
};
use crate::{BalanceOf, CapacityDetails, Config, Error, Event, FreezeReason, StakingDetails};
use common_primitives::{capacity::Nontransferable, msa::MessageSourceId};
use frame_support::{assert_noop, assert_ok, traits::fungible::InspectFreeze};
use sp_runtime::ArithmeticError;
Expand Down Expand Up @@ -412,8 +410,7 @@ fn stake_when_there_are_unlocks_sets_lock_correctly() {
assert_ok!(Capacity::stake(RuntimeOrigin::signed(staker), target2, 20));

// should all still be locked.
assert_eq!(Balances::locks(&staker)[0].amount, 40);
assert_eq!(Balances::locks(&staker)[0].reasons, WithdrawReasons::all().into());
assert_eq!(Balances::balance_frozen(&FreezeReason::Staked.into(), &staker), 40);
})
}

Expand Down
12 changes: 8 additions & 4 deletions pallets/capacity/src/tests/unstaking_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use super::{mock::*, testing_utils::*};
use crate as pallet_capacity;
use crate::{CapacityDetails, StakingDetails, StakingTargetDetails, StakingType, UnlockChunk};
use crate::{
CapacityDetails, FreezeReason, StakingDetails, StakingTargetDetails, StakingType, UnlockChunk,
};
use common_primitives::msa::MessageSourceId;
use frame_support::{assert_noop, assert_ok, traits::Get};
use frame_support::{
assert_noop, assert_ok,
traits::{fungible::InspectFreeze, Get},
};
use pallet_capacity::{BalanceOf, Config, Error, Event};
use sp_core::bounded::BoundedVec;

Expand Down Expand Up @@ -174,8 +179,7 @@ fn unstaking_everything_reaps_staking_account() {
run_to_block(1);
// unstake everything
assert_ok!(Capacity::unstake(RuntimeOrigin::signed(staker), target, 20));
assert_eq!(1, Balances::locks(&staker).len());
assert_eq!(20u64, Balances::locks(&staker)[0].amount);
assert_eq!(20u64, Balances::balance_frozen(&FreezeReason::Staked.into(), &staker));

// it should reap the staking account right away
assert!(Capacity::get_staking_account_for(&staker).is_none());
Expand Down
15 changes: 6 additions & 9 deletions pallets/capacity/src/tests/withdraw_unstaked_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use super::{
testing_utils::{register_provider, run_to_block},
};
use crate::{
unlock_chunks_from_vec, CurrentEpoch, CurrentEpochInfo, EpochInfo, Error, Event, UnstakeUnlocks,
self as pallet_capacity, FreezeReason, StakingDetails,
self as pallet_capacity, unlock_chunks_from_vec, CurrentEpoch, CurrentEpochInfo, EpochInfo,
Error, Event, FreezeReason, UnstakeUnlocks,
};
use frame_support::{assert_noop, assert_ok, traits::fungible::InspectFreeze};
use pallet_capacity::{BalanceOf, Config, Error, Event};
use pallet_capacity::Config;

#[test]
fn withdraw_unstaked_happy_path() {
Expand Down Expand Up @@ -47,21 +47,18 @@ fn withdraw_unstaked_correctly_sets_new_lock_state() {

run_to_block(1);
assert_ok!(Capacity::unstake(RuntimeOrigin::signed(staker), target, 1));
assert_eq!(1, Balances::locks(&staker).len());
assert_eq!(20u64, Balances::locks(&staker)[0].amount);
assert_eq!(20, Balances::balance_frozen(&FreezeReason::Staked.into(), &staker));

// thaw period in mock is 2 Epochs * 10 blocks = 20 blocks.
run_to_block(21);
assert_ok!(Capacity::unstake(RuntimeOrigin::signed(staker), target, 2));
assert_ok!(Capacity::withdraw_unstaked(RuntimeOrigin::signed(staker)));
assert_eq!(1, Balances::locks(&staker).len());
assert_eq!(19u64, Balances::locks(&staker)[0].amount);
assert_eq!(19u64, Balances::balance_frozen(&FreezeReason::Staked.into(), &staker));

run_to_block(41);
assert_ok!(Capacity::unstake(RuntimeOrigin::signed(staker), target, 3));
assert_ok!(Capacity::withdraw_unstaked(RuntimeOrigin::signed(staker)));
assert_eq!(1, Balances::locks(&staker).len());
assert_eq!(17u64, Balances::locks(&staker)[0].amount);
assert_eq!(17u64, Balances::balance_frozen(&FreezeReason::Staked.into(), &staker));

run_to_block(61);
assert_ok!(Capacity::withdraw_unstaked(RuntimeOrigin::signed(staker)));
Expand Down

0 comments on commit 568582b

Please sign in to comment.