Skip to content

Commit

Permalink
update representative field in asset record
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed Feb 24, 2023
1 parent f4a0c38 commit bcaf363
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pallets/asset_management/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use scale_info::prelude::boxed::Box;
pub use sp_core::H256;
use sp_runtime::traits::{StaticLookup, Zero};
impl<T: Config> Pallet<T> {
pub fn approve_representative(origin: OriginFor<T>, who: T::AccountId) -> DispatchResult {
pub fn approve_representative_role(origin: OriginFor<T>, who: T::AccountId) -> DispatchResult {
let caller = ensure_signed(origin.clone())?;

let mut representative = Roles::Pallet::<T>::get_pending_representatives(&who).unwrap();
Expand Down
16 changes: 11 additions & 5 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::get_pending_representatives(&representative);
ensure!(rep.is_some(), Error::<T>::NotAPendingRepresentative);

// Ensure that the asset doesn't have a representative yet
ensure!(
asset.representative.is_none(),
Error::<T>::AssetAlreadyLinkedWithRepresentative
);

// Check if the account is in the representative waiting list
let rep = Roles::Pallet::<T>::get_pending_representatives(&representative);
ensure!(rep.is_some(), Error::<T>::NotAPendingRepresentative);

//Ensure that the Representative is not already connected to this asset
ensure!(
!rep.unwrap().assets_accounts.contains(&virtual_account),
Expand Down Expand Up @@ -507,8 +507,14 @@ pub mod pallet {
//Check that the caller is a stored virtual account
ensure!(caller == asset_account.clone(), Error::<T>::NotAnAssetAccount);

Onboarding::Houses::<T>::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,
Expand Down
8 changes: 6 additions & 2 deletions pallets/asset_management/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -284,7 +288,7 @@ fn test_integration_test() {
assert!(Roles::RepresentativeLog::<Test>::contains_key(FERDIE));
assert!(Roles::AccountsRolesLog::<Test>::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(),
Expand Down

0 comments on commit bcaf363

Please sign in to comment.