Skip to content

Commit 3a1e5cc

Browse files
authored
Merge pull request #101 from rmrk-team/bug/55/fail-when-accepting-non-pending-resource
implement ResourceNotPending when accepting a resource that need not be accepted
2 parents ffbfcb9 + 9e3d713 commit 3a1e5cc

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

pallets/rmrk-core/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ pub mod pallet {
254254
CannotAcceptNonOwnedNft,
255255
CannotRejectNonOwnedNft,
256256
ResourceDoesntExist,
257+
/// Accepting a resource that is not pending should fail
258+
ResourceNotPending,
257259
}
258260

259261
#[pallet::call]
@@ -592,6 +594,7 @@ pub mod pallet {
592594
(collection_id, nft_id, resource_id.clone()),
593595
|resource| -> DispatchResult {
594596
if let Some(res) = resource.into_mut() {
597+
ensure!(res.pending, Error::<T>::ResourceNotPending);
595598
res.pending = false;
596599
}
597600
Ok(())

pallets/rmrk-core/src/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ fn add_resource_pending_works() {
805805
}));
806806
// Resource should now have false pending status
807807
assert_eq!(RMRKCore::resources((0, 0, stbr("res-4"))).unwrap().pending, false);
808+
// Accepting resource again should fail with ResourceNotPending
809+
assert_noop!(RMRKCore::accept_resource(Origin::signed(ALICE), 0, 0, stbr("res-4")), Error::<Test>::ResourceNotPending);
808810
});
809811
}
810812

0 commit comments

Comments
 (0)