From b0fe26e620dbf90aceb5e8d025afed03e6c81517 Mon Sep 17 00:00:00 2001 From: letodunc Date: Mon, 14 Nov 2022 12:18:27 +0100 Subject: [PATCH 1/4] added function to retrieve houses with FINALISING status --- pallets/onboarding/src/functions.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pallets/onboarding/src/functions.rs b/pallets/onboarding/src/functions.rs index 21b305d3..7c5111be 100644 --- a/pallets/onboarding/src/functions.rs +++ b/pallets/onboarding/src/functions.rs @@ -159,25 +159,38 @@ impl Pallet { T::FeesAccount::get().into_account_truncating() } - pub fn get_onboarded_houses() -> Vec<( + fn get_houses_by_status(status: types::AssetStatus) -> Vec<( ::NftCollectionId, ::NftItemId, types::Asset, )> { Houses::::iter() - .filter(|val| val.2.status == types::AssetStatus::ONBOARDED) + .filter(|val| val.2.status == status) .map(|elt| (elt.0, elt.1, elt.2)) .collect() } + pub fn get_onboarded_houses() -> Vec<( + ::NftCollectionId, + ::NftItemId, + types::Asset, + )> { + Self::get_houses_by_status(types::AssetStatus::ONBOARDED) + } + pub fn get_finalised_houses() -> Vec<( ::NftCollectionId, ::NftItemId, types::Asset, )> { - Houses::::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<( + ::NftCollectionId, + ::NftItemId, + types::Asset, + )> { + Self::get_houses_by_status(types::AssetStatus::FINALISING) } } From ea78fcde90a890c7de913395957e77c4532b55e2 Mon Sep 17 00:00:00 2001 From: letodunc Date: Mon, 14 Nov 2022 12:18:38 +0100 Subject: [PATCH 2/4] updated tests --- pallets/onboarding/src/tests.rs | 89 ++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/pallets/onboarding/src/tests.rs b/pallets/onboarding/src/tests.rs index 997fcbb7..434acd31 100644 --- a/pallets/onboarding/src/tests.rs +++ b/pallets/onboarding/src/tests.rs @@ -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); @@ -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::StringLimit> = + b"metadata0".to_vec().try_into().unwrap(); + let metadata1: BoundedVec::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::StringLimit> = + b"metadata0".to_vec().try_into().unwrap(); + let metadata1: BoundedVec::StringLimit> = + b"metadata1".to_vec().try_into().unwrap(); + let metadata2: BoundedVec::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::::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::FINALISING, + )); + + 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,); + assert_eq!(house.2.price, Some(price),); + }); +} From 7f646f7be7f94240cfbad92f70503010396929be Mon Sep 17 00:00:00 2001 From: cuteolaf <53915161+cuteolaf@users.noreply.github.com> Date: Mon, 14 Nov 2022 04:31:46 -0800 Subject: [PATCH 3/4] Update functions.rs --- pallets/onboarding/src/functions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/onboarding/src/functions.rs b/pallets/onboarding/src/functions.rs index 7c5111be..50989b7f 100644 --- a/pallets/onboarding/src/functions.rs +++ b/pallets/onboarding/src/functions.rs @@ -165,8 +165,8 @@ impl Pallet { types::Asset, )> { Houses::::iter() - .filter(|val| val.2.status == status) - .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() } From a73f5f84da508c476b8a1f53962bc8c68ae5027f Mon Sep 17 00:00:00 2001 From: letodunc Date: Mon, 14 Nov 2022 13:54:32 +0100 Subject: [PATCH 4/4] added cosmetic changes --- pallets/onboarding/src/tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/onboarding/src/tests.rs b/pallets/onboarding/src/tests.rs index 434acd31..1ea4b697 100644 --- a/pallets/onboarding/src/tests.rs +++ b/pallets/onboarding/src/tests.rs @@ -416,12 +416,12 @@ fn get_finalised_houses_with_finalised_houses() { let collection_id = NftColl::OFFICESTEST.value(); let item_id = pallet_nft::ItemsCount::::get()[collection_id as usize] - 1; - // we simulate for the the presence of an finalised house by changing its status + // we simulate for the the presence of a finalised house by changing its status assert_ok!(OnboardingModule::change_status( Origin::signed(BOB), NftColl::OFFICESTEST, item_id, - AssetStatus::FINALISED, + AssetStatus::FINALISED )); let price2 = 200_000_000; @@ -503,12 +503,12 @@ fn get_finalising_houses_with_finalising_houses() { let collection_id = NftColl::OFFICESTEST.value(); let item_id = pallet_nft::ItemsCount::::get()[collection_id as usize] - 1; - // we simulate for the the presence of an finalised house by changing its status + // we simulate for the the presence of a finalising house by changing its status assert_ok!(OnboardingModule::change_status( Origin::signed(BOB), NftColl::OFFICESTEST, item_id, - AssetStatus::FINALISING, + AssetStatus::FINALISING )); let price2 = 200_000_000; @@ -526,7 +526,7 @@ fn get_finalising_houses_with_finalising_houses() { assert_eq!(finalising_houses.len(), 1); let house = finalising_houses[0].clone(); - assert_eq!(house.2.status, AssetStatus::FINALISING,); - assert_eq!(house.2.price, Some(price),); + assert_eq!(house.2.status, AssetStatus::FINALISING); + assert_eq!(house.2.price, Some(price)); }); }