git.delta.rocks / unique-network / refs/commits / 6090f15f03e0

difftreelog

source

tests/src/setVariableMetaData.test.ts4.0 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {12  burnItemExpectSuccess,13  createCollectionExpectSuccess,14  createItemExpectSuccess,15  destroyCollectionExpectSuccess,16  findNotExistingCollection,17  setVariableMetaDataExpectFailure,18  setVariableMetaDataExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test setVariableMetaData', () => {25  const data = [1, 2, 254, 255];2627  let alice: IKeyringPair;28  let collectionId: number;29  let tokenId: number;30  before(async () => {31    await usingApi(async () => {32      alice = privateKey('//Alice');33      collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });34      tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');35    });36  });3738  it('execute setVariableMetaData', async () => {39    await setVariableMetaDataExpectSuccess(alice, collectionId, tokenId, data);40  });4142  it('verify data was set', async () => {43    await usingApi(async api => {44      const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();4546      expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));47    });48  });49});5051describe('Negative Integration Test setVariableMetaData', () => {52  let data = [1];5354  let alice: IKeyringPair;55  let bob: IKeyringPair;5657  let validCollectionId: number;58  let validTokenId: number;5960  before(async () => {61    await usingApi(async () => {62      alice = privateKey('//Alice');63      bob = privateKey('//Bob');6465      validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });66      validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');67    });68  });6970  it('fails on not existing collection id', async () => {71    await usingApi(async api => {72      let nonExistingCollectionId = await findNotExistingCollection(api);73      await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);74    });75  });76  it('fails on removed collection id', async () => {77    const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });78    const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');7980    await destroyCollectionExpectSuccess(removedCollectionId);81    await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);82  });83  it('fails on removed token', async () => {84    const removedTokenCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });85    const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');86    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);8788    await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);89  });90  it('fails on not existing token', async () => {91    const nonExistingTokenId = validTokenId + 1;9293    await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);94  });95  it('fails on too long data', async () => {96    const tooLongData = new Array(4097).fill(0xff);9798    await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);99  });100  it('fails on fungible token', async () => {101    const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });102    const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');103104    await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);105  });106  it('fails on bad sender', async () => {107    await setVariableMetaDataExpectFailure(bob, validCollectionId, validTokenId, data);108  });109});