1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {21 normalizeAccountId,22} from './util/helpers';23import {usingPlaygrounds} from './util/playgrounds';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728let donor: IKeyringPair;2930before(async () => {31 await usingPlaygrounds(async (_, privateKey) => {32 donor = privateKey('//Alice');33 });34});3536describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {37 let alice: IKeyringPair;3839 before(async () => {40 await usingPlaygrounds(async (helper) => {41 [alice] = await helper.arrange.createAccounts([100n], donor);42 });43 });4445 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {46 await usingPlaygrounds(async (helper) => {47 const collection = await helper.nft.mintCollection(alice, {48 name: 'name',49 description: 'descr',50 tokenPrefix: 'COL',51 tokenPropertyPermissions: [52 {key: 'data', permission: {tokenOwner: true, mutable: false, collectionAdmin: false}},53 ],54 });55 const args = [56 {properties: [{key: 'data', value: '1'}]},57 {properties: [{key: 'data', value: '2'}]},58 {properties: [{key: 'data', value: '3'}]},59 ];60 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);61 for (const [i, token] of tokens.entries()) {62 const tokenData = await token.getData();63 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: alice.address});64 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);65 }66 });67 });6869 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {70 await usingPlaygrounds(async (helper) => {71 const collection = await helper.ft.mintCollection(alice, {72 name: 'name',73 description: 'descr',74 tokenPrefix: 'COL',75 });76 const args = [77 {value: 1n},78 {value: 2n},79 {value: 3n},80 ];81 await helper.ft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);82 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(6n);83 });84 });8586 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async function() {87 await usingPlaygrounds(async (helper) => {88 const collection = await helper.rft.mintCollection(alice, {89 name: 'name',90 description: 'descr',91 tokenPrefix: 'COL',92 });93 const args = [94 {pieces: 1n},95 {pieces: 2n},96 {pieces: 3n},97 ];98 const tokens = await helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);99100 for (const [i, token] of tokens.entries()) {101 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(BigInt(i + 1));102 }103 });104 });105106 it('Can mint amount of items equals to collection limits', async () => {107 await usingPlaygrounds(async (helper) => {108 const collection = await helper.nft.mintCollection(alice, {109 name: 'name',110 description: 'descr',111 tokenPrefix: 'COL',112 limits: {113 tokenLimit: 2,114 },115 });116 const args = [{}, {}];117 await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);118 });119 });120121 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {122 await usingPlaygrounds(async (helper) => {123 const collection = await helper.nft.mintCollection(alice, {124 name: 'name',125 description: 'descr',126 tokenPrefix: 'COL',127 tokenPropertyPermissions: [128 {key: 'data', permission: {tokenOwner: false, mutable: true, collectionAdmin: true}},129 ],130 });131 const args = [132 {properties: [{key: 'data', value: '1'}]},133 {properties: [{key: 'data', value: '2'}]},134 {properties: [{key: 'data', value: '3'}]},135 ];136 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);137 for (const [i, token] of tokens.entries()) {138 const tokenData = await token.getData();139 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: alice.address});140 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);141 }142 });143 });144145 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {146 await usingPlaygrounds(async (helper) => {147 const collection = await helper.nft.mintCollection(alice, {148 name: 'name',149 description: 'descr',150 tokenPrefix: 'COL',151 tokenPropertyPermissions: [152 {key: 'data', permission: {tokenOwner: false, mutable: false, collectionAdmin: true}},153 ],154 });155 const args = [156 {properties: [{key: 'data', value: '1'}]},157 {properties: [{key: 'data', value: '2'}]},158 {properties: [{key: 'data', value: '3'}]},159 ];160 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);161 for (const [i, token] of tokens.entries()) {162 const tokenData = await token.getData();163 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: alice.address});164 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);165 }166 });167 });168169 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {170 await usingPlaygrounds(async (helper) => {171 const collection = await helper.nft.mintCollection(alice, {172 name: 'name',173 description: 'descr',174 tokenPrefix: 'COL',175 tokenPropertyPermissions: [176 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},177 ],178 });179 const args = [180 {properties: [{key: 'data', value: '1'}]},181 {properties: [{key: 'data', value: '2'}]},182 {properties: [{key: 'data', value: '3'}]},183 ];184 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);185 for (const [i, token] of tokens.entries()) {186 const tokenData = await token.getData();187 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: alice.address});188 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);189 }190 });191 });192});193194describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {195 let alice: IKeyringPair;196 let bob: IKeyringPair;197198 before(async () => {199 await usingPlaygrounds(async (helper) => {200 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);201 });202 });203204 it('Regular user cannot create items in active NFT collection', async () => {205 await usingPlaygrounds(async (helper) => {206 const collection = await helper.nft.mintCollection(alice, {207 name: 'name',208 description: 'descr',209 tokenPrefix: 'COL',210 });211 const args = [212 {},213 {},214 ];215 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(bob, collection.collectionId, {Substrate: alice.address}, args);216 await expect(mintTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);217 });218 });219220 it('Regular user cannot create items in active Fungible collection', async () => {221 await usingPlaygrounds(async (helper) => {222 const collection = await helper.ft.mintCollection(alice, {223 name: 'name',224 description: 'descr',225 tokenPrefix: 'COL',226 });227 const args = [228 {value: 1n},229 {value: 2n},230 {value: 3n},231 ];232 const mintTx = async () => helper.ft.mintMultipleTokensWithOneOwner(bob, collection.collectionId, {Substrate: alice.address}, args);233 await expect(mintTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);234 });235 });236237 it('Regular user cannot create items in active ReFungible collection', async function() {238 await usingPlaygrounds(async (helper) => {239 const collection = await helper.rft.mintCollection(alice, {240 name: 'name',241 description: 'descr',242 tokenPrefix: 'COL',243 });244 const args = [245 {pieces: 1n},246 {pieces: 1n},247 {pieces: 1n},248 ];249 const mintTx = async () => helper.rft.mintMultipleTokensWithOneOwner(bob, collection.collectionId, {Substrate: alice.address}, args);250 await expect(mintTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);251 });252 });253254 it('Create token in not existing collection', async () => {255 await usingPlaygrounds(async (helper) => {256 const collectionId = 1_000_000;257 const args = [258 {},259 {},260 ];261 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(bob, collectionId, {Substrate: alice.address}, args);262 await expect(mintTx()).to.be.rejectedWith(/common\.CollectionNotFound/);263 });264 });265266 it('Create NFTs that has reached the maximum data limit', async function() {267 await usingPlaygrounds(async (helper) => {268 const collection = await helper.nft.mintCollection(alice, {269 name: 'name',270 description: 'descr',271 tokenPrefix: 'COL',272 tokenPropertyPermissions: [273 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},274 ],275 });276 const args = [277 {properties: [{key: 'data', value: 'A'.repeat(32769)}]},278 {properties: [{key: 'data', value: 'B'.repeat(32769)}]},279 {properties: [{key: 'data', value: 'C'.repeat(32769)}]},280 ];281 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);282 await expect(mintTx()).to.be.rejected;283 });284 });285286 it('Create Refungible tokens that has reached the maximum data limit', async function() {287 await usingPlaygrounds(async (helper) => {288 const collection = await helper.rft.mintCollection(alice, {289 name: 'name',290 description: 'descr',291 tokenPrefix: 'COL',292 tokenPropertyPermissions: [293 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},294 ],295 });296 const args = [297 {pieces: 10n, properties: [{key: 'data', value: 'A'.repeat(32769)}]},298 {pieces: 10n, properties: [{key: 'data', value: 'B'.repeat(32769)}]},299 {pieces: 10n, properties: [{key: 'data', value: 'C'.repeat(32769)}]},300 ];301 const mintTx = async () => helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);302 await expect(mintTx()).to.be.rejected;303 });304 });305306 it('Create tokens with different types', async () => {307 await usingPlaygrounds(async (helper) => {308 const {collectionId} = await helper.nft.mintCollection(alice, {309 name: 'name',310 description: 'descr',311 tokenPrefix: 'COL',312 });313314 315 const types = ['NFT', 'Fungible', 'ReFungible'];316 const mintTx = helper.api?.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), types);317 await expect(helper.signTransaction(alice, mintTx)).to.be.rejected;318 });319 });320321 it('Create tokens with different data limits <> maximum data limit', async () => {322 await usingPlaygrounds(async (helper) => {323 const collection = await helper.nft.mintCollection(alice, {324 name: 'name',325 description: 'descr',326 tokenPrefix: 'COL',327 tokenPropertyPermissions: [328 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},329 ],330 });331 const args = [332 {properties: [{key: 'data', value: 'A'}]},333 {properties: [{key: 'data', value: 'B'.repeat(32769)}]},334 ];335 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);336 await expect(mintTx()).to.be.rejected;337 });338 });339340 it('Fails when minting tokens exceeds collectionLimits amount', async () => {341 await usingPlaygrounds(async (helper) => {342 const collection = await helper.nft.mintCollection(alice, {343 name: 'name',344 description: 'descr',345 tokenPrefix: 'COL',346 tokenPropertyPermissions: [347 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},348 ],349 limits: {350 tokenLimit: 1,351 },352 });353 const args = [354 {},355 {},356 ];357 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);358 await expect(mintTx()).to.be.rejected;359 });360 });361362 it('User doesnt have editing rights', async () => {363 await usingPlaygrounds(async (helper) => {364 const collection = await helper.nft.mintCollection(alice, {365 name: 'name',366 description: 'descr',367 tokenPrefix: 'COL',368 tokenPropertyPermissions: [369 {key: 'data', permission: {tokenOwner: false, mutable: true, collectionAdmin: false}},370 ],371 });372 const args = [373 {properties: [{key: 'data', value: 'A'}]},374 ];375 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);376 await expect(mintTx()).to.be.rejected;377 });378 });379380 it('Adding property without access rights', async () => {381 await usingPlaygrounds(async (helper) => {382 const collection = await helper.nft.mintCollection(alice, {383 name: 'name',384 description: 'descr',385 tokenPrefix: 'COL',386 properties: [387 {388 key: 'data',389 value: 'v',390 },391 ],392 });393 const args = [394 {properties: [{key: 'data', value: 'A'}]},395 ];396 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);397 await expect(mintTx()).to.be.rejected;398 });399 });400401 it('Adding more than 64 prps', async () => {402 await usingPlaygrounds(async (helper) => {403 const collection = await helper.nft.mintCollection(alice, {404 name: 'name',405 description: 'descr',406 tokenPrefix: 'COL',407 });408 const prps = [];409410 for (let i = 0; i < 65; i++) {411 prps.push({key: `key${i}`, value: `value${i}`});412 }413414 const args = [415 {properties: prps},416 {properties: prps},417 {properties: prps},418 ];419420 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);421 await expect(mintTx()).to.be.rejected;422 });423 });424});