Skip to content

Commit

Permalink
174 onboarding pallet get asset with finalised status (#175)
Browse files Browse the repository at this point in the history
* added function to gest asset with FINALISED status

* updated tests
  • Loading branch information
letodunc authored Sep 28, 2022
1 parent 259a772 commit d26f1b6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pallets/onboarding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,8 @@ impl<T: Config> Pallet<T> {
pub fn get_onboarded_houses() -> Vec<(<T as pallet_nft::Config>::NftCollectionId, <T as pallet_nft::Config>::NftItemId, types::Asset<T>)> {
Houses::<T>::iter().filter(|val| val.2.status == types::AssetStatus::ONBOARDED).map(|elt| (elt.0, elt.1, elt.2)).collect()
}

pub fn get_finalised_houses() -> Vec<(<T as pallet_nft::Config>::NftCollectionId, <T as pallet_nft::Config>::NftItemId, types::Asset<T>)> {
Houses::<T>::iter().filter(|val| val.2.status == types::AssetStatus::FINALISED).map(|elt| (elt.0, elt.1, elt.2)).collect()
}
}
99 changes: 99 additions & 0 deletions pallets/onboarding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,102 @@ fn get_onboarded_houses_with_onboarded_houses() {
});
}

#[test]
fn get_finalised_houses_no_finalised_houses() {
ExtBuilder::default().build().execute_with(|| {
let metadata0: BoundedVec<u8, <Test as pallet_uniques::Config>::StringLimit> =
b"metadata0".to_vec().try_into().unwrap();
let metadata1: BoundedVec<u8, <Test as pallet_uniques::Config>::StringLimit> =
b"metadata1".to_vec().try_into().unwrap();

prep_roles();

//Charlie creates a collection
assert_ok!(NftModule::create_collection(
Origin::signed(CHARLIE),
NftColl::OFFICESTEST,
metadata0
));
// Bob creates a proposal without submiting for review
assert_ok!(OnboardingModule::create_and_submit_proposal(
Origin::signed(BOB),
NftColl::OFFICESTEST,
Some(100_000_000),
metadata1,
false
));

let finalised_houses = OnboardingModule::get_finalised_houses();
assert_eq!(
finalised_houses.len(),
0
);
});
}

#[test]
fn get_finalised_houses_with_finalised_houses() {
ExtBuilder::default().build().execute_with(|| {
let metadata0: BoundedVec<u8, <Test as pallet_uniques::Config>::StringLimit> =
b"metadata0".to_vec().try_into().unwrap();
let metadata1: BoundedVec<u8, <Test as pallet_uniques::Config>::StringLimit> =
b"metadata1".to_vec().try_into().unwrap();
let metadata2: BoundedVec<u8, <Test as pallet_uniques::Config>::StringLimit> =
b"metadata1".to_vec().try_into().unwrap();
prep_roles();
//Charlie creates a collection
assert_ok!(NftModule::create_collection(
Origin::signed(CHARLIE),
NftColl::OFFICESTEST,
metadata0
));
// Bob creates a proposal without submiting for review
let price = 100_000_000;
assert_ok!(OnboardingModule::create_and_submit_proposal(
Origin::signed(BOB),
NftColl::OFFICESTEST,
Some(price.clone()),
metadata1,
false
));

let collection_id = NftColl::OFFICESTEST.value();
let item_id = pallet_nft::ItemsCount::<Test>::get()[collection_id as usize] - 1;

// we simulate for the the presence of an finalised house by changing its status
assert_ok!(OnboardingModule::change_status(
Origin::signed(BOB),
NftColl::OFFICESTEST,
item_id,
AssetStatus::FINALISED,
));

let price2 = 200_000_000;
// we add a new asset that won't have the FINALISED status
assert_ok!(OnboardingModule::create_and_submit_proposal(
Origin::signed(BOB),
NftColl::OFFICESTEST,
Some(price2.clone()),
metadata2,
false
));

// we check that the onboarded house is correctly retrieved
let finalised_houses = OnboardingModule::get_finalised_houses();
assert_eq!(
finalised_houses.len(),
1
);

let house = finalised_houses[0].clone();
assert_eq!(
house.2.status,
AssetStatus::FINALISED,
);
assert_eq!(
house.2.price,
Some(price),
);
});
}

0 comments on commit d26f1b6

Please sign in to comment.