Skip to content

Commit

Permalink
Merge pull request Fair-Squares#138 from Fair-Squares/137-onboarding-…
Browse files Browse the repository at this point in the history
…pallet-get-houses-with-onboarded-status

137 onboarding pallet get houses with onboarded status
  • Loading branch information
ndkazu authored Sep 11, 2022
2 parents db24557 + 05bc56e commit 08e5cc4
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pallets/onboarding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ benchmarks! {
assert_eq!(Something::<T>::get(), Some(s));
}

impl_benchmark_test_suite!(Onboarding, crate::mock::new_test_ext(), crate::mock::Test);
impl_benchmark_test_suite!(Onboarding, crate::mock::ExtBuilder::default().build(), crate::mock::Test);
}
4 changes: 4 additions & 0 deletions pallets/onboarding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ impl<T: Config> Pallet<T> {
pub fn account_id() -> T::AccountId {
T::FeesAccount::get().into_account_truncating()
}

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()
}
}
99 changes: 99 additions & 0 deletions pallets/onboarding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,102 @@ fn proposal_rejections() {
});
}

#[test]
fn get_onboarded_houses_no_onboarded_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 onboarded_houses = OnboardingModule::get_onboarded_houses();
assert_eq!(
onboarded_houses.len(),
0
);
});
}

#[test]
fn get_onboarded_houses_with_onboarded_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 onboarded house by changing its status
assert_ok!(OnboardingModule::change_status(
Origin::signed(BOB),
NftColl::OFFICESTEST,
item_id,
AssetStatus::ONBOARDED,
));

let price2 = 200_000_000;
// we add a new asset that won't have the ONBOARDED 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 onboarded_houses = OnboardingModule::get_onboarded_houses();
assert_eq!(
onboarded_houses.len(),
1
);

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

0 comments on commit 08e5cc4

Please sign in to comment.