From a5210c75c2f269ca3a662de3a63bc8c3e29d44de Mon Sep 17 00:00:00 2001 From: Shady Khalifa Date: Tue, 24 Dec 2024 17:39:46 +0200 Subject: [PATCH] fix: reversed balance should be returned on unstake --- pallets/multi-asset-delegation/src/functions/operator.rs | 3 +++ pallets/multi-asset-delegation/src/tests/operator.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pallets/multi-asset-delegation/src/functions/operator.rs b/pallets/multi-asset-delegation/src/functions/operator.rs index 9e6e2b39..68a22b8f 100644 --- a/pallets/multi-asset-delegation/src/functions/operator.rs +++ b/pallets/multi-asset-delegation/src/functions/operator.rs @@ -238,6 +238,9 @@ impl Pallet { .checked_sub(&request.amount) .ok_or(Error::::UnstakeAmountTooLarge)?; + // Unreserve the unstaked amount and clear the request + T::Currency::unreserve(who, request.amount); + operator.request = None; Operators::::insert(who, operator); diff --git a/pallets/multi-asset-delegation/src/tests/operator.rs b/pallets/multi-asset-delegation/src/tests/operator.rs index 210b49f4..cbe18c5f 100644 --- a/pallets/multi-asset-delegation/src/tests/operator.rs +++ b/pallets/multi-asset-delegation/src/tests/operator.rs @@ -401,15 +401,18 @@ fn execute_operator_unstake_success() { // Set the current round to simulate passage of time >::put(15); + let reserved_balance = Balances::reserved_balance(Alice.to_account_id()); // Execute unstake assert_ok!(MultiAssetDelegation::execute_operator_unstake(RuntimeOrigin::signed( Alice.to_account_id() ))); + let reserved_balance_after = Balances::reserved_balance(Alice.to_account_id()); // Verify operator metadata let operator_info = MultiAssetDelegation::operator_info(Alice.to_account_id()).unwrap(); assert_eq!(operator_info.stake, bond_amount - unstake_amount); assert_eq!(operator_info.request, None); + assert_eq!(reserved_balance - reserved_balance_after, unstake_amount); // Verify event System::assert_has_event(RuntimeEvent::MultiAssetDelegation(