Skip to content

Commit

Permalink
Upgraded payment pallet for Asset vacancy check
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Mar 3, 2023
1 parent cbe5245 commit 6a2fb58
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 33 deletions.
4 changes: 4 additions & 0 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,10 @@ pub mod pallet {
let vacancy = Self::fetch_house(collection,item).max_tenants;
ensure!(vacancy > 0, Error::<T>::MaximumNumberOfTenantsReached);

// Check for awaiting guaranty payment requests
let requests = Payment::Payment::<T>::iter().count();
ensure!(vacancy > requests as u8, Error::<T>::MaximumNumberOfTenantsReached);

//Launch payment request
Self::guaranty_payment(origin, from.clone(), collection, item).ok();
let payment = Self::guaranty(from.clone(), asset_account).unwrap();
Expand Down
15 changes: 10 additions & 5 deletions pallets/bidding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -683,7 +686,8 @@ fn process_onboarded_assets_should_succeed() {
NftCollection::OFFICESTEST,
Some(100),
metadata,
false
false,
3
));

let collection_id = NftCollection::OFFICESTEST.value();
Expand Down Expand Up @@ -840,7 +844,8 @@ fn process_finalised_assets_should_succeed() {
NftCollection::OFFICESTEST,
Some(100),
metadata,
false
false,
3
));

let collection_id = NftCollection::OFFICESTEST.value();
Expand Down
27 changes: 18 additions & 9 deletions pallets/finalizer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -169,7 +171,8 @@ fn validate_transaction_asset_should_succeed() {
NftCollection::OFFICESTEST,
Some(100),
metadata,
false
false,
3
));

let collection_id = NftCollection::OFFICESTEST.value();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -384,7 +389,8 @@ fn reject_transaction_asset_should_succeed() {
NftCollection::OFFICESTEST,
Some(100),
metadata,
false
false,
3
));

let collection_id = NftCollection::OFFICESTEST.value();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -612,7 +620,8 @@ fn cancel_transaction_asset_should_succeed() {
NftCollection::OFFICESTEST,
Some(100),
metadata,
false
false,
3
));

let collection_id = NftCollection::OFFICESTEST.value();
Expand Down
28 changes: 14 additions & 14 deletions pallets/onboarding/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -43,7 +43,7 @@ fn create_proposal() {
Some(price),
metadata1,
false,
max_tenants
MAX_TENANTS
));

let coll_id = NftColl::OFFICESTEST.value();
Expand Down Expand Up @@ -125,7 +125,7 @@ fn create_proposal_2() {
Some(price),
metadata1,
true,
max_tenants
MAX_TENANTS
));

let coll_id = NftColl::OFFICESTEST.value();
Expand Down Expand Up @@ -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::<Test>::get()[coll_id as usize] - 1;
Expand All @@ -213,7 +213,7 @@ fn proposal_rejections() {
Some(price1),
metadata2,
true,
max_tenants
MAX_TENANTS
));
let item_id1 = pallet_nft::ItemsCount::<Test>::get()[coll_id as usize] - 1;
let status_1: AssetStatus = Houses::<Test>::get(coll_id, item_id0).unwrap().status;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pallets/payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> = StorageDoubleMap<
pub type Payment<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId, // payment creator
Expand Down Expand Up @@ -407,10 +407,11 @@ pub mod pallet {
ensure!(payment.state == PaymentState::PaymentRequested, Error::<T>::InvalidAction);

// reserve all the fees from the sender
<Self as PaymentHandler<T>>::reserve_payment_amount(&from, &to, payment)?;
<Self as PaymentHandler<T>>::reserve_payment_amount(&from, &to, payment.clone())?;

// release the payment and delete the payment from storage
//<Self as PaymentHandler<T>>::settle_payment(&from, &to, Percent::from_percent(100))?;
<Self as PaymentHandler<T>>::settle_payment(&from, &to, Percent::from_percent(100))?;
T::Currency::reserve(&to, payment.amount).ok();

Self::deposit_event(Event::PaymentRequestCompleted { from, to });

Expand Down
6 changes: 4 additions & 2 deletions pallets/share_distributor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ pub fn prep_test(
NftColl::OFFICESTEST,
Some(price1),
metadata1,
false
false,
3
));

assert_ok!(OnboardingModule::create_and_submit_proposal(
Origin::signed(BOB),
NftColl::APPARTMENTSTEST,
Some(price2),
metadata2,
false
false,
3
));
}

Expand Down

0 comments on commit 6a2fb58

Please sign in to comment.