1234567891011121314151617import {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';19import {IKeyringPair} from '@polkadot/types/types';20import {21 createCollectionExpectSuccess,22 createItemExpectSuccess,23 addCollectionAdminExpectSuccess,24 createCollectionWithPropsExpectSuccess,25 createItemWithPropsExpectSuccess,26 createItemWithPropsExpectFailure,27 createCollection,28 transferExpectSuccess,29} from './util/helpers';3031const expect = chai.expect;32let alice: IKeyringPair;33let bob: IKeyringPair;3435describe('integration test: ext. ():', () => {36 before(async () => {37 await usingApi(async (api, privateKeyWrapper) => {38 alice = privateKeyWrapper('//Alice');39 bob = privateKeyWrapper('//Bob');40 });41 });4243 it('Create new item in NFT collection', async () => {44 const createMode = 'NFT';45 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});46 await createItemExpectSuccess(alice, newCollectionID, createMode);47 });48 it('Create new item in Fungible collection', async () => {49 const createMode = 'Fungible';50 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});51 await createItemExpectSuccess(alice, newCollectionID, createMode);52 });53 it('Create new item in ReFungible collection', async () => {54 const createMode = 'ReFungible';55 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});56 await createItemExpectSuccess(alice, newCollectionID, createMode);57 });58 it('Create new item in NFT collection with collection admin permissions', async () => {59 const createMode = 'NFT';60 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});61 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);62 await createItemExpectSuccess(bob, newCollectionID, createMode);63 });64 it('Create new item in Fungible collection with collection admin permissions', async () => {65 const createMode = 'Fungible';66 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});67 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);68 await createItemExpectSuccess(bob, newCollectionID, createMode);69 });70 it('Create new item in ReFungible collection with collection admin permissions', async () => {71 const createMode = 'ReFungible';72 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});73 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);74 await createItemExpectSuccess(bob, newCollectionID, createMode);75 });7677 it('Set property Admin', async () => {78 const createMode = 'NFT';79 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 80 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});81 82 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);83 });8485 it('Set property AdminConst', async () => {86 const createMode = 'NFT';87 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 88 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});89 90 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);91 });9293 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},96 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});97 98 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);99 });100101 it.only('Check total pieces of Fungible token', async () => {102 await usingApi(async api => {103 const createMode = 'Fungible';104 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});105 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);106 {107 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);108 expect(totalPieces.isSome).to.be.true;109 expect(totalPieces.unwrap().toBigInt()).to.be.eq(10n);110 }111112 await transferExpectSuccess(collectionId, tokenId, bob, alice, 1, createMode);113 {114 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);115 expect(totalPieces.isSome).to.be.true;116 expect(totalPieces.unwrap().toBigInt()).to.be.eq(10n);117 }118 });119 });120121 it.only('Check total pieces of NFT token', async () => {122 await usingApi(async api => {123 const createMode = 'NFT';124 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});125 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);126 {127 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);128 expect(totalPieces.isSome).to.be.true;129 expect(totalPieces.unwrap().toBigInt()).to.be.eq(1n);130 }131132 await transferExpectSuccess(collectionId, tokenId, bob, alice, 1, createMode);133 {134 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);135 expect(totalPieces.isSome).to.be.true;136 expect(totalPieces.unwrap().toBigInt()).to.be.eq(1n);137 }138 });139 });140141 it.only('Check total pieces of ReFungible token', async () => {142 await usingApi(async api => {143 const createMode = 'ReFungible';144 const createCollectionResult = await createCollection(api, alice, {mode: {type: createMode}});145 const collectionId = createCollectionResult.collectionId;146 const amountPieces = 100n;147 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);148 {149 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);150 expect(totalPieces.isSome).to.be.true;151 expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);152 }153154 await transferExpectSuccess(collectionId, tokenId, bob, alice, 60n, createMode);155 {156 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);157 expect(totalPieces.isSome).to.be.true;158 expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);159 }160 });161 });162});163164describe('Negative integration test: ext. createItem():', () => {165 before(async () => {166 await usingApi(async (api, privateKeyWrapper) => {167 alice = privateKeyWrapper('//Alice');168 bob = privateKeyWrapper('//Bob');169 });170 });171172 it('Regular user cannot create new item in NFT collection', async () => {173 const createMode = 'NFT';174 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});175 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;176 });177 it('Regular user cannot create new item in Fungible collection', async () => {178 const createMode = 'Fungible';179 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});180 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;181 });182 it('Regular user cannot create new item in ReFungible collection', async () => {183 const createMode = 'ReFungible';184 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});185 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;186 });187188 it('No editing rights', async () => {189 await usingApi(async () => {190 const createMode = 'NFT';191 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 192 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});193 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);194195 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);196 });197 });198199 it('User doesnt have editing rights', async () => {200 await usingApi(async () => {201 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});202 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);203 });204 });205206 it('Adding property without access rights', async () => {207 await usingApi(async () => {208 const newCollectionID = await createCollectionWithPropsExpectSuccess();209 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);210211 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);212 });213 });214215 it('Adding more than 64 prps', async () => {216 await usingApi(async () => {217 const prps = [];218219 for (let i = 0; i < 65; i++) {220 prps.push({key: `key${i}`, value: `value${i}`});221 }222223 const newCollectionID = await createCollectionWithPropsExpectSuccess();224 225 await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);226 });227 });228229 it('Trying to add bigger property than allowed', async () => {230 await usingApi(async () => {231 const newCollectionID = await createCollectionWithPropsExpectSuccess();232 233 await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);234 });235 });236});