Skip to content

Commit eacdaef

Browse files
committed
Additional checks
1 parent 89264ae commit eacdaef

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pallets/dapps-staking/src/pallet/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ pub mod pallet {
310310
NominationTransferToSameContract,
311311
/// Decommission is in progress so this call is not allowed.
312312
DecommissionInProgress,
313+
/// Delegated claim call is not allowed if both the staker & caller are the same accounts.
314+
ClaimForCallerAccount,
313315
}
314316

315317
#[pallet::hooks]
@@ -930,6 +932,8 @@ pub mod pallet {
930932
Self::ensure_pallet_enabled()?;
931933
let caller = ensure_signed(origin)?;
932934

935+
ensure!(caller != staker, Error::<T>::ClaimForCallerAccount);
936+
933937
Self::internal_claim_staker_for(caller, staker, contract_id, true)
934938
}
935939

pallets/dapps-staking/src/tests.rs

+26
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,32 @@ fn claim_staker_for_works() {
25502550
})
25512551
}
25522552

2553+
#[test]
2554+
fn claim_staker_for_fails_if_caller_is_same_as_staker() {
2555+
ExternalityBuilder::build().execute_with(|| {
2556+
initialize_first_block();
2557+
2558+
// Register a dApp and stake some amount on it
2559+
let developer = 1;
2560+
let staker = 2;
2561+
let smart_contract = MockSmartContract::Evm(H160::repeat_byte(0x02));
2562+
assert_register(developer, &smart_contract);
2563+
assert_bond_and_stake(staker, &smart_contract, 13);
2564+
2565+
// Advance to next era so we can claim rewards for it
2566+
advance_to_era(DappsStaking::current_era() + 1);
2567+
2568+
assert_noop!(
2569+
DappsStaking::claim_staker_for(
2570+
RuntimeOrigin::signed(staker),
2571+
staker,
2572+
smart_contract.clone()
2573+
),
2574+
Error::<TestRuntime>::ClaimForCallerAccount
2575+
);
2576+
})
2577+
}
2578+
25532579
#[test]
25542580
fn set_reward_destination_for_works() {
25552581
ExternalityBuilder::build().execute_with(|| {

0 commit comments

Comments
 (0)