Skip to content

Commit 51a93ec

Browse files
committed
feat: solving staking bug
1 parent 818d940 commit 51a93ec

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

pallets/torus0/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ pub mod pallet {
229229
amount: BalanceOf<T>,
230230
) -> DispatchResult {
231231
let key = ensure_signed(origin)?;
232+
ensure!(
233+
amount >= crate::MinAllowedStake::<T>::get(),
234+
crate::Error::<T>::StakeTooSmall
235+
);
232236
stake::add_stake::<T>(key, agent_key, amount)
233237
}
234238

pallets/torus0/src/stake.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ pub fn add_stake<T: crate::Config>(
1111
staked: AccountIdOf<T>,
1212
amount: BalanceOf<T>,
1313
) -> DispatchResult {
14-
ensure!(
15-
amount >= crate::MinAllowedStake::<T>::get(),
16-
crate::Error::<T>::StakeTooSmall
17-
);
18-
1914
ensure!(
2015
agent::exists::<T>(&staked),
2116
crate::Error::<T>::AgentDoesNotExist
@@ -76,6 +71,8 @@ pub fn remove_stake<T: crate::Config>(
7671

7772
let _ = <T as crate::Config>::Currency::deposit_creating(&key, amount);
7873

74+
crate::Pallet::<T>::deposit_event(crate::Event::<T>::StakeRemoved(key, agent_key, amount));
75+
7976
Ok(())
8077
}
8178

pallets/torus0/tests/stake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pallet_torus0::{Error, MinAllowedStake, StakedBy, StakingTo, TotalStake};
22
use polkadot_sdk::frame_support::{assert_err, traits::Currency};
3-
use test_utils::{assert_ok, pallet_governance, Balances, Test};
3+
use test_utils::{assert_ok, get_origin, pallet_governance, Balances, Test};
44

55
#[test]
66
fn add_stake_correctly() {
@@ -78,7 +78,7 @@ fn add_stake_without_the_minimum_stake() {
7878
assert_eq!(Balances::total_balance(&to), 0);
7979

8080
assert_err!(
81-
pallet_torus0::stake::add_stake::<Test>(from, to, stake_to_add - 1),
81+
pallet_torus0::Pallet::<Test>::add_stake(get_origin(from), to, stake_to_add - 1),
8282
Error::<Test>::StakeTooSmall
8383
);
8484

0 commit comments

Comments
 (0)