git.delta.rocks / unique-network / refs/commits / cb7dd0f34de4

difftreelog

source

tests/src/setVariableMetaData.test.ts5.5 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';21import usingApi from './substrate/substrate-api';22import {23  burnItemExpectSuccess,24  createCollectionExpectSuccess,25  createItemExpectSuccess,26  destroyCollectionExpectSuccess,27  findNotExistingCollection,28  setVariableMetaDataExpectFailure,29  setVariableMetaDataExpectSuccess,30  addCollectionAdminExpectSuccess,31  setMetadataUpdatePermissionFlagExpectSuccess,32  getVariableMetadata,33} from './util/helpers';3435chai.use(chaiAsPromised);36const expect = chai.expect;3738describe('Integration Test setVariableMetaData', () => {39  const data = [1, 2, 254, 255];4041  let alice: IKeyringPair;42  let collectionId: number;43  let tokenId: number;44  before(async () => {45    await usingApi(async () => {46      alice = privateKey('//Alice');47      collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});48      tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');49    });50  });5152  it('execute setVariableMetaData', async () => {53    await setVariableMetaDataExpectSuccess(alice, collectionId, tokenId, data);54  });5556  it('verify data was set', async () => {57    await usingApi(async api => {58      expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);59    });60  });61});6263describe('Integration Test collection admin setVariableMetaData', () => {64  const data = [1, 2, 254, 255];6566  let alice: IKeyringPair;67  let bob: IKeyringPair;68  let collectionId: number;69  let tokenId: number;70  before(async () => {71    await usingApi(async () => {72      alice = privateKey('//Alice');73      bob = privateKey('//Bob');74      collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});75      tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');76      await setMetadataUpdatePermissionFlagExpectSuccess(alice, collectionId, 'Admin');77      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);78    });79  });8081  it('execute setVariableMetaData', async () => {82    await setVariableMetaDataExpectSuccess(bob, collectionId, tokenId, data);83  });8485  it('verify data was set', async () => {86    await usingApi(async api => {87      expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);88    });89  });90});9192describe('Negative Integration Test setVariableMetaData', () => {93  const data = [1];9495  let alice: IKeyringPair;96  let bob: IKeyringPair;9798  let validCollectionId: number;99  let validTokenId: number;100101  before(async () => {102    await usingApi(async () => {103      alice = privateKey('//Alice');104      bob = privateKey('//Bob');105106      validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});107      validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');108    });109  });110111  it('fails on not existing collection id', async () => {112    await usingApi(async api => {113      const nonExistingCollectionId = await findNotExistingCollection(api);114      await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);115    });116  });117  it('fails on removed collection id', async () => {118    const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});119    const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');120121    await destroyCollectionExpectSuccess(removedCollectionId);122    await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);123  });124  it('fails on removed token', async () => {125    const removedTokenCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});126    const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');127    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);128129    await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);130  });131  it('fails on not existing token', async () => {132    const nonExistingTokenId = validTokenId + 1;133134    await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);135  });136  it('fails on too long data', async () => {137    const tooLongData = new Array(4097).fill(0xff);138139    await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);140  });141  it('fails on fungible token', async () => {142    const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});143    const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');144145    await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);146  });147  it('fails on bad sender', async () => {148    await setVariableMetaDataExpectFailure(bob, validCollectionId, validTokenId, data);149  });150});