1234567import {ApiPromise, Keyring} from '@polkadot/api';8import {IKeyringPair} from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';12import {13 createCollectionExpectSuccess,14 destroyCollectionExpectSuccess,15 getCreatedCollectionCount,16 getCreateItemResult,17 getDetailedCollectionInfo,18 addCollectionAdminExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324let alice: IKeyringPair;25let bob: IKeyringPair;26let charlie: IKeyringPair;27282930313233describe('setSchemaVersion positive', () => {34 let tx;35 before(async () => {36 await usingApi(async () => {37 const keyring = new Keyring({type: 'sr25519'});38 alice = keyring.addFromUri('//Alice');39 });40 });41 it('execute setSchemaVersion with image url and unique ', async () => {42 await usingApi(async (api: ApiPromise) => {43 const collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});44 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');45 const events = await submitTransactionAsync(alice, tx);46 const result = getCreateItemResult(events);47 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);48 49 expect(result.success).to.be.true;50 51 expect(collectionInfo).to.be.exist;52 53 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');54 });55 });56});5758describe('Collection admin setSchemaVersion positive', () => {59 let tx;60 let collectionIdForTesting: any;6162 before(async () => {63 await usingApi(async () => {64 const keyring = new Keyring({type: 'sr25519'});65 alice = keyring.addFromUri('//Alice');66 bob = keyring.addFromUri('//Bob');67 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});68 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);69 });70 });71 it('execute setSchemaVersion with image url and unique ', async () => {72 await usingApi(async (api: ApiPromise) => {73 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');74 const events = await submitTransactionAsync(bob, tx);75 const result = getCreateItemResult(events);76 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);77 78 expect(result.success).to.be.true;79 80 expect(collectionInfo).to.be.exist;81 82 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');83 });84 });8586 it('validate schema version with just entered data', async () => {87 await usingApi(async (api: ApiPromise) => {88 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');89 const events = await submitTransactionAsync(bob, tx);90 const result = getCreateItemResult(events);91 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);92 93 expect(result.success).to.be.true;94 95 expect(collectionInfo).to.be.exist;96 97 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('ImageURL');98 });99 });100});101102describe('setSchemaVersion negative', () => {103 let tx;104 let collectionIdForTesting: any;105 before(async () => {106 await usingApi(async () => {107 const keyring = new Keyring({type: 'sr25519'});108 alice = keyring.addFromUri('//Alice');109 charlie = keyring.addFromUri('//Charlie');110 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});111 });112 });113 it('execute setSchemaVersion for not exists collection', async () => {114 await usingApi(async (api: ApiPromise) => {115 const collectionCount = await getCreatedCollectionCount(api);116 const nonExistedCollectionId = collectionCount + 1;117 tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');118 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;119 });120 });121 it('execute setSchemaVersion for deleted collection', async () => {122 await usingApi(async (api: ApiPromise) => {123 await destroyCollectionExpectSuccess(collectionIdForTesting);124 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');125 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;126 });127 });128 it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {129 await usingApi(async (api: ApiPromise) => {130 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');131 await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;132 });133 });134});