difftreelog
setSchema test scenarios
in: master
1 file changed
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth4import BN from 'bn.js';4import BN from 'bn.js';5import chai from 'chai';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';6import chaiAsPromised from 'chai-as-promised';7import privateKey from './substrate/privateKey';8import promisifySubstrate from './substrate/promisify-substrate';9import usingApi, { submitTransactionAsync } from './substrate/substrate-api';7import usingApi, { submitTransactionAsync } from './substrate/substrate-api';10import { ICollectionInterface } from './types';8import { ICollectionInterface } from './types';11import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, getCreateItemResult } from './util/helpers';9import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, getCreateItemResult } from './util/helpers';223. Use this id for setSchemaVersion.203. Use this id for setSchemaVersion.23*/21*/242225async function getDetailedCollectionInfo(api: ApiPromise, collectionId: number)23const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)26 : Promise<ICollectionInterface | null> {24 : Promise<ICollectionInterface | null> => {27 return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;25 return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;28}26};292730async function getCollectionCount(api: ApiPromise): Promise<number> {28const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {31 // set global object - collectionsCount29 // set global object - collectionsCount32 return (await api.query.nft.collectionCount() as unknown as BN).toNumber();30 return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();33}31};3435function utf8Decoder(name: [Uint8Array]) {36 const collectionNameArr = Array.prototype.slice.call(name);37 return String.fromCharCode(...collectionNameArr);38}393240describe('hooks', () => {33describe('hooks', () => {41 before(async () => {34 before(async () => {42 await usingApi(async (api) => {35 await usingApi(async () => {43 const keyring = new Keyring({ type: 'sr25519' });36 const keyring = new Keyring({ type: 'sr25519' });44 alice = keyring.addFromUri('//Alice');37 alice = keyring.addFromUri('//Alice');45 });38 });46 });39 });47 it('choose or create collection for testing', async () => {40 it('choose or create collection for testing', async () => {48 await usingApi(async (api: ApiPromise) => {41 await usingApi(async () => {49 const newCollectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});42 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});50 console.log('newCollectionId', newCollectionId);51 collectionIdForTesting = newCollectionId;52 });43 });53 });44 });54});45});554656describe('setSchemaVersion positive', () => {47describe('setSchemaVersion positive', () => {57 let tx;48 let tx;58 before(async () => {49 before(async () => {59 await usingApi(async (api) => {50 await usingApi(async () => {60 const keyring = new Keyring({ type: 'sr25519' });51 const keyring = new Keyring({ type: 'sr25519' });61 alice = keyring.addFromUri('//Alice');52 alice = keyring.addFromUri('//Alice');62 });53 });95describe('setSchemaVersion negative', () => {86describe('setSchemaVersion negative', () => {96 let tx;87 let tx;97 before(async () => {88 before(async () => {98 await usingApi(async (api) => {89 await usingApi(async () => {99 const keyring = new Keyring({ type: 'sr25519' });90 const keyring = new Keyring({ type: 'sr25519' });100 alice = keyring.addFromUri('//Alice');91 alice = keyring.addFromUri('//Alice');101 });92 });102 });93 });103 it('execute setSchemaVersion for not exists collection', async () => {94 it('execute setSchemaVersion for not exists collection', async () => {104 await usingApi(async (api: ApiPromise) => {95 await usingApi(async (api: ApiPromise) => {105 const collectionCount = await getCollectionCount(api);96 const collectionCount = await getCreatedCollectionCount(api);106 const nonExistedCollectionId = collectionCount + 1;97 const nonExistedCollectionId = collectionCount + 1;107 tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');98 tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');108 try {99 try {128119129 it('execute setSchemaVersion for deleted collection', async () => {120 it('execute setSchemaVersion for deleted collection', async () => {130 await usingApi(async (api: ApiPromise) => {121 await usingApi(async (api: ApiPromise) => {131 const collectionCount = await getCollectionCount(api);132 await destroyCollectionExpectSuccess(collectionCount);122 await destroyCollectionExpectSuccess(collectionIdForTesting);133 try {123 try {134 tx = api.tx.nft.setSchemaVersion(collectionCount, 'ImageURL');124 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');135 await submitTransactionAsync(alice, tx);125 await submitTransactionAsync(alice, tx);136 } catch (e) {126 } catch (e) {137 // tslint:disable-next-line:no-unused-expression127 // tslint:disable-next-line:no-unused-expression