1234567891011121314151617import {default as usingApi, executeTransaction} from './substrate/substrate-api';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';21import {22 createCollectionExpectSuccess,23 createItemExpectSuccess,24 addCollectionAdminExpectSuccess,25 createCollectionWithPropsExpectSuccess,26} from './util/helpers';2728const expect = chai.expect;29let alice: IKeyringPair;30let bob: IKeyringPair;3132describe('integration test: ext. createItem():', () => {33 before(async () => {34 await usingApi(async () => {35 const keyring = new Keyring({type: 'sr25519'});36 alice = keyring.addFromUri('//Alice');37 bob = keyring.addFromUri('//Bob');38 });39 });4041 it('Create new item in NFT collection', async () => {42 const createMode = 'NFT';43 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});44 await createItemExpectSuccess(alice, newCollectionID, createMode);45 });46 it('Create new item in Fungible collection', async () => {47 const createMode = 'Fungible';48 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});49 await createItemExpectSuccess(alice, newCollectionID, createMode);50 });51 it('Create new item in ReFungible collection', async () => {52 const createMode = 'ReFungible';53 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});54 await createItemExpectSuccess(alice, newCollectionID, createMode);55 });56 it('Create new item in NFT collection with collection admin permissions', async () => {57 const createMode = 'NFT';58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);60 await createItemExpectSuccess(bob, newCollectionID, createMode);61 });62 it('Create new item in Fungible collection with collection admin permissions', async () => {63 const createMode = 'Fungible';64 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});65 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);66 await createItemExpectSuccess(bob, newCollectionID, createMode);67 });68 it('Create new item in ReFungible collection with collection admin permissions', async () => {69 const createMode = 'ReFungible';70 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});71 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);72 await createItemExpectSuccess(bob, newCollectionID, createMode);73 });7475 it('Set property Admin', async () => {76 const createMode = 'NFT';77 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 properties: [{key: 'key1', value: 'val1'}], 79 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});80 81 await createItemExpectSuccess(alice, newCollectionID, createMode);82 });8384 it('Set property AdminConst', async () => {85 const createMode = 'NFT';86 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87 properties: [{key: 'key1', value: 'val1'}], 88 propPerm: [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});89 90 await createItemExpectSuccess(alice, newCollectionID, createMode);91 });9293 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 96 properties: [{key: 'key1', value: 'val1'}], 97 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});98 99 await createItemExpectSuccess(alice, newCollectionID, createMode);100 });101});102103describe('Negative integration test: ext. createItem():', () => {104 before(async () => {105 await usingApi(async () => {106 const keyring = new Keyring({type: 'sr25519'});107 alice = keyring.addFromUri('//Alice');108 bob = keyring.addFromUri('//Bob');109 });110 });111112 it('Regular user cannot create new item in NFT collection', async () => {113 const createMode = 'NFT';114 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});115 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;116 });117 it('Regular user cannot create new item in Fungible collection', async () => {118 const createMode = 'Fungible';119 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});120 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;121 });122 it('Regular user cannot create new item in ReFungible collection', async () => {123 const createMode = 'ReFungible';124 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});125 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;126 });127128 it('No editing rights', async () => {129 await usingApi(async api => {130 const createMode = 'NFT';131 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 132 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});133134 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');135 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);136137 await expect(executeTransaction(138 api, 139 alice, 140 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 141 )).to.be.rejected;142 });143 });144145 it('User doesnt have editing rights', async () => {146 await usingApi(async api => {147 const createMode = 'NFT';148 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});149 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');150151 await expect(executeTransaction(152 api, 153 bob, 154 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 155 )).to.be.rejected;156 });157 });158159 it('Adding property without access rights', async () => {160 await usingApi(async api => {161 const createMode = 'NFT';162 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});163164 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');165 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);166 167 await expect(executeTransaction(168 api, 169 bob, 170 api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 171 )).to.be.rejected;172 });173 });174175 it('Adding more than 64 prps', async () => {176 await usingApi(async api => {177 const createMode = 'NFT';178179 const prps = [];180181 for (let i = 0; i < 65; i++) {182 prps.push({key: `key${i}`, value: `value${i}`});183 }184185 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});186 187 await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);188 });189 });190191 it('Trying to add bigger property than allowed', async () => {192 await usingApi(async api => {193 const createMode = 'NFT';194 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});195 196 await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]))).to.be.rejectedWith(/common\.NoSpaceForProperty/);197 });198 });199});