Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

137 onboarding pallet get houses with onboarded status #138

Merged
merged 3 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
);
});
}