diff --git a/pallets/asset_management/src/functions.rs b/pallets/asset_management/src/functions.rs index 2bdb4995..37c507ed 100644 --- a/pallets/asset_management/src/functions.rs +++ b/pallets/asset_management/src/functions.rs @@ -6,7 +6,7 @@ pub use scale_info::prelude::boxed::Box; pub use sp_core::H256; use sp_runtime::traits::{StaticLookup, Zero}; impl Pallet { - pub fn approve_representative(origin: OriginFor, who: T::AccountId) -> DispatchResult { + pub fn approve_representative_role(origin: OriginFor, who: T::AccountId) -> DispatchResult { let caller = ensure_signed(origin.clone())?; let mut representative = Roles::Pallet::::get_pending_representatives(&who).unwrap(); diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index 375c95cb..57ec1894 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -356,16 +356,16 @@ pub mod pallet { // Create the call let proposal_call = match proposal { VoteProposals::Election => { + // Check if the account is in the representative waiting list + let rep = Roles::Pallet::::get_pending_representatives(&representative); + ensure!(rep.is_some(), Error::::NotAPendingRepresentative); + // Ensure that the asset doesn't have a representative yet ensure!( asset.representative.is_none(), Error::::AssetAlreadyLinkedWithRepresentative ); - // Check if the account is in the representative waiting list - let rep = Roles::Pallet::::get_pending_representatives(&representative); - ensure!(rep.is_some(), Error::::NotAPendingRepresentative); - //Ensure that the Representative is not already connected to this asset ensure!( !rep.unwrap().assets_accounts.contains(&virtual_account), @@ -507,8 +507,14 @@ pub mod pallet { //Check that the caller is a stored virtual account ensure!(caller == asset_account.clone(), Error::::NotAnAssetAccount); + Onboarding::Houses::::mutate(collection, item, |asset| { + let mut asset0 = asset.clone().unwrap(); + asset0.representative = Some(rep_account.clone()); + *asset = Some(asset0); + }); + //Approve role request - Self::approve_representative(origin, rep_account.clone()).ok(); + Self::approve_representative_role(origin, rep_account.clone()).ok(); Self::deposit_event(Event::RepresentativeCandidateApproved { candidate: rep_account, diff --git a/pallets/asset_management/src/tests.rs b/pallets/asset_management/src/tests.rs index aa292d36..15e26901 100644 --- a/pallets/asset_management/src/tests.rs +++ b/pallets/asset_management/src/tests.rs @@ -75,9 +75,13 @@ pub fn prep_test( )); } -// FIXME: write more tests for the representative flow #[test] fn test_representative() { + // TODO: write more tests for the representative flow + // edge cases to cover + // - asset is already linked with the given representative(election) + // - asset is already linked with a representative(election) + // ... ExtBuilder::default().build().execute_with(|| { //submit a request for representative role RoleModule::set_role(Origin::signed(CHARLIE), CHARLIE, Acc::REPRESENTATIVE).ok(); @@ -284,7 +288,7 @@ fn test_integration_test() { assert!(Roles::RepresentativeLog::::contains_key(FERDIE)); assert!(Roles::AccountsRolesLog::::contains_key(FERDIE)); - // TODO: after fixing the issue of the representative flow, please uncomment + // TODO: after fixing the issue of the representative flow, please comment assert_err!( AssetManagement::launch_representative_session( origin_eve.clone(),