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} from './util/helpers';2829const expect = chai.expect;30let alice: IKeyringPair;31let bob: IKeyringPair;3233describe('integration test: ext. ():', () => {34 before(async () => {35 await usingApi(async (api, privateKeyWrapper) => {36 alice = privateKeyWrapper('//Alice');37 bob = privateKeyWrapper('//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 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});79 80 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);81 });8283 it('Set property AdminConst', async () => {84 const createMode = 'NFT';85 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 86 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});87 88 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);89 });9091 it('Set property itemOwnerOrAdmin', async () => {92 const createMode = 'NFT';93 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},94 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});95 96 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);97 });98});99100describe('Negative integration test: ext. createItem():', () => {101 before(async () => {102 await usingApi(async (api, privateKeyWrapper) => {103 alice = privateKeyWrapper('//Alice');104 bob = privateKeyWrapper('//Bob');105 });106 });107108 it('Regular user cannot create new item in NFT collection', async () => {109 const createMode = 'NFT';110 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});111 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;112 });113 it('Regular user cannot create new item in Fungible collection', async () => {114 const createMode = 'Fungible';115 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});116 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;117 });118 it('Regular user cannot create new item in ReFungible collection', async () => {119 const createMode = 'ReFungible';120 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});121 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;122 });123124 it('No editing rights', async () => {125 await usingApi(async () => {126 const createMode = 'NFT';127 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 128 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});129 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);130131 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);132 });133 });134135 it('User doesnt have editing rights', async () => {136 await usingApi(async () => {137 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});138 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);139 });140 });141142 it('Adding property without access rights', async () => {143 await usingApi(async () => {144 const newCollectionID = await createCollectionWithPropsExpectSuccess();145 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);146147 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);148 });149 });150151 it('Adding more than 64 prps', async () => {152 await usingApi(async () => {153 const prps = [];154155 for (let i = 0; i < 65; i++) {156 prps.push({key: `key${i}`, value: `value${i}`});157 }158159 const newCollectionID = await createCollectionWithPropsExpectSuccess();160 161 await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);162 });163 });164165 it('Trying to add bigger property than allowed', async () => {166 await usingApi(async () => {167 const newCollectionID = await createCollectionWithPropsExpectSuccess();168 169 await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);170 });171 });172});