difftreelog
Missing tests added
in: master
6 files changed
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -17,6 +17,7 @@
enableWhiteListExpectSuccess,
normalizeAccountId,
addCollectionAdminExpectSuccess,
+ addToWhiteListExpectFail,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -98,6 +99,11 @@
});
});
+ it('Add to the white list by regular user', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);
+ });
+
it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
const collectionId = await createCollectionExpectSuccess();
await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -37,6 +37,33 @@
});
});
+ it('Remove collection admin by admin.', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ const Charlie = privateKey('//Charlie');
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(collection.Owner).to.be.deep.eq(Alice.address);
+ // first - add collection admin Bob
+ const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
+ await submitTransactionAsync(Alice, addAdminTx);
+
+ const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));
+ await submitTransactionAsync(Alice, addAdminTx2);
+
+ const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();
+ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));
+
+ // then remove bob from admins of collection
+ const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
+ await submitTransactionAsync(Charlie, removeAdminTx);
+
+ const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;
+ expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));
+ });
+ });
+
it('Remove admin from collection that has no admins', async () => {
await usingApi(async (api: ApiPromise) => {
const Alice = privateKey('//Alice');
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -112,6 +112,12 @@
await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
});
+ it('(!negative test!) Remove sponsor for a collection by regular user', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
+ });
+
it('(!negative test!) Remove sponsor in a destroyed collection', async () => {
const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
tests/src/removeFromWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromWhiteList.test.ts
+++ b/tests/src/removeFromWhiteList.test.ts
@@ -124,4 +124,13 @@
await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
});
});
+
+ it('Regular user can`t remove from whitelist', async () => {
+ await usingApi(async () => {
+ const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
+ await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
+ await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
+ await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
+ });
+ });
});
\ No newline at end of file
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion7import { ApiPromise, Keyring } from '@polkadot/api';8import { IKeyringPair } from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';12import { ICollectionInterface } from './types';13import {14 createCollectionExpectSuccess,15 destroyCollectionExpectSuccess,16 getCreatedCollectionCount,17 getCreateItemResult,18 getDetailedCollectionInfo,19 addCollectionAdminExpectSuccess,20} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let alice: IKeyringPair;26let bob: IKeyringPair;27let collectionIdForTesting: number;2829/*301. We create collection.312. Save just created collection id.323. Use this id for setSchemaVersion.33*/3435describe('hooks', () => {36 before(async () => {37 await usingApi(async () => {38 const keyring = new Keyring({ type: 'sr25519' });39 alice = keyring.addFromUri('//Alice');40 });41 });42 it('choose or create collection for testing', async () => {43 await usingApi(async () => {44 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});45 });46 });47});4849describe('setSchemaVersion positive', () => {50 let tx;51 before(async () => {52 await usingApi(async () => {53 const keyring = new Keyring({ type: 'sr25519' });54 alice = keyring.addFromUri('//Alice');55 });56 });57 it('execute setSchemaVersion with image url and unique ', async () => {58 await usingApi(async (api: ApiPromise) => {59 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');60 const events = await submitTransactionAsync(alice, tx);61 const result = getCreateItemResult(events);62 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;63 // tslint:disable-next-line:no-unused-expression64 expect(result.success).to.be.true;65 // tslint:disable-next-line:no-unused-expression66 expect(collectionInfo).to.be.exist;67 // tslint:disable-next-line:no-unused-expression68 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');69 });70 });71});7273describe('Collection admin setSchemaVersion positive', () => {74 let tx;75 before(async () => {76 await usingApi(async () => {77 const keyring = new Keyring({ type: 'sr25519' });78 alice = keyring.addFromUri('//Alice');79 bob = keyring.addFromUri('//Bob');80 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);81 });82 });83 it('execute setSchemaVersion with image url and unique ', async () => {84 await usingApi(async (api: ApiPromise) => {85 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');86 const events = await submitTransactionAsync(bob, tx);87 const result = getCreateItemResult(events);88 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;89 // tslint:disable-next-line:no-unused-expression90 expect(result.success).to.be.true;91 // tslint:disable-next-line:no-unused-expression92 expect(collectionInfo).to.be.exist;93 // tslint:disable-next-line:no-unused-expression94 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');95 });96 });9798 it('validate schema version with just entered data', async () => {99 await usingApi(async (api: ApiPromise) => {100 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');101 const events = await submitTransactionAsync(bob, tx);102 const result = getCreateItemResult(events);103 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;104 // tslint:disable-next-line:no-unused-expression105 expect(result.success).to.be.true;106 // tslint:disable-next-line:no-unused-expression107 expect(collectionInfo).to.be.exist;108 // tslint:disable-next-line:no-unused-expression109 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');110 });111 });112});113114describe('setSchemaVersion negative', () => {115 let tx;116 before(async () => {117 await usingApi(async () => {118 const keyring = new Keyring({ type: 'sr25519' });119 alice = keyring.addFromUri('//Alice');120 });121 });122 it('execute setSchemaVersion for not exists collection', async () => {123 await usingApi(async (api: ApiPromise) => {124 const collectionCount = await getCreatedCollectionCount(api);125 const nonExistedCollectionId = collectionCount + 1;126 tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');127 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;128 });129 });130131 it('execute setSchemaVersion with not correct schema version', async () => {132 await usingApi(async (api: ApiPromise) => {133 const consoleError = console.error;134 console.error = () => {};135 try {136 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');137 await submitTransactionAsync(alice, tx);138 } catch (e) {139 // tslint:disable-next-line:no-unused-expression140 expect(e).to.be.exist;141 } finally {142 console.error = consoleError;143 }144 });145 });146147 it('execute setSchemaVersion for deleted collection', async () => {148 await usingApi(async (api: ApiPromise) => {149 await destroyCollectionExpectSuccess(collectionIdForTesting);150 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');151 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;152 });153 });154});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -1088,6 +1088,19 @@
});
}
+export async function addToWhiteListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
+ await usingApi(async (api) => {
+ // Run the transaction
+ const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
+ const events = await expect(submitTransactionAsync(sender, tx)).to.be.rejected;
+ const result = getGenericResult(events);
+
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.false;
+ });
+}
+
export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {
await usingApi(async (api) => {
// Run the transaction