From 6a2fb589d30b1b26d50ecb53a4449633fac638f9 Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong Date: Fri, 3 Mar 2023 16:06:10 +0900 Subject: [PATCH] Upgraded payment pallet for Asset vacancy check --- pallets/asset_management/src/lib.rs | 4 ++++ pallets/bidding/src/tests.rs | 15 +++++++++----- pallets/finalizer/src/tests.rs | 27 ++++++++++++++++--------- pallets/onboarding/src/tests.rs | 28 +++++++++++++------------- pallets/payment/src/lib.rs | 7 ++++--- pallets/share_distributor/src/tests.rs | 6 ++++-- 6 files changed, 54 insertions(+), 33 deletions(-) diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index 2e07b4c0..9306486c 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -795,6 +795,10 @@ pub mod pallet { let vacancy = Self::fetch_house(collection,item).max_tenants; ensure!(vacancy > 0, Error::::MaximumNumberOfTenantsReached); + // Check for awaiting guaranty payment requests + let requests = Payment::Payment::::iter().count(); + ensure!(vacancy > requests as u8, Error::::MaximumNumberOfTenantsReached); + //Launch payment request Self::guaranty_payment(origin, from.clone(), collection, item).ok(); let payment = Self::guaranty(from.clone(), asset_account).unwrap(); diff --git a/pallets/bidding/src/tests.rs b/pallets/bidding/src/tests.rs index 46c649d6..0907280e 100644 --- a/pallets/bidding/src/tests.rs +++ b/pallets/bidding/src/tests.rs @@ -429,7 +429,8 @@ fn process_onboarded_assets_not_enough_fund_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -513,7 +514,8 @@ fn process_onboarded_assets_not_enough_fund_among_investors_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -599,7 +601,8 @@ fn process_onboarded_assets_cannot_assemble_investor_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -683,7 +686,8 @@ fn process_onboarded_assets_should_succeed() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -840,7 +844,8 @@ fn process_finalised_assets_should_succeed() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); diff --git a/pallets/finalizer/src/tests.rs b/pallets/finalizer/src/tests.rs index 9d2d04c2..446558a5 100644 --- a/pallets/finalizer/src/tests.rs +++ b/pallets/finalizer/src/tests.rs @@ -33,7 +33,8 @@ fn validate_transaction_asset_no_notary_role_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -114,7 +115,8 @@ fn validate_transaction_asset_no_finalising_status_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -169,7 +171,8 @@ fn validate_transaction_asset_should_succeed() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -239,7 +242,8 @@ fn reject_transaction_asset_no_notary_role_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -320,7 +324,8 @@ fn reject_transaction_asset_no_finalising_status_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -384,7 +389,8 @@ fn reject_transaction_asset_should_succeed() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -477,7 +483,8 @@ fn cancel_transaction_asset_no_seller_role_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -544,7 +551,8 @@ fn cancel_transaction_asset_no_finalised_status_should_fail() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); @@ -612,7 +620,8 @@ fn cancel_transaction_asset_should_succeed() { NftCollection::OFFICESTEST, Some(100), metadata, - false + false, + 3 )); let collection_id = NftCollection::OFFICESTEST.value(); diff --git a/pallets/onboarding/src/tests.rs b/pallets/onboarding/src/tests.rs index 0271ad06..75a095e1 100644 --- a/pallets/onboarding/src/tests.rs +++ b/pallets/onboarding/src/tests.rs @@ -19,7 +19,7 @@ pub fn prep_roles() { RoleModule::account_approval(Origin::signed(ALICE), ACCOUNT_WITH_NO_BALANCE0).ok(); } -pub const max_tenants:u8 = 3; +pub const MAX_TENANTS:u8 = 3; #[test] fn create_proposal() { @@ -43,7 +43,7 @@ fn create_proposal() { Some(price), metadata1, false, - max_tenants + MAX_TENANTS )); let coll_id = NftColl::OFFICESTEST.value(); @@ -125,7 +125,7 @@ fn create_proposal_2() { Some(price), metadata1, true, - max_tenants + MAX_TENANTS )); let coll_id = NftColl::OFFICESTEST.value(); @@ -196,7 +196,7 @@ fn proposal_rejections() { Some(price0), metadata1, true, - max_tenants + MAX_TENANTS )); let coll_id = NftColl::OFFICESTEST.value(); let item_id0 = pallet_nft::ItemsCount::::get()[coll_id as usize] - 1; @@ -213,7 +213,7 @@ fn proposal_rejections() { Some(price1), metadata2, true, - max_tenants + MAX_TENANTS )); let item_id1 = pallet_nft::ItemsCount::::get()[coll_id as usize] - 1; let status_1: AssetStatus = Houses::::get(coll_id, item_id0).unwrap().status; @@ -301,7 +301,7 @@ fn get_onboarded_houses_no_onboarded_houses() { Some(100_000_000), metadata1, false, - max_tenants + MAX_TENANTS )); let onboarded_houses = OnboardingModule::get_onboarded_houses(); @@ -333,7 +333,7 @@ fn get_onboarded_houses_with_onboarded_houses() { Some(price), metadata1, false, - max_tenants + MAX_TENANTS )); let collection_id = NftColl::OFFICESTEST.value(); @@ -355,7 +355,7 @@ fn get_onboarded_houses_with_onboarded_houses() { Some(price2), metadata2, false, - max_tenants + MAX_TENANTS )); // we check that the onboarded house is correctly retrieved @@ -391,7 +391,7 @@ fn get_finalised_houses_no_finalised_houses() { Some(100_000_000), metadata1, false, - max_tenants + MAX_TENANTS )); let finalised_houses = OnboardingModule::get_finalised_houses(); @@ -423,7 +423,7 @@ fn get_finalised_houses_with_finalised_houses() { Some(price), metadata1, false, - max_tenants + MAX_TENANTS )); let collection_id = NftColl::OFFICESTEST.value(); @@ -445,7 +445,7 @@ fn get_finalised_houses_with_finalised_houses() { Some(price2), metadata2, false, - max_tenants + MAX_TENANTS )); // we check that the finalised house is correctly retrieved @@ -481,7 +481,7 @@ fn get_finalising_houses_no_finalising_houses() { Some(100_000_000), metadata1, false, - max_tenants + MAX_TENANTS )); let finalising_houses = OnboardingModule::get_finalising_houses(); @@ -513,7 +513,7 @@ fn get_finalising_houses_with_finalising_houses() { Some(price), metadata1, false, - max_tenants + MAX_TENANTS )); let collection_id = NftColl::OFFICESTEST.value(); @@ -535,7 +535,7 @@ fn get_finalising_houses_with_finalising_houses() { Some(price2), metadata2, false, - max_tenants + MAX_TENANTS )); // we check that the finalising house is correctly retrieved diff --git a/pallets/payment/src/lib.rs b/pallets/payment/src/lib.rs index 5852cdc0..cb80cde4 100644 --- a/pallets/payment/src/lib.rs +++ b/pallets/payment/src/lib.rs @@ -63,7 +63,7 @@ pub mod pallet { /// interest. The storage map keys are the creator and the recipient, this /// also ensures that for any (sender,recipient) combo, only a single /// payment is active. The history of payment is not stored. - pub(super) type Payment = StorageDoubleMap< + pub type Payment = StorageDoubleMap< _, Blake2_128Concat, T::AccountId, // payment creator @@ -407,10 +407,11 @@ pub mod pallet { ensure!(payment.state == PaymentState::PaymentRequested, Error::::InvalidAction); // reserve all the fees from the sender - >::reserve_payment_amount(&from, &to, payment)?; + >::reserve_payment_amount(&from, &to, payment.clone())?; // release the payment and delete the payment from storage - //>::settle_payment(&from, &to, Percent::from_percent(100))?; + >::settle_payment(&from, &to, Percent::from_percent(100))?; + T::Currency::reserve(&to, payment.amount).ok(); Self::deposit_event(Event::PaymentRequestCompleted { from, to }); diff --git a/pallets/share_distributor/src/tests.rs b/pallets/share_distributor/src/tests.rs index 2a3b41ed..b124cf78 100644 --- a/pallets/share_distributor/src/tests.rs +++ b/pallets/share_distributor/src/tests.rs @@ -53,7 +53,8 @@ pub fn prep_test( NftColl::OFFICESTEST, Some(price1), metadata1, - false + false, + 3 )); assert_ok!(OnboardingModule::create_and_submit_proposal( @@ -61,7 +62,8 @@ pub fn prep_test( NftColl::APPARTMENTSTEST, Some(price2), metadata2, - false + false, + 3 )); }