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

204 onboarding pallet get asset with finalising status #205

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
27 changes: 20 additions & 7 deletions pallets/onboarding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,38 @@ impl<T: Config> Pallet<T> {
T::FeesAccount::get().into_account_truncating()
}

pub fn get_onboarded_houses() -> Vec<(
fn get_houses_by_status(status: types::AssetStatus) -> 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))
.filter(|(_, _, house)| house.status == status)
.map(|(collection_id, item_id, house)| (collection_id, item_id, house))
.collect()
}

cuteolaf marked this conversation as resolved.
Show resolved Hide resolved
pub fn get_onboarded_houses() -> Vec<(
<T as pallet_nft::Config>::NftCollectionId,
<T as pallet_nft::Config>::NftItemId,
types::Asset<T>,
)> {
Self::get_houses_by_status(types::AssetStatus::ONBOARDED)
}

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()
Self::get_houses_by_status(types::AssetStatus::FINALISED)
}

pub fn get_finalising_houses() -> Vec<(
<T as pallet_nft::Config>::NftCollectionId,
<T as pallet_nft::Config>::NftItemId,
types::Asset<T>,
)> {
Self::get_houses_by_status(types::AssetStatus::FINALISING)
}
}
89 changes: 88 additions & 1 deletion pallets/onboarding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fn get_finalised_houses_with_finalised_houses() {
false
));

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

Expand All @@ -443,3 +443,90 @@ fn get_finalised_houses_with_finalised_houses() {
assert_eq!(house.2.price, Some(price),);
});
}

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

#[test]
fn get_finalising_houses_with_finalising_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),
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
cuteolaf marked this conversation as resolved.
Show resolved Hide resolved
assert_ok!(OnboardingModule::change_status(
Origin::signed(BOB),
NftColl::OFFICESTEST,
item_id,
AssetStatus::FINALISING,
cuteolaf marked this conversation as resolved.
Show resolved Hide resolved
));

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

// we check that the finalising house is correctly retrieved
let finalising_houses = OnboardingModule::get_finalising_houses();
assert_eq!(finalising_houses.len(), 1);

let house = finalising_houses[0].clone();
assert_eq!(house.2.status, AssetStatus::FINALISING,);
cuteolaf marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(house.2.price, Some(price),);
});
}