difftreelog
Merge pull request #170 from UniqueNetwork/feature/CORE-161
in: master
Feature/core 161
2 files changed
tests/src/change-collection-owner.test.tsdiffbeforeafterboth8import privateKey from './substrate/privateKey';8import privateKey from './substrate/privateKey';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';10import { createCollectionExpectSuccess, 11 addCollectionAdminExpectSuccess,12 setCollectionSponsorExpectSuccess,13 confirmSponsorshipExpectSuccess,14 removeCollectionSponsorExpectSuccess,15 enableWhiteListExpectSuccess,16 setMintPermissionExpectSuccess,17 destroyCollectionExpectSuccess,18 setCollectionSponsorExpectFailure,19 confirmSponsorshipExpectFailure,20 removeCollectionSponsorExpectFailure,21 enableWhiteListExpectFail,22 setMintPermissionExpectFailure,23 destroyCollectionExpectFailure,24 setPublicAccessModeExpectSuccess,25} from './util/helpers';112612chai.use(chaiAsPromised);27chai.use(chaiAsPromised);31 });46 });32});47});4849describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {50 it('Changing the owner of the collection is not allowed for the former owner', async () => {51 await usingApi(async api => {52 const collectionId = await createCollectionExpectSuccess();53 const alice = privateKey('//Alice');54 const bob = privateKey('//Bob');5556 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();57 expect(collection.Owner).to.be.deep.eq(alice.address);5859 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);60 await submitTransactionAsync(alice, changeOwnerTx);6162 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);63 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;6465 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();66 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);67 });68 });6970 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {71 await usingApi(async api => {72 const collectionId = await createCollectionExpectSuccess();73 const alice = privateKey('//Alice');74 const bob = privateKey('//Bob');75 const charlie = privateKey('//Charlie');7677 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();78 expect(collection.Owner).to.be.deep.eq(alice.address);7980 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);81 await submitTransactionAsync(alice, changeOwnerTx);8283 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();84 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);8586 // After changing the owner of the collection, all privileged methods are available to the new owner87 // The new owner of the collection has access to sponsorship management operations in the collection88 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');89 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');90 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');9192 // The new owner of the collection has access to operations for managing the collection parameters93 const collectionLimits = {94 AccountTokenOwnershipLimit: 1,95 SponsoredMintSize: 1,96 TokenLimit: 1,97 SponsorTimeout: 1,98 OwnerCanTransfer: true,99 OwnerCanDestroy: true,100 };101 const tx1 = api.tx.nft.setCollectionLimits(102 collectionId,103 collectionLimits,104 );105 await submitTransactionAsync(bob, tx1);106107 await setPublicAccessModeExpectSuccess(bob, collectionId, 'WhiteList');108 await enableWhiteListExpectSuccess(bob, collectionId);109 await setMintPermissionExpectSuccess(bob, collectionId, true);110 await destroyCollectionExpectSuccess(collectionId, '//Bob');111 });112 });113114 it('New collectionOwner has access to changeCollectionOwner', async () => {115 await usingApi(async api => {116 const collectionId = await createCollectionExpectSuccess();117 const alice = privateKey('//Alice');118 const bob = privateKey('//Bob');119 const charlie = privateKey('//Charlie');120 121 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();122 expect(collection.Owner).to.be.deep.eq(alice.address);123 124 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);125 await submitTransactionAsync(alice, changeOwnerTx);126 127 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();128 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);129130 const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);131 await submitTransactionAsync(bob, changeOwnerTx2);132 133 // ownership lost134 const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();135 expect(collectionAfterOwnerChange2.Owner).to.be.deep.eq(charlie.address);136 });137 });138});3313934describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {140describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {35 it('Not owner can\'t change owner.', async () => {141 it('Not owner can\'t change owner.', async () => {82 });188 });83 });189 });190191 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {192 await usingApi(async api => {193 const collectionId = await createCollectionExpectSuccess();194 const alice = privateKey('//Alice');195 const bob = privateKey('//Bob');196 const charlie = privateKey('//Charlie');197198 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();199 expect(collection.Owner).to.be.deep.eq(alice.address);200201 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);202 await submitTransactionAsync(alice, changeOwnerTx);203204 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);205 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;206207 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();208 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);209210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');211 await confirmSponsorshipExpectFailure(collectionId, '//Alice');212 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');213214 const collectionLimits = {215 AccountTokenOwnershipLimit: 1,216 SponsoredMintSize: 1,217 TokenLimit: 1,218 SponsorTimeout: 1,219 OwnerCanTransfer: true,220 OwnerCanDestroy: true,221 };222 const tx1 = api.tx.nft.setCollectionLimits(223 collectionId,224 collectionLimits,225 );226 await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;227228 await enableWhiteListExpectFail(alice, collectionId);229 await setMintPermissionExpectFailure(alice, collectionId, true);230 await destroyCollectionExpectFailure(collectionId, '//Alice');231 });232 });84});233});85234tests/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');
}