123456789101112131415161718import {ApiPromise, Keyring} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';20import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';22import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';23import {24 createCollectionExpectSuccess,25 destroyCollectionExpectSuccess,26 getCreatedCollectionCount,27 getCreateItemResult,28 getDetailedCollectionInfo,29 addCollectionAdminExpectSuccess,30} from './util/helpers';3132chai.use(chaiAsPromised);33const expect = chai.expect;3435let alice: IKeyringPair;36let bob: IKeyringPair;37let charlie: IKeyringPair;38394041424344describe('setSchemaVersion positive', () => {45 let tx;46 before(async () => {47 await usingApi(async () => {48 const keyring = new Keyring({type: 'sr25519'});49 alice = keyring.addFromUri('//Alice');50 });51 });52 it('execute setSchemaVersion with image url and unique ', async () => {53 await usingApi(async (api: ApiPromise) => {54 const collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});55 tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'Unique');56 const events = await submitTransactionAsync(alice, tx);57 const result = getCreateItemResult(events);58 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);59 60 expect(result.success).to.be.true;61 62 expect(collectionInfo).to.be.exist;63 64 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');65 });66 });67});6869describe('Collection admin setSchemaVersion positive', () => {70 let tx;71 let collectionIdForTesting: any;7273 before(async () => {74 await usingApi(async () => {75 const keyring = new Keyring({type: 'sr25519'});76 alice = keyring.addFromUri('//Alice');77 bob = keyring.addFromUri('//Bob');78 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});79 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);80 });81 });82 it('execute setSchemaVersion with image url and unique ', async () => {83 await usingApi(async (api: ApiPromise) => {84 tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'Unique');85 const events = await submitTransactionAsync(bob, tx);86 const result = getCreateItemResult(events);87 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);88 89 expect(result.success).to.be.true;90 91 expect(collectionInfo).to.be.exist;92 93 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');94 });95 });9697 it('validate schema version with just entered data', async () => {98 await usingApi(async (api: ApiPromise) => {99 tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'ImageURL');100 const events = await submitTransactionAsync(bob, tx);101 const result = getCreateItemResult(events);102 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);103 104 expect(result.success).to.be.true;105 106 expect(collectionInfo).to.be.exist;107 108 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('ImageURL');109 });110 });111});112113describe('setSchemaVersion negative', () => {114 let tx;115 let collectionIdForTesting: any;116 before(async () => {117 await usingApi(async () => {118 const keyring = new Keyring({type: 'sr25519'});119 alice = keyring.addFromUri('//Alice');120 charlie = keyring.addFromUri('//Charlie');121 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});122 });123 });124 it('execute setSchemaVersion for not exists collection', async () => {125 await usingApi(async (api: ApiPromise) => {126 const collectionCount = await getCreatedCollectionCount(api);127 const nonExistedCollectionId = collectionCount + 1;128 tx = api.tx.unique.setSchemaVersion(nonExistedCollectionId, 'ImageURL');129 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;130 });131 });132 it('execute setSchemaVersion for deleted collection', async () => {133 await usingApi(async (api: ApiPromise) => {134 await destroyCollectionExpectSuccess(collectionIdForTesting);135 tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'ImageURL');136 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;137 });138 });139 it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {140 await usingApi(async (api: ApiPromise) => {141 tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'Unique');142 await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;143 });144 });145});