git.delta.rocks / unique-network / refs/commits / 23a018e7c903

difftreelog

source

tests/src/setVariableMetaData.test.ts4.9 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  addCollectionAdminExpectSuccess,20  setMetadataUpdatePermissionFlagExpectSuccess,21  getVariableMetadata,22} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627describe('Integration Test setVariableMetaData', () => {28  const data = [1, 2, 254, 255];2930  let alice: IKeyringPair;31  let collectionId: number;32  let tokenId: number;33  before(async () => {34    await usingApi(async () => {35      alice = privateKey('//Alice');36      collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});37      tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');38    });39  });4041  it('execute setVariableMetaData', async () => {42    await setVariableMetaDataExpectSuccess(alice, collectionId, tokenId, data);43  });4445  it('verify data was set', async () => {46    await usingApi(async api => {47      expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);48    });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 setMetadataUpdatePermissionFlagExpectSuccess(alice, collectionId, 'Admin');66      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);67    });68  });6970  it('execute setVariableMetaData', async () => {71    await setVariableMetaDataExpectSuccess(bob, collectionId, tokenId, data);72  });7374  it('verify data was set', async () => {75    await usingApi(async api => {76      expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);77    });78  });79});8081describe('Negative Integration Test setVariableMetaData', () => {82  const data = [1];8384  let alice: IKeyringPair;85  let bob: IKeyringPair;8687  let validCollectionId: number;88  let validTokenId: number;8990  before(async () => {91    await usingApi(async () => {92      alice = privateKey('//Alice');93      bob = privateKey('//Bob');9495      validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});96      validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');97    });98  });99100  it('fails on not existing collection id', async () => {101    await usingApi(async api => {102      const nonExistingCollectionId = await findNotExistingCollection(api);103      await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);104    });105  });106  it('fails on removed collection id', async () => {107    const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});108    const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');109110    await destroyCollectionExpectSuccess(removedCollectionId);111    await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);112  });113  it('fails on removed token', async () => {114    const removedTokenCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});115    const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');116    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);117118    await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);119  });120  it('fails on not existing token', async () => {121    const nonExistingTokenId = validTokenId + 1;122123    await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);124  });125  it('fails on too long data', async () => {126    const tooLongData = new Array(4097).fill(0xff);127128    await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);129  });130  it('fails on fungible token', async () => {131    const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});132    const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');133134    await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);135  });136  it('fails on bad sender', async () => {137    await setVariableMetaDataExpectFailure(bob, validCollectionId, validTokenId, data);138  });139});