Skip to content

Commit

Permalink
add test case & amend error check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick95550 committed Sep 10, 2024
1 parent bc17d79 commit edae085
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pallet/marketplace/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<T: Config> Pallet<T> {
) -> Result<OfferId, DispatchError> {
ensure!(!amount.is_zero(), Error::<T>::ZeroOffer);
let token_owner = T::NFTExt::get_token_owner(&token_id);
ensure!(!token_owner.is_none(), Error::<T>::NoTokenOwner);
ensure!(token_owner.is_some(), Error::<T>::NoToken);
ensure!(token_owner != Some(who), Error::<T>::IsTokenOwner);
let offer_id = Self::next_offer_id();
ensure!(offer_id.checked_add(One::one()).is_some(), Error::<T>::NoAvailableIds);
Expand Down
4 changes: 2 additions & 2 deletions pallet/marketplace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ pub mod pallet {
TokenOnAuction,
/// No tokens were specified in the listing
EmptyTokens,
/// Token does not have an owner, likely the token has been burnt
NoTokenOwner,
/// The token does not exist
NoToken,
}

#[pallet::hooks]
Expand Down
22 changes: 21 additions & 1 deletion pallet/marketplace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,27 @@ fn make_simple_offer_on_burnt_token_should_fail() {
NativeAssetId::get(),
None
),
Error::<Test>::NoTokenOwner
Error::<Test>::NoToken
);
});
}

#[test]
fn make_simple_offer_on_non_existent_token_should_fail() {
let buyer = create_account(7);

TestExt::<Test>::default().build().execute_with(|| {
let (collection_id, _, _) = setup_nft_token();
let offer_amount: Balance = 100;
assert_noop!(
Marketplace::make_simple_offer(
Some(buyer).into(),
(collection_id, 456), // non existent token
offer_amount,
NativeAssetId::get(),
None
),
Error::<Test>::NoToken
);
});
}
Expand Down

0 comments on commit edae085

Please sign in to comment.