git.delta.rocks / unique-network / refs/commits / 09636be4bace

difftreelog

source

tests/src/setVariableMetaData.test.ts3.8 KiBsourcehistory
1import { IKeyringPair } from '@polkadot/types/types';2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import privateKey from './substrate/privateKey';5import usingApi from './substrate/substrate-api';6import {7  burnItemExpectSuccess,8  createCollectionExpectSuccess,9  createItemExpectSuccess,10  destroyCollectionExpectSuccess,11  findNotExistingCollection,12  setVariableMetaDataExpectFailure,13  setVariableMetaDataExpectSuccess,14} from './util/helpers';1516chai.use(chaiAsPromised);17const expect = chai.expect;1819describe('Integration Test setVariableMetaData', () => {20  const data = [1, 2, 254, 255];2122  let alice: IKeyringPair;23  let collectionId: number;24  let tokenId: number;25  before(async () => {26    await usingApi(async () => {27      alice = privateKey('//Alice');28      collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });29      tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');30    });31  });3233  it('execute setVariableMetaData', async () => {34    await setVariableMetaDataExpectSuccess(alice, collectionId, tokenId, data);35  });3637  it('verify data was set', async () => {38    await usingApi(async api => {39      const item: any = await api.query.nft.nftItemList(collectionId, tokenId);4041      expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));42    });43  });44});4546describe('Negative Integration Test setVariableMetaData', () => {47  let data = [1];4849  let alice: IKeyringPair;50  let bob: IKeyringPair;5152  let validCollectionId: number;53  let validTokenId: number;5455  before(async () => {56    await usingApi(async () => {57      alice = privateKey('//Alice');58      bob = privateKey('//Bob');5960      validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });61      validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');62    });63  });6465  it('fails on not existing collection id', async () => {66    await usingApi(async api => {67      let nonExistingCollectionId = await findNotExistingCollection(api);68      await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);69    });70  });71  it('fails on removed collection id', async () => {72    const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });73    const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');7475    await destroyCollectionExpectSuccess(removedCollectionId);76    await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);77  });78  it('fails on removed token', async () => {79    const removedTokenCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });80    const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');81    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);8283    await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);84  });85  it('fails on not existing token', async () => {86    const nonExistingTokenId = validTokenId + 1;8788    await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);89  });90  it('fails on too long data', async () => {91    const tooLongData = new Array(4097).fill(0xff);9293    await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);94  });95  it('fails on fungible token', async () => {96    const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });97    const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');9899    await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);100  });101  it('fails on bad sender', async () => {102    await setVariableMetaDataExpectFailure(bob, validCollectionId, validTokenId, data);103  });104});