Skip to content

Commit

Permalink
chore: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Dec 10, 2024
1 parent 627a0e6 commit 4535a52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pallets/nfts/src/features/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Item::<T, I>::get(collection, item).ok_or(Error::<T, I>::UnknownCollection)?;

if let Some(check_origin) = maybe_check_origin {
// Cannot revoke approvals for individual items when there are existing approvals to
// transfer all items in the collection owned by the origin.
ensure!(
CollectionApprovals::<T, I>::iter_prefix((collection, &check_origin))
.take(1)
Expand Down
38 changes: 27 additions & 11 deletions pallets/nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn lifecycle_should_work() {
account(20),
default_item_config()
));
assert_eq!(AccountBalance::<Test>::get(0, account(20)), 1);
assert_eq!(AccountBalance::<Test>::get(collection_id, account(20)), 1);
assert_eq!(Balances::reserved_balance(&owner), 7);
assert_ok!(Nfts::mint(
RuntimeOrigin::signed(owner.clone()),
Expand Down Expand Up @@ -2438,7 +2438,7 @@ fn approve_collection_transfer_works() {
Nfts::approve_collection_transfer(
RuntimeOrigin::signed(item_owner.clone()),
locked_collection,
account(3),
delegate.clone(),
None
),
Error::<Test>::ItemsNonTransferable
Expand Down Expand Up @@ -2477,7 +2477,7 @@ fn approve_collection_transfer_works() {
delegate.clone(),
Some(deadline)
));
assert_eq!(Balances::reserved_balance(&account(2)), 1);
assert_eq!(Balances::reserved_balance(&item_owner), 1);
let now = System::block_number();
assert!(events().contains(&Event::<Test>::TransferApproved {
collection: 0,
Expand Down Expand Up @@ -2564,7 +2564,7 @@ fn force_approve_collection_transfer_works() {
RuntimeOrigin::root(),
item_owner.clone(),
locked_collection,
account(3),
delegate.clone(),
None
),
Error::<Test>::ItemsNonTransferable
Expand Down Expand Up @@ -2606,7 +2606,7 @@ fn force_approve_collection_transfer_works() {
delegate.clone(),
Some(deadline)
));
assert_eq!(Balances::reserved_balance(&account(2)), 1);
assert_eq!(Balances::reserved_balance(&item_owner), 1);
let now = System::block_number();
assert!(events().contains(&Event::<Test>::TransferApproved {
collection: 0,
Expand Down Expand Up @@ -2928,7 +2928,10 @@ fn clear_collection_approvals_works() {
0
));
assert_eq!(Balances::free_balance(&owner), balance - 2);
assert_eq!(CollectionApprovals::<Test>::iter_prefix((0, owner.clone())).count(), 2);
assert_eq!(
CollectionApprovals::<Test>::iter_prefix((collection_id, owner.clone())).count(),
2
);
assert!(!events().contains(&Event::<Test>::ApprovalsCancelled {
collection: collection_id,
item: None,
Expand All @@ -2942,7 +2945,10 @@ fn clear_collection_approvals_works() {
1
));
assert_eq!(Balances::free_balance(&owner), balance - 1);
assert_eq!(CollectionApprovals::<Test>::iter_prefix((0, owner.clone())).count(), 1);
assert_eq!(
CollectionApprovals::<Test>::iter_prefix((collection_id, owner.clone())).count(),
1
);

// Successfully remove all collection approvals.
assert_ok!(Nfts::clear_collection_approvals(
Expand All @@ -2956,7 +2962,9 @@ fn clear_collection_approvals_works() {
owner: owner.clone(),
}));
assert_eq!(Balances::free_balance(&owner), balance);
assert!(CollectionApprovals::<Test>::iter_prefix((0, owner)).count().is_zero());
assert!(CollectionApprovals::<Test>::iter_prefix((collection_id, owner))
.count()
.is_zero());

assert_noop!(
Nfts::transfer(RuntimeOrigin::signed(delegate_1), collection_id, item_id, account(5)),
Expand Down Expand Up @@ -3013,7 +3021,10 @@ fn force_clear_collection_approvals_work() {
0
));
assert_eq!(Balances::free_balance(&owner), balance - 2);
assert_eq!(CollectionApprovals::<Test>::iter_prefix((0, owner.clone())).count(), 2);
assert_eq!(
CollectionApprovals::<Test>::iter_prefix((collection_id, owner.clone())).count(),
2
);
assert!(!events().contains(&Event::<Test>::ApprovalsCancelled {
collection: collection_id,
item: None,
Expand All @@ -3028,7 +3039,10 @@ fn force_clear_collection_approvals_work() {
1
));
assert_eq!(Balances::free_balance(&owner), balance - 1);
assert_eq!(CollectionApprovals::<Test>::iter_prefix((0, owner.clone())).count(), 1);
assert_eq!(
CollectionApprovals::<Test>::iter_prefix((collection_id, owner.clone())).count(),
1
);

// Successfully remove all collection approvals.
assert_ok!(Nfts::force_clear_collection_approvals(
Expand All @@ -3043,7 +3057,9 @@ fn force_clear_collection_approvals_work() {
owner: owner.clone(),
}));
assert_eq!(Balances::free_balance(&owner), balance);
assert!(CollectionApprovals::<Test>::iter_prefix((0, owner)).count().is_zero());
assert!(CollectionApprovals::<Test>::iter_prefix((collection_id, owner))
.count()
.is_zero());

assert_noop!(
Nfts::transfer(RuntimeOrigin::signed(delegate_1), collection_id, item_id, account(5)),
Expand Down

0 comments on commit 4535a52

Please sign in to comment.