Skip to content

Commit 2291d78

Browse files
committed
Add Unit Tests for offers.
1 parent b444edb commit 2291d78

File tree

4 files changed

+630
-9
lines changed

4 files changed

+630
-9
lines changed

pallets/gated-marketplace/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ std = [
4343
"frame-support/std",
4444
"frame-system/std",
4545
"frame-benchmarking/std",
46+
"pallet-balances/std",
47+
"pallet-timestamp/std",
4648
]
4749

4850
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]

pallets/gated-marketplace/src/functions.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ impl<T: Config> Pallet<T> {
152152
}
153153

154154
pub fn do_enlist_sell_offer(authority: T::AccountId, marketplace_id: [u8;32], collection_id: T::CollectionId, item_id: T::ItemId, price: BalanceOf<T>,) -> DispatchResult {
155-
//TODO: ensure the user is a Marketparticipant
156-
155+
//This function is only called by the owner of the marketplace
157156
//ensure the marketplace exists
158157
ensure!(<Marketplaces<T>>::contains_key(marketplace_id), Error::<T>::MarketplaceNotFound);
159158

@@ -428,10 +427,13 @@ impl<T: Config> Pallet<T> {
428427
pub fn do_remove_offer(authority: T::AccountId, offer_id: [u8;32], marketplace_id: [u8;32], collection_id: T::CollectionId, item_id: T::ItemId, ) -> DispatchResult {
429428
//ensure marketplace_id exits
430429
ensure!(<Marketplaces<T>>::contains_key(marketplace_id), Error::<T>::MarketplaceNotFound);
431-
430+
432431
//ensure the offer_id exists
433432
ensure!(<OffersInfo<T>>::contains_key(offer_id), Error::<T>::OfferNotFound);
434433

434+
//ensure the offer status is Open
435+
ensure!(Self::is_offer_status(offer_id, OfferStatus::Open), Error::<T>::CannotDeleteOffer);
436+
435437

436438
// ensure the owner is the same as the authority
437439
let offer_creator = Self::get_offer_creator(offer_id).map_err(|_| Error::<T>::OfferNotFound)?;
@@ -440,9 +442,6 @@ impl<T: Config> Pallet<T> {
440442
//ensure the offer_id exists in OffersByItem
441443
Self::does_exist_offer_id_for_this_item(collection_id, item_id, offer_id)?;
442444

443-
//ensure the offer status is Open
444-
ensure!(Self::is_offer_status(offer_id, OfferStatus::Open), Error::<T>::CannotDeleteOffer);
445-
446445

447446
//remove the offer from OfferInfo
448447
<OffersInfo<T>>::remove(offer_id);

pallets/gated-marketplace/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ frame_support::construct_runtime!(
2323
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>},
2424
Fruniques: pallet_fruniques::{Pallet, Call, Storage, Event<T>},
2525
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
26-
26+
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
2727
}
2828
);
2929

0 commit comments

Comments
 (0)