difftreelog
Missing tests added
in: master
6 files changed
tests/src/addToWhiteList.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//56import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {12 addToWhiteListExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 enablePublicMintingExpectSuccess,17 enableWhiteListExpectSuccess,18 normalizeAccountId,19 addCollectionAdminExpectSuccess,20} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let Alice: IKeyringPair;26let Bob: IKeyringPair;27let Charlie: IKeyringPair;2829describe('Integration Test ext. addToWhiteList()', () => {3031 before(async () => {32 await usingApi(async () => {33 Alice = privateKey('//Alice');34 Bob = privateKey('//Bob');35 });36 });3738 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {39 const collectionId = await createCollectionExpectSuccess();40 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);41 });4243 it('Whitelisted minting: list restrictions', async () => {44 const collectionId = await createCollectionExpectSuccess();45 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);46 await enableWhiteListExpectSuccess(Alice, collectionId);47 await enablePublicMintingExpectSuccess(Alice, collectionId);48 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);49 });50});5152describe('Negative Integration Test ext. addToWhiteList()', () => {5354 it('White list an address in the collection that does not exist', async () => {55 await usingApi(async (api) => {56 // tslint:disable-next-line: no-bitwise57 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;58 const Bob = privateKey('//Bob');5960 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));61 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;62 });63 });6465 it('White list an address in the collection that was destroyed', async () => {66 await usingApi(async (api) => {67 const Alice = privateKey('//Alice');68 const Bob = privateKey('//Bob');69 // tslint:disable-next-line: no-bitwise70 const collectionId = await createCollectionExpectSuccess();71 await destroyCollectionExpectSuccess(collectionId);72 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));73 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;74 });75 });7677 it('White list an address in the collection that does not have white list access enabled', async () => {78 await usingApi(async (api) => {79 const Alice = privateKey('//Alice');80 const Ferdie = privateKey('//Ferdie');81 const collectionId = await createCollectionExpectSuccess();82 await enableWhiteListExpectSuccess(Alice, collectionId);83 await enablePublicMintingExpectSuccess(Alice, collectionId);84 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');85 await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;86 });87 });8889});9091describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {9293 before(async () => {94 await usingApi(async () => {95 Alice = privateKey('//Alice');96 Bob = privateKey('//Bob');97 Charlie = privateKey('//Charlie');98 });99 });100101 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {102 const collectionId = await createCollectionExpectSuccess();103 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);104 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);105 });106107 it('Whitelisted minting: list restrictions', async () => {108 const collectionId = await createCollectionExpectSuccess();109 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);110 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);111112 // allowed only for collection owner113 await enableWhiteListExpectSuccess(Alice, collectionId);114 await enablePublicMintingExpectSuccess(Alice, collectionId);115116 await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);117 });118});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, { submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {12 addToWhiteListExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 enablePublicMintingExpectSuccess,17 enableWhiteListExpectSuccess,18 normalizeAccountId,19 addCollectionAdminExpectSuccess,20 addToWhiteListExpectFail,21} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526let Alice: IKeyringPair;27let Bob: IKeyringPair;28let Charlie: IKeyringPair;2930describe('Integration Test ext. addToWhiteList()', () => {3132 before(async () => {33 await usingApi(async () => {34 Alice = privateKey('//Alice');35 Bob = privateKey('//Bob');36 });37 });3839 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {40 const collectionId = await createCollectionExpectSuccess();41 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);42 });4344 it('Whitelisted minting: list restrictions', async () => {45 const collectionId = await createCollectionExpectSuccess();46 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);47 await enableWhiteListExpectSuccess(Alice, collectionId);48 await enablePublicMintingExpectSuccess(Alice, collectionId);49 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);50 });51});5253describe('Negative Integration Test ext. addToWhiteList()', () => {5455 it('White list an address in the collection that does not exist', async () => {56 await usingApi(async (api) => {57 // tslint:disable-next-line: no-bitwise58 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;59 const Bob = privateKey('//Bob');6061 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));62 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;63 });64 });6566 it('White list an address in the collection that was destroyed', async () => {67 await usingApi(async (api) => {68 const Alice = privateKey('//Alice');69 const Bob = privateKey('//Bob');70 // tslint:disable-next-line: no-bitwise71 const collectionId = await createCollectionExpectSuccess();72 await destroyCollectionExpectSuccess(collectionId);73 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));74 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;75 });76 });7778 it('White list an address in the collection that does not have white list access enabled', async () => {79 await usingApi(async (api) => {80 const Alice = privateKey('//Alice');81 const Ferdie = privateKey('//Ferdie');82 const collectionId = await createCollectionExpectSuccess();83 await enableWhiteListExpectSuccess(Alice, collectionId);84 await enablePublicMintingExpectSuccess(Alice, collectionId);85 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');86 await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;87 });88 });8990});9192describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {9394 before(async () => {95 await usingApi(async () => {96 Alice = privateKey('//Alice');97 Bob = privateKey('//Bob');98 Charlie = privateKey('//Charlie');99 });100 });101102 it('Add to the white list by regular user', async () => {103 const collectionId = await createCollectionExpectSuccess();104 await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);105 });106107 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {108 const collectionId = await createCollectionExpectSuccess();109 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);110 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);111 });112113 it('Whitelisted minting: list restrictions', async () => {114 const collectionId = await createCollectionExpectSuccess();115 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);116 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);117118 // allowed only for collection owner119 await enableWhiteListExpectSuccess(Alice, collectionId);120 await enablePublicMintingExpectSuccess(Alice, collectionId);121122 await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);123 });124});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.tsdiffbeforeafterboth--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -24,6 +24,7 @@
let alice: IKeyringPair;
let bob: IKeyringPair;
+let charlie: IKeyringPair;
let collectionIdForTesting: number;
/*
@@ -111,12 +112,13 @@
});
});
-describe('setSchemaVersion negative', () => {
+describe.only('setSchemaVersion negative', () => {
let tx;
before(async () => {
await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
alice = keyring.addFromUri('//Alice');
+ charlie = keyring.addFromUri('//Charlie');
});
});
it('execute setSchemaVersion for not exists collection', async () => {
@@ -127,7 +129,6 @@
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
-
it('execute setSchemaVersion with not correct schema version', async () => {
await usingApi(async (api: ApiPromise) => {
const consoleError = console.error;
@@ -143,7 +144,6 @@
}
});
});
-
it('execute setSchemaVersion for deleted collection', async () => {
await usingApi(async (api: ApiPromise) => {
await destroyCollectionExpectSuccess(collectionIdForTesting);
@@ -151,4 +151,10 @@
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
+ it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
+ await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;
+ });
+ });
});
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