diff --git a/modules/homa-validator-list/src/lib.rs b/modules/homa-validator-list/src/lib.rs index fc33ce86c..08f772328 100644 --- a/modules/homa-validator-list/src/lib.rs +++ b/modules/homa-validator-list/src/lib.rs @@ -210,6 +210,11 @@ pub mod module { validator: T::RelayChainAccountId, bond: Balance, }, + RebondGuarantee { + who: T::AccountId, + validator: T::RelayChainAccountId, + bond: Balance, + }, } /// The slash guarantee deposits for relaychain validators. @@ -342,8 +347,17 @@ pub mod module { if !amount.is_zero() { Self::update_guarantee(&guarantor, &validator, |guarantee| -> DispatchResult { *guarantee = guarantee.rebond(amount); + ensure!( + guarantee.bonded >= T::MinBondAmount::get(), + Error::::BelowMinBondAmount + ); Ok(()) })?; + Self::deposit_event(Event::RebondGuarantee { + who: guarantor, + validator: validator.clone(), + bond: amount, + }); } Ok(()) } diff --git a/modules/homa-validator-list/src/tests.rs b/modules/homa-validator-list/src/tests.rs index 79023e567..ac745093a 100644 --- a/modules/homa-validator-list/src/tests.rs +++ b/modules/homa-validator-list/src/tests.rs @@ -449,15 +449,15 @@ fn rebond_work() { assert_ok!(HomaValidatorListModule::unbond( RuntimeOrigin::signed(ALICE), VALIDATOR_1, - 100 + 200 )); assert_eq!( HomaValidatorListModule::guarantees(VALIDATOR_1, ALICE).unwrap_or_default(), Guarantee { total: 200, - bonded: 100, - unbonding: Some((100, 29)) + bonded: 0, + unbonding: Some((200, 29)) } ); assert_eq!(OrmlTokens::accounts(ALICE, LDOT).frozen, 200); @@ -472,17 +472,29 @@ fn rebond_work() { 200 ); + assert_noop!( + HomaValidatorListModule::rebond(RuntimeOrigin::signed(ALICE), VALIDATOR_1, 99), + Error::::BelowMinBondAmount + ); + assert_ok!(HomaValidatorListModule::rebond( RuntimeOrigin::signed(ALICE), VALIDATOR_1, - 50 + 100 + )); + System::assert_has_event(mock::RuntimeEvent::HomaValidatorListModule( + crate::Event::RebondGuarantee { + who: ALICE, + validator: VALIDATOR_1, + bond: 100, + }, )); assert_eq!( HomaValidatorListModule::guarantees(VALIDATOR_1, ALICE).unwrap_or_default(), Guarantee { total: 200, - bonded: 150, - unbonding: Some((50, 29)) + bonded: 100, + unbonding: Some((100, 29)) } ); assert_eq!(OrmlTokens::accounts(ALICE, LDOT).frozen, 200);