Skip to content

Commit 82e1bd5

Browse files
authored
Merge pull request #149 from rmrk-team/bug/148-fail-to-remove-burned-child-from-parent
2 parents 218fe30 + d455bfd commit 82e1bd5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pallets/rmrk-core/src/functions.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ where
313313
max_recursions: u32,
314314
) -> sp_std::result::Result<(CollectionId, NftId), DispatchError> {
315315
ensure!(max_recursions > 0, Error::<T>::TooManyRecursions);
316+
317+
// Remove self from parent's Children storage
318+
if let Some(nft) = Self::nfts(collection_id, nft_id) {
319+
if let AccountIdOrCollectionNftTuple::CollectionAndNftTuple(parent_col, parent_nft) = nft.owner {
320+
Children::<T>::remove((parent_col, parent_nft), (collection_id, nft_id));
321+
}
322+
}
323+
316324
Nfts::<T>::remove(collection_id, nft_id);
317325

318326
Resources::<T>::remove_prefix((collection_id, nft_id), None);

pallets/rmrk-core/src/tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,37 @@ fn burn_nft_beyond_max_recursions_fails_gracefully() {
823823
});
824824
}
825825

826+
/// NFT: Burn child removes NFT from owner-NFT's Children list
827+
#[test]
828+
fn burn_child_nft_removes_parents_children() {
829+
ExtBuilder::default().build().execute_with(|| {
830+
// Create a basic collection
831+
assert_ok!(basic_collection());
832+
// Mint NFTs (0, 0), (0, 1), (0, 2), (0, 3)
833+
for _ in 0..2 {
834+
assert_ok!(basic_mint());
835+
}
836+
// ALICE sends NFT (0, 1) to NFT (0, 0)
837+
assert_ok!(RMRKCore::send(
838+
Origin::signed(ALICE),
839+
0,
840+
1,
841+
AccountIdOrCollectionNftTuple::CollectionAndNftTuple(0, 0),
842+
));
843+
// All NFTs exist
844+
assert_eq!(RMRKCore::nfts(COLLECTION_ID_0, 0).is_some(), true);
845+
assert_eq!(RMRKCore::nfts(COLLECTION_ID_0, 1).is_some(), true);
846+
// NFT (0, 0) should have 1 Children storage member
847+
assert_eq!(Children::<Test>::iter_prefix((0, 0)).count(), 1);
848+
// Burn NFT (0, 1)
849+
assert_ok!(
850+
RMRKCore::burn_nft(Origin::signed(ALICE), 0, 1),
851+
);
852+
// NFT (0, 0) should have 0 Children storage members
853+
assert_eq!(Children::<Test>::iter_prefix((0, 0)).count(), 0);
854+
});
855+
}
856+
826857
/// Resource: Basic resource addition (RMRK2.0 spec: RESADD)
827858
#[test]
828859
fn create_resource_works() {

0 commit comments

Comments
 (0)