difftreelog
Tests updated
in: master
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, 11 addCollectionAdminExpectSuccess,12 setCollectionSponsorExpectSuccess,13 confirmSponsorshipExpectSuccess,14 removeCollectionSponsorExpectSuccess,15 enableWhiteListExpectSuccess,16 setMintPermissionExpectSuccess,17 destroyCollectionExpectSuccess,18} from './util/helpers';1920chai.use(chaiAsPromised);21const expect = chai.expect;2223describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {24 it('Changing owner changes owner address', async () => {25 await usingApi(async api => {26 const collectionId = await createCollectionExpectSuccess();27 const alice = privateKey('//Alice');28 const bob = privateKey('//Bob');2930 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();31 expect(collection.Owner).to.be.deep.eq(alice.address);3233 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);34 await submitTransactionAsync(alice, changeOwnerTx);3536 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();37 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);38 });39 });40});4142describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {43 it('Changing the owner of the collection is not allowed for the former owner', async () => {44 await usingApi(async api => {45 const collectionId = await createCollectionExpectSuccess();46 const alice = privateKey('//Alice');47 const bob = privateKey('//Bob');4849 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();50 expect(collection.Owner).to.be.deep.eq(alice.address);5152 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);53 await submitTransactionAsync(alice, changeOwnerTx);5455 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);56 await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;5758 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();59 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);60 });61 });6263 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {64 await usingApi(async api => {65 const collectionId = await createCollectionExpectSuccess();66 const alice = privateKey('//Alice');67 const bob = privateKey('//Bob');68 const charlie = privateKey('//Charlie');6970 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();71 expect(collection.Owner).to.be.deep.eq(alice.address);7273 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);74 await submitTransactionAsync(alice, changeOwnerTx);7576 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();77 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);7879 // After changing the owner of the collection, all privileged methods are available to the new owner80 // The new owner of the collection has access to sponsorship management operations in the collection81 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');82 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');83 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');8485 // The new owner of the collection has access to operations for managing the collection parameters86 const collectionLimits = {87 AccountTokenOwnershipLimit: 1,88 SponsoredMintSize: 1,89 TokenLimit: 1,90 SponsorTimeout: 1,91 OwnerCanTransfer: true,92 OwnerCanDestroy: true,93 };94 const tx1 = api.tx.nft.setCollectionLimits(95 collectionId,96 collectionLimits,97 );98 await submitTransactionAsync(bob, tx1);99100 await enableWhiteListExpectSuccess(bob, collectionId);101 await setMintPermissionExpectSuccess(bob, collectionId, true);102 await destroyCollectionExpectSuccess(collectionId, '//Bob');103 });104 });105});106107describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {108 it('Not owner can\'t change owner.', async () => {109 await usingApi(async api => {110 const collectionId = await createCollectionExpectSuccess();111 const alice = privateKey('//Alice');112 const bob = privateKey('//Bob');113114 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);115 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;116117 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();118 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);119120 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)121 await createCollectionExpectSuccess();122 });123 });124125 it('Collection admin can\'t change owner.', async () => {126 await usingApi(async api => {127 const collectionId = await createCollectionExpectSuccess();128 const alice = privateKey('//Alice');129 const bob = privateKey('//Bob');130131 await addCollectionAdminExpectSuccess(alice, collectionId, bob);132133 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);134 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;135136 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();137 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);138139 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)140 await createCollectionExpectSuccess();141 });142 });143144 it('Can\'t change owner of a non-existing collection.', async () => {145 await usingApi(async api => {146 const collectionId = (1<<32) - 1;147 const alice = privateKey('//Alice');148 const bob = privateKey('//Bob');149150 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);151 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;152153 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)154 await createCollectionExpectSuccess();155 });156 });157158 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {159 await usingApi(async api => {160 const collectionId = await createCollectionExpectSuccess();161 const alice = privateKey('//Alice');162 const bob = privateKey('//Bob');163 const charlie = privateKey('//Charlie');164165 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();166 expect(collection.Owner).to.be.deep.eq(alice.address);167168 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);169 await submitTransactionAsync(alice, changeOwnerTx);170171 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);172 await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;173174 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();175 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);176177 await expect(setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Alice')).to.be.rejected;178 await expect(confirmSponsorshipExpectSuccess(collectionId, '//Alice')).to.be.rejected;179 await expect(removeCollectionSponsorExpectSuccess(collectionId, '//Alice')).to.be.rejected;180181 const collectionLimits = {182 AccountTokenOwnershipLimit: 1,183 SponsoredMintSize: 1,184 TokenLimit: 1,185 SponsorTimeout: 1,186 OwnerCanTransfer: true,187 OwnerCanDestroy: true,188 };189 const tx1 = api.tx.nft.setCollectionLimits(190 collectionId,191 collectionLimits,192 );193 await expect(submitTransactionAsync(alice, tx1)).to.be.rejected;194195 await expect(enableWhiteListExpectSuccess(alice, collectionId)).to.be.rejected;196 await expect(setMintPermissionExpectSuccess(alice, collectionId, true)).to.be.rejected;197 await expect(destroyCollectionExpectSuccess(collectionId, '//Alice')).to.be.rejected;198 });199 });200});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 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, 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} from './util/helpers';2526chai.use(chaiAsPromised);27const expect = chai.expect;2829describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {30 it('Changing owner changes owner address', async () => {31 await usingApi(async api => {32 const collectionId = await createCollectionExpectSuccess();33 const alice = privateKey('//Alice');34 const bob = privateKey('//Bob');3536 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();37 expect(collection.Owner).to.be.deep.eq(alice.address);3839 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);40 await submitTransactionAsync(alice, changeOwnerTx);4142 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();43 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);44 });45 });46});4748describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {49 it('Changing the owner of the collection is not allowed for the former owner', async () => {50 await usingApi(async api => {51 const collectionId = await createCollectionExpectSuccess();52 const alice = privateKey('//Alice');53 const bob = privateKey('//Bob');5455 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();56 expect(collection.Owner).to.be.deep.eq(alice.address);5758 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);59 await submitTransactionAsync(alice, changeOwnerTx);6061 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);62 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;6364 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();65 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);66 });67 });6869 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {70 await usingApi(async api => {71 const collectionId = await createCollectionExpectSuccess();72 const alice = privateKey('//Alice');73 const bob = privateKey('//Bob');74 const charlie = privateKey('//Charlie');7576 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();77 expect(collection.Owner).to.be.deep.eq(alice.address);7879 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);80 await submitTransactionAsync(alice, changeOwnerTx);8182 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();83 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);8485 // After changing the owner of the collection, all privileged methods are available to the new owner86 // The new owner of the collection has access to sponsorship management operations in the collection87 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');88 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');89 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');9091 // The new owner of the collection has access to operations for managing the collection parameters92 const collectionLimits = {93 AccountTokenOwnershipLimit: 1,94 SponsoredMintSize: 1,95 TokenLimit: 1,96 SponsorTimeout: 1,97 OwnerCanTransfer: true,98 OwnerCanDestroy: true,99 };100 const tx1 = api.tx.nft.setCollectionLimits(101 collectionId,102 collectionLimits,103 );104 await submitTransactionAsync(bob, tx1);105106 await enableWhiteListExpectSuccess(bob, collectionId);107 await setMintPermissionExpectSuccess(bob, collectionId, true);108 await destroyCollectionExpectSuccess(collectionId, '//Bob');109 });110 });111});112113describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {114 it('Not owner can\'t change owner.', async () => {115 await usingApi(async api => {116 const collectionId = await createCollectionExpectSuccess();117 const alice = privateKey('//Alice');118 const bob = privateKey('//Bob');119120 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);121 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;122123 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();124 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);125126 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)127 await createCollectionExpectSuccess();128 });129 });130131 it('Collection admin can\'t change owner.', async () => {132 await usingApi(async api => {133 const collectionId = await createCollectionExpectSuccess();134 const alice = privateKey('//Alice');135 const bob = privateKey('//Bob');136137 await addCollectionAdminExpectSuccess(alice, collectionId, bob);138139 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);140 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;141142 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();143 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);144145 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)146 await createCollectionExpectSuccess();147 });148 });149150 it('Can\'t change owner of a non-existing collection.', async () => {151 await usingApi(async api => {152 const collectionId = (1<<32) - 1;153 const alice = privateKey('//Alice');154 const bob = privateKey('//Bob');155156 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);157 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;158159 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)160 await createCollectionExpectSuccess();161 });162 });163164 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {165 await usingApi(async api => {166 const collectionId = await createCollectionExpectSuccess();167 const alice = privateKey('//Alice');168 const bob = privateKey('//Bob');169 const charlie = privateKey('//Charlie');170171 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();172 expect(collection.Owner).to.be.deep.eq(alice.address);173174 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);175 await submitTransactionAsync(alice, changeOwnerTx);176177 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);178 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;179180 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();181 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);182183 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');184 await confirmSponsorshipExpectFailure(collectionId, '//Alice');185 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');186187 const collectionLimits = {188 AccountTokenOwnershipLimit: 1,189 SponsoredMintSize: 1,190 TokenLimit: 1,191 SponsorTimeout: 1,192 OwnerCanTransfer: true,193 OwnerCanDestroy: true,194 };195 const tx1 = api.tx.nft.setCollectionLimits(196 collectionId,197 collectionLimits,198 );199 await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;200201 await enableWhiteListExpectFail(alice, collectionId);202 await setMintPermissionExpectFailure(alice, collectionId, true);203 await destroyCollectionExpectFailure(collectionId, '//Alice');204 });205 });206});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -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');
}