Skip to content

Commit 596c68f

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix/freeze-lock-inconsistency-fix-call
2 parents 5a9a582 + f63d30e commit 596c68f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

pallets/dapp-staking-v3/src/test/testing_utils.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ impl MemorySnapshot {
8686
/// Returns locked balance in dApp staking for the specified account.
8787
/// In case no balance is locked, returns zero.
8888
pub fn locked_balance(&self, account: &AccountId) -> Balance {
89-
self.ledger
90-
.get(&account)
91-
.map_or(Balance::zero(), |ledger| ledger.active_locked_amount())
89+
self.ledger.get(&account).map_or(Balance::zero(), |ledger| {
90+
ledger.locked + ledger.unlocking.iter().fold(0, |acc, x| acc + x.amount)
91+
})
9292
}
9393
}
9494

@@ -240,10 +240,15 @@ pub(crate) fn assert_lock(account: AccountId, amount: Balance) {
240240
"Total locked balance should be increased by the amount locked."
241241
);
242242

243+
let post_frozen_balance = Balances::balance_frozen(&FreezeReason::DAppStaking.into(), &account);
243244
assert_eq!(
244245
init_frozen_balance + expected_lock_amount,
245-
Balances::balance_frozen(&FreezeReason::DAppStaking.into(), &account)
246+
post_frozen_balance
246247
);
248+
assert!(
249+
Balances::total_balance(&account) >= post_frozen_balance,
250+
"Total balance should never be less than frozen balance."
251+
)
247252
}
248253

249254
/// Start the unlocking process for locked funds and assert success.

pallets/dapp-staking-v3/src/test/tests.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3358,3 +3358,18 @@ fn fix_account_scenarios_work() {
33583358
);
33593359
})
33603360
}
3361+
3362+
fn lock_correctly_considers_unlocking_amount() {
3363+
ExtBuilder::build().execute_with(|| {
3364+
// Lock the entire amount & immediately start the unlocking process
3365+
let (staker, unlock_amount) = (1, 13);
3366+
let total_balance = Balances::total_balance(&staker);
3367+
assert_lock(staker, total_balance);
3368+
assert_unlock(staker, unlock_amount);
3369+
3370+
assert_noop!(
3371+
DappStaking::lock(RuntimeOrigin::signed(staker), 1),
3372+
Error::<Test>::ZeroAmount
3373+
);
3374+
})
3375+
}

0 commit comments

Comments
 (0)