git.delta.rocks / unique-network / refs/commits / 44f9d3c6ebe4

difftreelog

tests: find not existing ids

Yaroslav Bolyukin2021-01-25parent: #0e762cd.patch.diff
in: master

2 files changed

modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
before · tests/src/setVariableMetaData.test.ts
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  setVariableMetaDataExpectFailure,12  setVariableMetaDataExpectSuccess,13} from './util/helpers';1415chai.use(chaiAsPromised);16const expect = chai.expect;1718describe('Integration Test setVariableMetaData', () => {19  const data = [1, 2, 254, 255];2021  let alice: IKeyringPair;22  let collectionId: number;23  let tokenId: number;24  before(async () => {25    await usingApi(async () => {26      alice = privateKey('//Alice');27      collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });28      tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');29    });30  });3132  it('execute setVariableMetaData', async () => {33    await setVariableMetaDataExpectSuccess(alice, collectionId, tokenId, data);34  });3536  it('verify data was set', async () => {37    await usingApi(async api => {38      const item: any = await api.query.nft.nftItemList(collectionId, tokenId);3940      expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));41    });42  });43});4445describe('Negative Integration Test setVariableMetaData', () => {46  let data = [1];4748  let alice: IKeyringPair;49  let bob: IKeyringPair;5051  let validCollectionId: number;52  let validTokenId: number;5354  before(async () => {55    await usingApi(async () => {56      alice = privateKey('//Alice');57      bob = privateKey('//Bob');5859      validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });60      validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');61    });62  });6364  it('fails on not existing collection id', async () => {65    // Not sure how to implement it66    const nonExistingCollectionId = 200000;67    await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);68  });69  it('fails on removed collection id', async () => {70    const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });71    const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');7273    await destroyCollectionExpectSuccess(removedCollectionId);74    await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);75  });76  it('fails on removed token', async () => {77    const removedTokenCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });78    const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');79    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);8081    await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);82  });83  it('fails on not existing token', async () => {84    const nonExistingTokenId = 200000;8586    await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);87  });88  it('fails on too long data', async () => {89    const tooLongData = new Array(4097).fill(0xff);9091    await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);92  });93  it('fails on fungible token', async () => {94    const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });95    const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');9697    await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);98  });99  it('fails on bad sender', async () => {100    await setVariableMetaDataExpectFailure(bob, validCollectionId, validTokenId, data);101  });102});
after · tests/src/setVariableMetaData.test.ts
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});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -253,6 +253,11 @@
   return unused;
 }
 
+export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
+  let collection: number = parseInt((await api.query.nft.createdCollectionCount()).toString()) as unknown as number + 1;
+  return collection;
+}
+
 function getDestroyResult(events: EventRecord[]): boolean {
   let success: boolean = false;
   events.forEach(({ phase, event: { data, method, section } }) => {