difftreelog
Merge pull request #170 from UniqueNetwork/feature/CORE-161
in: master
Feature/core 161
2 files changed
tests/src/change-collection-owner.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 chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';1112chai.use(chaiAsPromised);13const expect = chai.expect;1415describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {16 it('Changing owner changes owner address', async () => {17 await usingApi(async api => {18 const collectionId = await createCollectionExpectSuccess();19 const alice = privateKey('//Alice');20 const bob = privateKey('//Bob');2122 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 expect(collection.Owner).to.be.deep.eq(alice.address);2425 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);26 await submitTransactionAsync(alice, changeOwnerTx);2728 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();29 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);30 });31 });32});3334describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {35 it('Not owner can\'t change owner.', async () => {36 await usingApi(async api => {37 const collectionId = await createCollectionExpectSuccess();38 const alice = privateKey('//Alice');39 const bob = privateKey('//Bob');4041 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);42 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;4344 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();45 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);4647 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)48 await createCollectionExpectSuccess();49 });50 });5152 it('Collection admin can\'t change owner.', async () => {53 await usingApi(async api => {54 const collectionId = await createCollectionExpectSuccess();55 const alice = privateKey('//Alice');56 const bob = privateKey('//Bob');5758 await addCollectionAdminExpectSuccess(alice, collectionId, bob);5960 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);61 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;6263 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();64 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);6566 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)67 await createCollectionExpectSuccess();68 });69 });7071 it('Can\'t change owner of a non-existing collection.', async () => {72 await usingApi(async api => {73 const collectionId = (1<<32) - 1;74 const alice = privateKey('//Alice');75 const bob = privateKey('//Bob');7677 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);78 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;7980 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)81 await createCollectionExpectSuccess();82 });83 });84});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -431,13 +431,13 @@
});
}
-export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
+export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {
await usingApi(async (api) => {
// Run the transaction
- const alicePrivateKey = privateKey('//Alice');
+ const senderPrivateKey = privateKey(sender);
const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
- const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const events = await submitTransactionAsync(senderPrivateKey, tx);
const result = getGenericResult(events);
// Get the collection
@@ -451,11 +451,11 @@
});
}
-export async function removeCollectionSponsorExpectSuccess(collectionId: number) {
+export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {
await usingApi(async (api) => {
// Run the transaction
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKey(sender);
const tx = api.tx.nft.removeCollectionSponsor(collectionId);
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getGenericResult(events);
@@ -1006,10 +1006,31 @@
});
}
+export async function setPublicAccessModeExpectFail(
+ sender: IKeyringPair, collectionId: number,
+ accessMode: 'Normal' | 'WhiteList',
+) {
+ await usingApi(async (api) => {
+
+ // Run the transaction
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);
+ const events = await expect(submitTransactionExpectFailAsync(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 enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');
}
+export async function enableWhiteListExpectFail(sender: IKeyringPair, collectionId: number) {
+ await setPublicAccessModeExpectFail(sender, collectionId, 'WhiteList');
+}
+
export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');
}