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 createItemWithPropsExpectSuccess,27 createItemWithPropsExpectFailure,28} from './util/helpers';2930const expect = chai.expect;31let alice: IKeyringPair;32let bob: IKeyringPair;3334describe('integration test: ext. ():', () => {35 before(async () => {36 await usingApi(async () => {37 const keyring = new Keyring({type: 'sr25519'});38 alice = keyring.addFromUri('//Alice');39 bob = keyring.addFromUri('//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 });100});101102describe('Negative integration test: ext. createItem():', () => {103 before(async () => {104 await usingApi(async () => {105 const keyring = new Keyring({type: 'sr25519'});106 alice = keyring.addFromUri('//Alice');107 bob = keyring.addFromUri('//Bob');108 });109 });110111 it('Regular user cannot create new item in NFT collection', async () => {112 const createMode = 'NFT';113 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});114 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;115 });116 it('Regular user cannot create new item in Fungible collection', async () => {117 const createMode = 'Fungible';118 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});119 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;120 });121 it('Regular user cannot create new item in ReFungible collection', async () => {122 const createMode = 'ReFungible';123 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});124 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;125 });126127 it('No editing rights', async () => {128 await usingApi(async api => {129 const createMode = 'NFT';130 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 131 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});132 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);133134 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);135 });136 });137138 it('User doesnt have editing rights', async () => {139 await usingApi(async api => {140 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});141 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);142 });143 });144145 it('Adding property without access rights', async () => {146 await usingApi(async api => {147 const newCollectionID = await createCollectionWithPropsExpectSuccess();148 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);149150 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);151 });152 });153154 it('Adding more than 64 prps', async () => {155 await usingApi(async api => {156 const prps = [];157158 for (let i = 0; i < 65; i++) {159 prps.push({key: `key${i}`, value: `value${i}`});160 }161162 const newCollectionID = await createCollectionWithPropsExpectSuccess();163 164 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);165 });166 });167168 it('Trying to add bigger property than allowed', async () => {169 await usingApi(async api => {170 const newCollectionID = await createCollectionWithPropsExpectSuccess();171 172 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);173 });174 });175});