Skip to content

Commit 8b182ad

Browse files
authored
Merge pull request #108 from Erebos0506/master
Collection max
2 parents 87ed274 + d442cc7 commit 8b182ad

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/rmrk2.0.0/tools/consolidator/interactions/mint.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export const validateMintNFT = async (
2323
`Attempted issue of NFT in non-owned collection. Issuer: ${nftParentCollection.issuer}, caller: ${remark.caller}`
2424
);
2525
}
26+
27+
const nfts = await dbAdapter.getNFTsByCollection(nftParentCollection.id);
28+
const unburnedNfts = nfts ? nfts.filter((nft) => nft.burned === "") : [];
29+
if (nftParentCollection.max <= unburnedNfts.length && nftParentCollection.max !== 0) {
30+
throw new Error(
31+
`Attempted to mint into maxed out collection ${nftParentCollection.id}`
32+
);
33+
}
2634

2735
if (nft.owner) {
2836
if (!isValidAddressPolkadotAddress(nft.owner)) {

test/2.0.0/consolidator/mint.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Consolidator, NFT } from "../../../src/rmrk2.0.0";
22
import {
33
createCollectionMock,
44
getBlockCallsMock,
5+
getAliceKey,
56
getBobKey,
67
getRemarksFromBlocksMock,
78
mintNftMock,
@@ -100,4 +101,20 @@ describe("rmrk2.0.0 Consolidator: MINT", () => {
100101
const consolidator = new Consolidator();
101102
expect(await consolidator.consolidate(remarks)).toMatchSnapshot();
102103
});
104+
105+
it("Should prevent minting NFT into locked collection", async () => {
106+
const remarks = getRemarksFromBlocksMock([
107+
...getSetupRemarks(),
108+
...getBlockCallsMock(
109+
createCollectionMock(2).lock(),
110+
getAliceKey().address
111+
),
112+
...getBlockCallsMock(mintNftMock2().mint()),
113+
]);
114+
const consolidator = new Consolidator();
115+
const consolidated = await consolidator.consolidate(remarks);
116+
expect(consolidated.invalid[0].message).toEqual(
117+
"Attempted to mint into maxed out collection d43593c715a56da27d-KANARIABIRDS"
118+
);
119+
});
103120
});

0 commit comments

Comments
 (0)