--- 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); --- 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'); --- 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); --- 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 --- 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; + }); + }); }); --- 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