git.delta.rocks / unique-network / refs/commits / 83994a56b4ab

difftreelog

New test added

str-mv2021-08-13parent: #6b16ace.patch.diff
in: master

1 file changed

modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
before · tests/src/change-collection-owner.test.ts
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});
after · tests/src/change-collection-owner.test.ts
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  setPublicAccessModeExpectSuccess,25} from './util/helpers';2627chai.use(chaiAsPromised);28const expect = chai.expect;2930describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {31  it('Changing owner changes owner address', async () => {32    await usingApi(async api => {33      const collectionId = await createCollectionExpectSuccess();34      const alice = privateKey('//Alice');35      const bob = privateKey('//Bob');3637      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();38      expect(collection.Owner).to.be.deep.eq(alice.address);3940      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);41      await submitTransactionAsync(alice, changeOwnerTx);4243      const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();44      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);45    });46  });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});139140describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {141  it('Not owner can\'t change owner.', async () => {142    await usingApi(async api => {143      const collectionId = await createCollectionExpectSuccess();144      const alice = privateKey('//Alice');145      const bob = privateKey('//Bob');146147      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);148      await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;149150      const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();151      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);152153      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)154      await createCollectionExpectSuccess();155    });156  });157158  it('Collection admin can\'t change owner.', async () => {159    await usingApi(async api => {160      const collectionId = await createCollectionExpectSuccess();161      const alice = privateKey('//Alice');162      const bob = privateKey('//Bob');163164      await addCollectionAdminExpectSuccess(alice, collectionId, bob);165166      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);167      await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;168169      const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();170      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);171172      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)173      await createCollectionExpectSuccess();174    });175  });176177  it('Can\'t change owner of a non-existing collection.', async () => {178    await usingApi(async api => {179      const collectionId = (1<<32) - 1;180      const alice = privateKey('//Alice');181      const bob = privateKey('//Bob');182183      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);184      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;185186      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)187      await createCollectionExpectSuccess();188    });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  });233});