difftreelog
CORE-160. Collection admin integration tests
in: master
23 files changed
tests/src/addToWhiteList.test.tsdiffbeforeafterboth16 enablePublicMintingExpectSuccess,16 enablePublicMintingExpectSuccess,17 enableWhiteListExpectSuccess,17 enableWhiteListExpectSuccess,18 normalizeAccountId,18 normalizeAccountId,19 addCollectionAdminExpectSuccess,19} from './util/helpers';20} from './util/helpers';202121chai.use(chaiAsPromised);22chai.use(chaiAsPromised);22const expect = chai.expect;23const expect = chai.expect;232424let Alice: IKeyringPair;25let Alice: IKeyringPair;25let Bob: IKeyringPair;26let Bob: IKeyringPair;27let Charlie: IKeyringPair;262827describe('Integration Test ext. addToWhiteList()', () => {29describe('Integration Test ext. addToWhiteList()', () => {2830868887});89});889091describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {9293 before(async () => {94 await usingApi(async () => {95 Alice = privateKey('//Alice');96 Bob = privateKey('//Bob');97 Charlie = privateKey('//Charlie');98 });99 });100101 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {102 const collectionId = await createCollectionExpectSuccess();103 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);104 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);105 });106107 it('Whitelisted minting: list restrictions', async () => {108 const collectionId = await createCollectionExpectSuccess();109 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);110 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);111112 // allowed only for collection owner113 await enableWhiteListExpectSuccess(Alice, collectionId);114 await enablePublicMintingExpectSuccess(Alice, collectionId);115116 await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);117 });118});tests/src/approve.test.tsdiffbeforeafterboth16 destroyCollectionExpectSuccess,16 destroyCollectionExpectSuccess,17 setCollectionLimitsExpectSuccess,17 setCollectionLimitsExpectSuccess,18 transferExpectSuccess,18 transferExpectSuccess,19 addCollectionAdminExpectSuccess,19} from './util/helpers';20} from './util/helpers';202121chai.use(chaiAsPromised);22chai.use(chaiAsPromised);178 });179 });179});180});181182describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {183 let Alice: IKeyringPair;184 let Bob: IKeyringPair;185 let Charlie: IKeyringPair;186187 before(async () => {188 await usingApi(async () => {189 Alice = privateKey('//Alice');190 Bob = privateKey('//Bob');191 Charlie = privateKey('//Charlie');192 });193 });194195 it('can be called by collection admin on non-owned item', async () => {196 const collectionId = await createCollectionExpectSuccess();197 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);198199 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);200 await approveExpectSuccess(collectionId, itemId, Bob, Charlie);201 });202});180203tests/src/burnItem.test.tsdiffbeforeafterboth12 getGenericResult,12 getGenericResult,13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 normalizeAccountId,14 normalizeAccountId,15 addCollectionAdminExpectSuccess,15} from './util/helpers';16} from './util/helpers';161717import chai from 'chai';18import chai from 'chai';136136137});137});138139describe('integration test: ext. burnItem() with admin permissions:', () => {140 before(async () => {141 await usingApi(async () => {142 const keyring = new Keyring({ type: 'sr25519' });143 alice = keyring.addFromUri('//Alice');144 bob = keyring.addFromUri('//Bob');145 });146 });147148 it('Burn item in NFT collection', async () => {149 const createMode = 'NFT';150 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});151 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);152 await addCollectionAdminExpectSuccess(alice, collectionId, bob);153154 await usingApi(async (api) => {155 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);156 const events = await submitTransactionAsync(bob, tx);157 const result = getGenericResult(events);158 // Get the item159 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();160 // What to expect161 // tslint:disable-next-line:no-unused-expression162 expect(result.success).to.be.true;163 // tslint:disable-next-line:no-unused-expression164 expect(item).to.be.null;165 });166 });167});138168139describe('Negative integration test: ext. burnItem():', () => {169describe('Negative integration test: ext. burnItem():', () => {140 before(async () => {170 before(async () => {tests/src/change-collection-owner.test.tsdiffbeforeafterboth7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';8import privateKey from './substrate/privateKey';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import { createCollectionExpectSuccess } from './util/helpers';10import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';111112chai.use(chaiAsPromised);12chai.use(chaiAsPromised);13const expect = chai.expect;13const expect = chai.expect;49 });49 });50 });50 });5152 it('Collection admin can\'t change owner.', async () => {53 await usingApi(async api => {54 const collectionId = await createCollectionExpectSuccess();55 const alice = privateKey('//Alice');56 const bob = privateKey('//Bob');5758 await addCollectionAdminExpectSuccess(alice, collectionId, bob);5960 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);61 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;6263 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();64 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);6566 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)67 await createCollectionExpectSuccess();68 });69 });7051 it('Can\'t change owner of a non-existing collection.', async () => {71 it('Can\'t change owner of a non-existing collection.', async () => {52 await usingApi(async api => {72 await usingApi(async api => {tests/src/confirmSponsorship.test.tsdiffbeforeafterboth19 enablePublicMintingExpectSuccess,19 enablePublicMintingExpectSuccess,20 addToWhiteListExpectSuccess,20 addToWhiteListExpectSuccess,21 normalizeAccountId,21 normalizeAccountId,22 addCollectionAdminExpectSuccess,22} from './util/helpers';23} from './util/helpers';23import { Keyring } from '@polkadot/api';24import { Keyring } from '@polkadot/api';24import { IKeyringPair } from '@polkadot/types/types';25import { IKeyringPair } from '@polkadot/types/types';365 await confirmSponsorshipExpectFailure(collectionId, '//Alice');366 await confirmSponsorshipExpectFailure(collectionId, '//Alice');366 });367 });368369 it('(!negative test!) Confirm sponsorship by collection admin', async () => {370 const collectionId = await createCollectionExpectSuccess();371 await setCollectionSponsorExpectSuccess(collectionId, bob.address);372 await addCollectionAdminExpectSuccess(alice, collectionId, charlie);373 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');374 });367375368 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {376 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {369 const collectionId = await createCollectionExpectSuccess();377 const collectionId = await createCollectionExpectSuccess();tests/src/createItem.test.tsdiffbeforeafterboth4//4//556import { default as usingApi } from './substrate/substrate-api';6import { default as usingApi } from './substrate/substrate-api';7import chai from 'chai';7import { Keyring } from '@polkadot/api';8import { Keyring } from '@polkadot/api';8import { IKeyringPair } from '@polkadot/types/types';9import { IKeyringPair } from '@polkadot/types/types';9import { 10import { 10 createCollectionExpectSuccess, 11 createCollectionExpectSuccess, 11 createItemExpectSuccess,12 createItemExpectSuccess,13 addCollectionAdminExpectSuccess,12} from './util/helpers';14} from './util/helpers';131516const expect = chai.expect;14let alice: IKeyringPair;17let alice: IKeyringPair;18let bob: IKeyringPair;151916describe('integration test: ext. createItem():', () => {20describe('integration test: ext. createItem():', () => {17 before(async () => {21 before(async () => {18 await usingApi(async () => {22 await usingApi(async () => {19 const keyring = new Keyring({ type: 'sr25519' });23 const keyring = new Keyring({ type: 'sr25519' });20 alice = keyring.addFromUri('//Alice');24 alice = keyring.addFromUri('//Alice');25 bob = keyring.addFromUri('//Bob');21 });26 });22 });27 });232836 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});41 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});37 await createItemExpectSuccess(alice, newCollectionID, createMode);42 await createItemExpectSuccess(alice, newCollectionID, createMode);38 });43 });44 it('Create new item in NFT collection with collection admin permissions', async () => {45 const createMode = 'NFT';46 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});47 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);48 await createItemExpectSuccess(bob, newCollectionID, createMode);49 });50 it('Create new item in Fungible collection with collection admin permissions', async () => {51 const createMode = 'Fungible';52 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});53 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);54 await createItemExpectSuccess(bob, newCollectionID, createMode);55 });56 it('Create new item in ReFungible collection with collection admin permissions', async () => {57 const createMode = 'ReFungible';58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);60 await createItemExpectSuccess(bob, newCollectionID, createMode);61 });39});62});6364describe('Negative integration test: ext. createItem():', () => {65 before(async () => {66 await usingApi(async () => {67 const keyring = new Keyring({ type: 'sr25519' });68 alice = keyring.addFromUri('//Alice');69 bob = keyring.addFromUri('//Bob');70 });71 });7273 it('Regular user cannot create new item in NFT collection', async () => {74 const createMode = 'NFT';75 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});76 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;77 });78 it('Regular user cannot create new item in Fungible collection', async () => {79 const createMode = 'Fungible';80 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});81 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;82 });83 it('Regular user cannot create new item in ReFungible collection', async () => {84 const createMode = 'ReFungible';85 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});86 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;87 });88});4089tests/src/createMultipleItems.test.tsdiffbeforeafterboth3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.4//4//5import { ApiPromise } from '@polkadot/api';5import { ApiPromise } from '@polkadot/api';6import { IKeyringPair } from '@polkadot/types/types';6import BN from 'bn.js';7import BN from 'bn.js';7import chai from 'chai';8import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import chaiAsPromised from 'chai-as-promised';12 createCollectionExpectSuccess,13 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 destroyCollectionExpectSuccess,14 getGenericResult,15 getGenericResult,16 IFungibleTokenDataType,15 IReFungibleTokenDataType,17 IReFungibleTokenDataType,16 normalizeAccountId,18 normalizeAccountId,17 setCollectionLimitsExpectSuccess,19 setCollectionLimitsExpectSuccess,20 addCollectionAdminExpectSuccess,18} from './util/helpers';21} from './util/helpers';192220chai.use(chaiAsPromised);23chai.use(chaiAsPromised);57 });60 });58 });61 });596263 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {64 await usingApi(async (api: ApiPromise) => {65 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});66 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;67 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);68 const Alice = privateKey('//Alice');69 const args = [70 {fungible: { value: 1 }},71 {fungible: { value: 2 }},72 {fungible: { value: 3 }},73 ];74 const createMultipleItemsTx = api.tx.nft75 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);76 await submitTransactionAsync(Alice, createMultipleItemsTx);77 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;7879 expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 380 });81 });8260 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {83 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {61 await usingApi(async (api: ApiPromise) => {84 await usingApi(async (api: ApiPromise) => {62 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});85 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});116 });139 });117});140});118141142describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {143144 let Alice: IKeyringPair;145 let Bob: IKeyringPair;146147 before(async () => {148 await usingApi(async () => {149 Alice = privateKey('//Alice');150 Bob = privateKey('//Bob');151 });152 });153154 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {155 await usingApi(async (api: ApiPromise) => {156 const collectionId = await createCollectionExpectSuccess();157 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;158 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);159 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob); 160 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];161 const createMultipleItemsTx = api.tx.nft162 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);163 await submitTransactionAsync(Bob, createMultipleItemsTx);164 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;165 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);166 const token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;167 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;168 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;169170 expect(token1Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));171 expect(token2Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));172 expect(token3Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));173174 expect(token1Data.ConstData.toString()).to.be.equal('0x31');175 expect(token2Data.ConstData.toString()).to.be.equal('0x32');176 expect(token3Data.ConstData.toString()).to.be.equal('0x33');177178 expect(token1Data.VariableData.toString()).to.be.equal('0x31');179 expect(token2Data.VariableData.toString()).to.be.equal('0x32');180 expect(token3Data.VariableData.toString()).to.be.equal('0x33');181 });182 });183184 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {185 await usingApi(async (api: ApiPromise) => {186 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});187 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;188 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);189 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob); 190 const args = [191 {fungible: { value: 1 }},192 {fungible: { value: 2 }},193 {fungible: { value: 3 }},194 ];195 const createMultipleItemsTx = api.tx.nft196 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);197 await submitTransactionAsync(Bob, createMultipleItemsTx);198 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;199200 expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 3201 });202 });203204 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {205 await usingApi(async (api: ApiPromise) => {206 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});207 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;208 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);209 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob); 210 const args = [211 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},212 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},213 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},214 ];215 const createMultipleItemsTx = api.tx.nft216 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);217 await submitTransactionAsync(Bob, createMultipleItemsTx);218 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;219 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);220 const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).toJSON() as unknown as IReFungibleTokenDataType;221 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;222 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;223224 expect(token1Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));225 expect(token1Data.Owner[0].Fraction).to.be.equal(1);226227 expect(token2Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));228 expect(token2Data.Owner[0].Fraction).to.be.equal(1);229230 expect(token3Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));231 expect(token3Data.Owner[0].Fraction).to.be.equal(1);232233 expect(token1Data.ConstData.toString()).to.be.equal('0x31');234 expect(token2Data.ConstData.toString()).to.be.equal('0x32');235 expect(token3Data.ConstData.toString()).to.be.equal('0x33');236237 expect(token1Data.VariableData.toString()).to.be.equal('0x31');238 expect(token2Data.VariableData.toString()).to.be.equal('0x32');239 expect(token3Data.VariableData.toString()).to.be.equal('0x33');240 });241 });242});243119describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {244describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {245246 let Alice: IKeyringPair;247 let Bob: IKeyringPair;248249 before(async () => {250 await usingApi(async () => {251 Alice = privateKey('//Alice');252 Bob = privateKey('//Bob');253 });254 });255256 it('Regular user cannot create items in active NFT collection', async () => {257 await usingApi(async (api: ApiPromise) => {258 const collectionId = await createCollectionExpectSuccess();259 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;260 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);261 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];262 const createMultipleItemsTx = api.tx.nft263 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);264 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;265 });266 });267268 it('Regular user cannot create items in active Fungible collection', async () => {269 await usingApi(async (api: ApiPromise) => {270 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});271 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;272 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);273 const args = [274 {fungible: { value: 1 }},275 {fungible: { value: 2 }},276 {fungible: { value: 3 }},277 ];278 const createMultipleItemsTx = api.tx.nft279 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);280 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;281 });282 });283284 it('Regular user cannot create items in active ReFungible collection', async () => {285 await usingApi(async (api: ApiPromise) => {286 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});287 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;288 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);289 const args = [290 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},291 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},292 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},293 ];294 const createMultipleItemsTx = api.tx.nft295 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);296 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;297 });298 });299120 it('Create token with not existing type', async () => {300 it('Create token with not existing type', async () => {121 await usingApi(async (api: ApiPromise) => {301 await usingApi(async (api: ApiPromise) => {122 const collectionId = await createCollectionExpectSuccess();302 const collectionId = await createCollectionExpectSuccess();123 const Alice = privateKey('//Alice');124 try {303 try {125 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];304 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];126 const createMultipleItemsTx = await api.tx.nft305 const createMultipleItemsTx = await api.tx.nft136 it('Create token in not existing collection', async () => {315 it('Create token in not existing collection', async () => {137 await usingApi(async (api: ApiPromise) => {316 await usingApi(async (api: ApiPromise) => {138 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;317 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;139 const Alice = privateKey('//Alice');140 const createMultipleItemsTx = api.tx.nft318 const createMultipleItemsTx = api.tx.nft141 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'NFT', 'NFT']);319 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'NFT', 'NFT']);142 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;320 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;174 it('Create tokens with different types', async () => {352 it('Create tokens with different types', async () => {175 await usingApi(async (api: ApiPromise) => {353 await usingApi(async (api: ApiPromise) => {176 const collectionId = await createCollectionExpectSuccess();354 const collectionId = await createCollectionExpectSuccess();177 const Alice = privateKey('//Alice');178 const createMultipleItemsTx = api.tx.nft355 const createMultipleItemsTx = api.tx.nft179 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'Fungible', 'ReFungible']);356 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'Fungible', 'ReFungible']);180 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;357 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;186 it('Create tokens with different data limits <> maximum data limit', async () => {363 it('Create tokens with different data limits <> maximum data limit', async () => {187 await usingApi(async (api: ApiPromise) => {364 await usingApi(async (api: ApiPromise) => {188 const collectionId = await createCollectionExpectSuccess();365 const collectionId = await createCollectionExpectSuccess();189 const Alice = privateKey('//Alice');190 const args = [366 const args = [191 { nft: ['A', 'A'] },367 { nft: ['A', 'A'] },192 { nft: ['B', 'B'.repeat(2049)] },368 { nft: ['B', 'B'.repeat(2049)] },200376201 it('Fails when minting tokens exceeds collectionLimits amount', async () => {377 it('Fails when minting tokens exceeds collectionLimits amount', async () => {202 await usingApi(async (api) => {378 await usingApi(async (api) => {203 const alice = privateKey('//Alice');204379205 const collectionId = await createCollectionExpectSuccess();380 const collectionId = await createCollectionExpectSuccess();206 await setCollectionLimitsExpectSuccess(alice, collectionId, {381 await setCollectionLimitsExpectSuccess(Alice, collectionId, {207 TokenLimit: 1,382 TokenLimit: 1,208 });383 });209 const args = [384 const args = [210 { nft: ['A', 'A'] },385 { nft: ['A', 'A'] },211 { nft: ['B', 'B'] },386 { nft: ['B', 'B'] },212 ];387 ];213 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);388 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);214 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;389 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;215 });390 });216 });391 });217});392});tests/src/destroyCollection.test.tsdiffbeforeafterboth11import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure, setCollectionLimitsExpectSuccess } from './util/helpers';11import { createCollectionExpectSuccess, 12 destroyCollectionExpectSuccess, 13 destroyCollectionExpectFailure, 14 setCollectionLimitsExpectSuccess,15 addCollectionAdminExpectSuccess,16} from './util/helpers';121713chai.use(chaiAsPromised);18chai.use(chaiAsPromised);293430describe('(!negative test!) integration test: ext. destroyCollection():', () => {35describe('(!negative test!) integration test: ext. destroyCollection():', () => {31 let alice: IKeyringPair;36 let alice: IKeyringPair;37 let bob: IKeyringPair;323833 before(async () => {39 before(async () => {34 await usingApi(async () => {40 await usingApi(async () => {35 alice = privateKey('//Alice');41 alice = privateKey('//Alice');42 bob = privateKey('//Bob');36 });43 });37 });44 });384553 await destroyCollectionExpectFailure(collectionId, '//Bob');60 await destroyCollectionExpectFailure(collectionId, '//Bob');54 await destroyCollectionExpectSuccess(collectionId, '//Alice');61 await destroyCollectionExpectSuccess(collectionId, '//Alice');55 });62 });63 it('(!negative test!) Destroy a collection using collection admin account', async () => {64 const collectionId = await createCollectionExpectSuccess();65 await addCollectionAdminExpectSuccess(alice, collectionId, bob);66 await destroyCollectionExpectFailure(collectionId, '//Bob');67 });56 it('fails when OwnerCanDestroy == false', async () => {68 it('fails when OwnerCanDestroy == false', async () => {57 const collectionId = await createCollectionExpectSuccess();69 const collectionId = await createCollectionExpectSuccess();58 await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });70 await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth84 });84 });85 });85 });8687 it('Regular user Can\'t remove collection admin', async () => {88 await usingApi(async (api: ApiPromise) => {89 const collectionId = await createCollectionExpectSuccess();90 const Alice = privateKey('//Alice');91 const Bob = privateKey('//Bob');92 const Charlie = privateKey('//Charlie');9394 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));95 await submitTransactionAsync(Alice, addAdminTx);9697 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));98 await expect(submitTransactionExpectFailAsync(Charlie, changeOwnerTx)).to.be.rejected;99100 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)101 await createCollectionExpectSuccess();102 });103 });86});104});87105tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth17 removeCollectionSponsorExpectSuccess,17 removeCollectionSponsorExpectSuccess,18 removeCollectionSponsorExpectFailure,18 removeCollectionSponsorExpectFailure,19 normalizeAccountId,19 normalizeAccountId,20 addCollectionAdminExpectSuccess,20} from './util/helpers';21} from './util/helpers';21import { Keyring } from '@polkadot/api';22import { Keyring } from '@polkadot/api';22import { IKeyringPair } from '@polkadot/types/types';23import { IKeyringPair } from '@polkadot/types/types';104 await removeCollectionSponsorExpectFailure(collectionId);105 await removeCollectionSponsorExpectFailure(collectionId);105 });106 });107108 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {109 const collectionId = await createCollectionExpectSuccess();110 await setCollectionSponsorExpectSuccess(collectionId, bob.address);111 await addCollectionAdminExpectSuccess(alice, collectionId, bob);112 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');113 });106114107 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {115 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {108 const collectionId = await createCollectionExpectSuccess();116 const collectionId = await createCollectionExpectSuccess();tests/src/removeFromWhiteList.test.tsdiffbeforeafterboth17 removeFromWhiteListExpectFailure,17 removeFromWhiteListExpectFailure,18 disableWhiteListExpectSuccess,18 disableWhiteListExpectSuccess,19 normalizeAccountId,19 normalizeAccountId,20 addCollectionAdminExpectSuccess,20} from './util/helpers';21} from './util/helpers';21import { IKeyringPair } from '@polkadot/types/types';22import { IKeyringPair } from '@polkadot/types/types';22import privateKey from './substrate/privateKey';23import privateKey from './substrate/privateKey';89 });90 });90});91});919293describe('Integration Test removeFromWhiteList with collection admin permissions', () => {94 let alice: IKeyringPair;95 let bob: IKeyringPair;96 let charlie: IKeyringPair;9798 before(async () => {99 await usingApi(async () => {100 alice = privateKey('//Alice');101 bob = privateKey('//Bob');102 charlie = privateKey('//Charlie');103 });104 });105106 it('ensure address is not in whitelist after removal', async () => {107 await usingApi(async () => {108 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });109 await enableWhiteListExpectSuccess(alice, collectionId);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob);111 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);112 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));113 expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;114 });115 });116117 it('Collection admin allowed to remove from whitelist with unset whitelist status', async () => {118 await usingApi(async () => {119 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();120 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);121 await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob);122 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);123 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);124 await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));125 });126 });127});tests/src/setChainLimits.test.tsdiffbeforeafterbothno changes
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth16 getDetailedCollectionInfo,16 getDetailedCollectionInfo,17 setCollectionLimitsExpectFailure,17 setCollectionLimitsExpectFailure,18 setCollectionLimitsExpectSuccess,18 setCollectionLimitsExpectSuccess,19 addCollectionAdminExpectSuccess,19} from './util/helpers';20} from './util/helpers';202121chai.use(chaiAsPromised);22chai.use(chaiAsPromised);150 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;151 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;151 });152 });152 });153 });154 it('execute setCollectionLimits from admin collection', async () => {155 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);156 await usingApi(async (api: ApiPromise) => {157 tx = api.tx.nft.setCollectionLimits(158 collectionIdForTesting,159 {160 accountTokenOwnershipLimit,161 sponsoredDataSize,162 sponsoredMintSize,163 tokenLimit,164 },165 );166 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;167 });168 });153 it('execute setCollectionLimits with incorrect limits', async () => {169 it('execute setCollectionLimits with incorrect limits', async () => {154 await usingApi(async (api: ApiPromise) => {170 await usingApi(async (api: ApiPromise) => {155 tx = api.tx.nft.setCollectionLimits(171 tx = api.tx.nft.setCollectionLimits(tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth9import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from './util/helpers';9import { createCollectionExpectSuccess, 10 setCollectionSponsorExpectSuccess, 11 destroyCollectionExpectSuccess, 12 setCollectionSponsorExpectFailure,13 addCollectionAdminExpectSuccess,14} from './util/helpers';10import { Keyring } from '@polkadot/api';15import { Keyring } from '@polkadot/api';11import { IKeyringPair } from '@polkadot/types/types';16import { IKeyringPair } from '@polkadot/types/types';121713chai.use(chaiAsPromised);18chai.use(chaiAsPromised);141920let alice: IKeyringPair;15let bob: IKeyringPair;21let bob: IKeyringPair;22let charlie: IKeyringPair;162317describe('integration test: ext. setCollectionSponsor():', () => {24describe('integration test: ext. setCollectionSponsor():', () => {182519 before(async () => {26 before(async () => {20 await usingApi(async () => {27 await usingApi(async () => {21 const keyring = new Keyring({ type: 'sr25519' });28 const keyring = new Keyring({ type: 'sr25519' });29 alice = keyring.addFromUri('//Alice');22 bob = keyring.addFromUri('//Bob');30 bob = keyring.addFromUri('//Bob');23 });31 });24 });32 });55 before(async () => {63 before(async () => {56 await usingApi(async () => {64 await usingApi(async () => {57 const keyring = new Keyring({ type: 'sr25519' });65 const keyring = new Keyring({ type: 'sr25519' });66 alice = keyring.addFromUri('//Alice');58 bob = keyring.addFromUri('//Bob');67 bob = keyring.addFromUri('//Bob');68 charlie = keyring.addFromUri('//Charlie');59 });69 });60 });70 });617177 await destroyCollectionExpectSuccess(collectionId);87 await destroyCollectionExpectSuccess(collectionId);78 await setCollectionSponsorExpectFailure(collectionId, bob.address);88 await setCollectionSponsorExpectFailure(collectionId, bob.address);79 });89 });90 it('(!negative test!) Collection admin add sponsor', async () => {91 const collectionId = await createCollectionExpectSuccess();92 await addCollectionAdminExpectSuccess(alice, collectionId, bob);93 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');94 });80});95});8196tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth11import {11import {12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 addCollectionAdminExpectSuccess,14} from './util/helpers';15} from './util/helpers';151616chai.use(chaiAsPromised);17chai.use(chaiAsPromised);43 });44 });44 });45 });4647 it('Collection admin can set the scheme', async () => {48 await usingApi(async (api) => {49 const collectionId = await createCollectionExpectSuccess();50 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();51 expect(collection.Owner).to.be.eq(Alice.address);52 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);54 await submitTransactionAsync(Bob, setShema);55 });56 });455746 it('Checking collection data using the ConstOnChainSchema parameter', async () => {58 it('Checking collection data using the ConstOnChainSchema parameter', async () => {47 await usingApi(async (api) => {59 await usingApi(async (api) => {tests/src/setMintPermission.test.tsdiffbeforeafterboth16 findNotExistingCollection,16 findNotExistingCollection,17 setMintPermissionExpectFailure,17 setMintPermissionExpectFailure,18 setMintPermissionExpectSuccess,18 setMintPermissionExpectSuccess,19 addCollectionAdminExpectSuccess,19} from './util/helpers';20} from './util/helpers';202121describe('Integration Test setMintPermission', () => {22describe('Integration Test setMintPermission', () => {91 await setMintPermissionExpectFailure(bob, collectionId, true);92 await setMintPermissionExpectFailure(bob, collectionId, true);92 });93 });9495 it('Collection admin fails on set', async () => {96 await usingApi(async () => {97 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });98 await addCollectionAdminExpectSuccess(alice, collectionId, bob);99 await setMintPermissionExpectFailure(bob, collectionId, true);100 });101 });9310294 it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {103 it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {95 await usingApi(async () => {104 await usingApi(async () => {tests/src/setOffchainSchema.test.tsdiffbeforeafterboth15 queryCollectionExpectSuccess,15 queryCollectionExpectSuccess,16 setOffchainSchemaExpectFailure,16 setOffchainSchemaExpectFailure,17 setOffchainSchemaExpectSuccess,17 setOffchainSchemaExpectSuccess,18 addCollectionAdminExpectSuccess,18} from './util/helpers';19} from './util/helpers';192020chai.use(chaiAsPromised);21chai.use(chaiAsPromised);242525describe('Integration Test setOffchainSchema', () => {26describe('Integration Test setOffchainSchema', () => {26 let alice: IKeyringPair;27 let alice: IKeyringPair;28 let bob: IKeyringPair;272928 before(async () => {30 before(async () => {29 await usingApi(async () => {31 await usingApi(async () => {30 alice = privateKey('//Alice');32 alice = privateKey('//Alice');33 bob = privateKey('//Bob');31 });34 });32 });35 });333639 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));42 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));40 });43 });4445 it('execute setOffchainSchema (collection admin), verify data was set', async () => {46 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });47 await addCollectionAdminExpectSuccess(alice, collectionId, bob);48 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);49 const collection = await queryCollectionExpectSuccess(collectionId);5051 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));52 });41});53});425443describe('Negative Integration Test setOffchainSchema', () => {55describe('Negative Integration Test setOffchainSchema', () => {tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth18 enablePublicMintingExpectSuccess,18 enablePublicMintingExpectSuccess,19 enableWhiteListExpectSuccess,19 enableWhiteListExpectSuccess,20 normalizeAccountId,20 normalizeAccountId,21 addCollectionAdminExpectSuccess,21} from './util/helpers';22} from './util/helpers';222323chai.use(chaiAsPromised);24chai.use(chaiAsPromised);93 });94 });94});95});9697describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {98 before(async () => {99 await usingApi(async () => {100 Alice = privateKey('//Alice');101 Bob = privateKey('//Bob');102 });103 });104 it('Set the collection that has been deleted', async () => {105 await usingApi(async (api: ApiPromise) => {106 // tslint:disable-next-line: no-bitwise107 const collectionId = await createCollectionExpectSuccess();108 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);109 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');110 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;111 });112 });113});95114tests/src/setSchemaVersion.test.tsdiffbeforeafterboth16 getCreatedCollectionCount,16 getCreatedCollectionCount,17 getCreateItemResult,17 getCreateItemResult,18 getDetailedCollectionInfo,18 getDetailedCollectionInfo,19 addCollectionAdminExpectSuccess,19} from './util/helpers';20} from './util/helpers';202121chai.use(chaiAsPromised);22chai.use(chaiAsPromised);22const expect = chai.expect;23const expect = chai.expect;232424let alice: IKeyringPair;25let alice: IKeyringPair;26let bob: IKeyringPair;25let collectionIdForTesting: number;27let collectionIdForTesting: number;262827/*29/*44 });46 });45});47});4849describe('setSchemaVersion positive', () => {50 let tx;51 before(async () => {52 await usingApi(async () => {53 const keyring = new Keyring({ type: 'sr25519' });54 alice = keyring.addFromUri('//Alice');55 });56 });57 it('execute setSchemaVersion with image url and unique ', async () => {58 await usingApi(async (api: ApiPromise) => {59 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');60 const events = await submitTransactionAsync(alice, tx);61 const result = getCreateItemResult(events);62 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;63 // tslint:disable-next-line:no-unused-expression64 expect(result.success).to.be.true;65 // tslint:disable-next-line:no-unused-expression66 expect(collectionInfo).to.be.exist;67 // tslint:disable-next-line:no-unused-expression68 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');69 });70 });71});467247describe('setSchemaVersion positive', () => {73describe('Collection admin setSchemaVersion positive', () => {48 let tx;74 let tx;49 before(async () => {75 before(async () => {50 await usingApi(async () => {76 await usingApi(async () => {51 const keyring = new Keyring({ type: 'sr25519' });77 const keyring = new Keyring({ type: 'sr25519' });52 alice = keyring.addFromUri('//Alice');78 alice = keyring.addFromUri('//Alice');79 bob = keyring.addFromUri('//Bob');80 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);53 });81 });54 });82 });55 it('execute setSchemaVersion with image url and unique ', async () => {83 it('execute setSchemaVersion with image url and unique ', async () => {56 await usingApi(async (api: ApiPromise) => {84 await usingApi(async (api: ApiPromise) => {57 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');85 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');58 const events = await submitTransactionAsync(alice, tx);86 const events = await submitTransactionAsync(bob, tx);59 const result = getCreateItemResult(events);87 const result = getCreateItemResult(events);60 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;88 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;61 // tslint:disable-next-line:no-unused-expression89 // tslint:disable-next-line:no-unused-expression70 it('validate schema version with just entered data', async () => {98 it('validate schema version with just entered data', async () => {71 await usingApi(async (api: ApiPromise) => {99 await usingApi(async (api: ApiPromise) => {72 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');100 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');73 const events = await submitTransactionAsync(alice, tx);101 const events = await submitTransactionAsync(bob, tx);74 const result = getCreateItemResult(events);102 const result = getCreateItemResult(events);75 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;103 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;76 // tslint:disable-next-line:no-unused-expression104 // tslint:disable-next-line:no-unused-expressiontests/src/setVariableMetaData.test.tsdiffbeforeafterboth16 findNotExistingCollection,16 findNotExistingCollection,17 setVariableMetaDataExpectFailure,17 setVariableMetaDataExpectFailure,18 setVariableMetaDataExpectSuccess,18 setVariableMetaDataExpectSuccess,19 addCollectionAdminExpectSuccess,19} from './util/helpers';20} from './util/helpers';202121chai.use(chaiAsPromised);22chai.use(chaiAsPromised);48 });49 });49});50});5152describe('Integration Test collection admin setVariableMetaData', () => {53 const data = [1, 2, 254, 255];5455 let alice: IKeyringPair;56 let bob: IKeyringPair;57 let collectionId: number;58 let tokenId: number;59 before(async () => {60 await usingApi(async () => {61 alice = privateKey('//Alice');62 bob = privateKey('//Bob');63 collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });64 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');65 await addCollectionAdminExpectSuccess(alice, collectionId, bob);66 });67 });6869 it('execute setVariableMetaData', async () => {70 await setVariableMetaDataExpectSuccess(bob, collectionId, tokenId, data);71 });7273 it('verify data was set', async () => {74 await usingApi(async api => {75 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();7677 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));78 });79 });80});508151describe('Negative Integration Test setVariableMetaData', () => {82describe('Negative Integration Test setVariableMetaData', () => {52 const data = [1];83 const data = [1];tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth11import {11import {12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 addCollectionAdminExpectSuccess,14} from './util/helpers';15} from './util/helpers';151616chai.use(chaiAsPromised);17chai.use(chaiAsPromised);55 });56 });56});57});5859describe('Integration Test ext. collection admin setVariableOnChainSchema()', () => {6061 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {62 await usingApi(async (api) => {63 const collectionId = await createCollectionExpectSuccess();64 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();65 expect(collection.Owner).to.be.eq(Alice.address);66 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);67 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);68 await submitTransactionAsync(Bob, setSchema);69 });70 });7172 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {73 await usingApi(async (api) => {74 const collectionId = await createCollectionExpectSuccess();75 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);77 await submitTransactionAsync(Bob, setSchema);78 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();79 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);8081 });82 });83});578458describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {85describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {5986tests/src/transfer.test.tsdiffbeforeafterboth18 getCreateItemResult,18 getCreateItemResult,19 transferExpectFailure,19 transferExpectFailure,20 transferExpectSuccess,20 transferExpectSuccess,21 addCollectionAdminExpectSuccess,21} from './util/helpers';22} from './util/helpers';222323let Alice: IKeyringPair;24let Alice: IKeyringPair;90 });91 });91 });92 });9394 it('Collection admin can transfer owned token', async () => {95 await usingApi(async () => {96 const Alice = privateKey('//Alice');97 const Bob = privateKey('//Bob');98 // nft99 const nftCollectionId = await createCollectionExpectSuccess();100 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);101 const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT', Bob.address);102 await transferExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 1, 'NFT');103 // fungible104 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});105 await addCollectionAdminExpectSuccess(Alice, fungibleCollectionId, Bob);106 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible', Bob.address);107 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, 1, 'Fungible');108 // reFungible109 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});110 await addCollectionAdminExpectSuccess(Alice, reFungibleCollectionId, Bob);111 const newReFungibleTokenId = await createItemExpectSuccess(Bob, reFungibleCollectionId, 'ReFungible', Bob.address);112 await transferExpectSuccess(113 reFungibleCollectionId,114 newReFungibleTokenId,115 Bob,116 Alice,117 100,118 'ReFungible',119 );120 });121 });92});122});9312394describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {124describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {tests/src/util/helpers.tsdiffbeforeafterboth95 checkMsgSysMethod: string;95 checkMsgSysMethod: string;96}96}9798export interface IFungibleTokenDataType {99 Value: number;100}101102export interface IChainLimits {103 CollectionNumbersLimit: number;104 AccountTokenOwnershipLimit: number;105 CollectionsAdminsLimit: number;106 CustomDataLimit: number;107 NftSponsorTransferTimeout: number;108 FungibleSponsorTransferTimeout: number;109 RefungibleSponsorTransferTimeout: number;110 OffchainSchemaLimit: number;111 VariableOnChainSchemaLimit: number;112 ConstOnChainSchemaLimit: number;113}9711498export interface IReFungibleTokenDataType {115export interface IReFungibleTokenDataType {99 Owner: IReFungibleOwner[];116 Owner: IReFungibleOwner[];452 });469 });453}470}454471455export async function removeCollectionSponsorExpectFailure(collectionId: number) {472export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {456 await usingApi(async (api) => {473 await usingApi(async (api) => {457474458 // Run the transaction475 // Run the transaction459 const alicePrivateKey = privateKey('//Alice');476 const alicePrivateKey = privateKey(senderSeed);460 const tx = api.tx.nft.removeCollectionSponsor(collectionId);477 const tx = api.tx.nft.removeCollectionSponsor(collectionId);461 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;478 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;462 });479 });765 });782 });766}783}784785export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {786 await usingApi(async (api) => {787 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));788 const events = await submitTransactionAsync(sender, changeAdminTx);789 const result = getCreateCollectionResult(events);790 expect(result.success).to.be.true;791 });792}767793768export async function794export async function769scheduleTransferExpectSuccess(795scheduleTransferExpectSuccess(1021 });1047 });1022}1048}10491050export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1051 await usingApi(async (api) => {1052 // Run the transaction1053 const tx = api.tx.nft.setChainLimits(limits);1054 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1055 const result = getCreateCollectionResult(events);1056 // tslint:disable-next-line:no-unused-expression1057 expect(result.success).to.be.false;1058 });1059}102310601024export async function isWhitelisted(collectionId: number, address: string) {1061export async function isWhitelisted(collectionId: number, address: string) {1025 let whitelisted = false;1062 let whitelisted = false;