git.delta.rocks / unique-network / refs/commits / dfb31491c2fc

difftreelog

source

tests/src/change-collection-owner.test.ts11.0 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {createCollectionExpectSuccess,21  addCollectionAdminExpectSuccess,22  setCollectionSponsorExpectSuccess,23  confirmSponsorshipExpectSuccess,24  removeCollectionSponsorExpectSuccess,25  enableAllowListExpectSuccess,26  setMintPermissionExpectSuccess,27  destroyCollectionExpectSuccess,28  setCollectionSponsorExpectFailure,29  confirmSponsorshipExpectFailure,30  removeCollectionSponsorExpectFailure,31  enableAllowListExpectFail,32  setMintPermissionExpectFailure,33  destroyCollectionExpectFailure,34  setPublicAccessModeExpectSuccess,35  queryCollectionExpectSuccess,36} from './util/helpers';3738chai.use(chaiAsPromised);39const expect = chai.expect;4041describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {42  it('Changing owner changes owner address', async () => {43    await usingApi(async (api, privateKeyWrapper) => {44      const collectionId = await createCollectionExpectSuccess();45      const alice = privateKeyWrapper('//Alice');46      const bob = privateKeyWrapper('//Bob');4748      const collection =await queryCollectionExpectSuccess(api, collectionId);49      expect(collection.owner.toString()).to.be.deep.eq(alice.address);5051      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);52      await submitTransactionAsync(alice, changeOwnerTx);5354      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);55      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);56    });57  });58});5960describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {61  it('Changing the owner of the collection is not allowed for the former owner', async () => {62    await usingApi(async (api, privateKeyWrapper) => {63      const collectionId = await createCollectionExpectSuccess();64      const alice = privateKeyWrapper('//Alice');65      const bob = privateKeyWrapper('//Bob');6667      const collection = await queryCollectionExpectSuccess(api, collectionId);68      expect(collection.owner.toString()).to.be.deep.eq(alice.address);6970      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);71      await submitTransactionAsync(alice, changeOwnerTx);7273      const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);74      await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;7576      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);77      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);78    });79  });8081  it('New collectionOwner has access to sponsorship management operations in the collection', async () => {82    await usingApi(async (api, privateKeyWrapper) => {83      const collectionId = await createCollectionExpectSuccess();84      const alice = privateKeyWrapper('//Alice');85      const bob = privateKeyWrapper('//Bob');86      const charlie = privateKeyWrapper('//Charlie');8788      const collection = await queryCollectionExpectSuccess(api, collectionId);89      expect(collection.owner.toString()).to.be.deep.eq(alice.address);9091      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);92      await submitTransactionAsync(alice, changeOwnerTx);9394      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);95      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);9697      // After changing the owner of the collection, all privileged methods are available to the new owner98      // The new owner of the collection has access to sponsorship management operations in the collection99      await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');100      await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');101      await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');102103      // The new owner of the collection has access to operations for managing the collection parameters104      const collectionLimits = {105        accountTokenOwnershipLimit: 1,106        sponsoredMintSize: 1,107        tokenLimit: 1,108        sponsorTransferTimeout: 1,109        ownerCanTransfer: true,110        ownerCanDestroy: true,111      };112      const tx1 = api.tx.unique.setCollectionLimits(113        collectionId,114        collectionLimits,115      );116      await submitTransactionAsync(bob, tx1);117118      await setPublicAccessModeExpectSuccess(bob, collectionId, 'AllowList');119      await enableAllowListExpectSuccess(bob, collectionId);120      await setMintPermissionExpectSuccess(bob, collectionId, true);121      await destroyCollectionExpectSuccess(collectionId, '//Bob');122    });123  });124125  it('New collectionOwner has access to changeCollectionOwner', async () => {126    await usingApi(async (api, privateKeyWrapper) => {127      const collectionId = await createCollectionExpectSuccess();128      const alice = privateKeyWrapper('//Alice');129      const bob = privateKeyWrapper('//Bob');130      const charlie = privateKeyWrapper('//Charlie');131132      const collection = await queryCollectionExpectSuccess(api, collectionId);133      expect(collection.owner.toString()).to.be.deep.eq(alice.address);134135      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);136      await submitTransactionAsync(alice, changeOwnerTx);137138      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);139      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);140141      const changeOwnerTx2 = api.tx.unique.changeCollectionOwner(collectionId, charlie.address);142      await submitTransactionAsync(bob, changeOwnerTx2);143144      // ownership lost145      const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);146      expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);147    });148  });149});150151describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {152  it('Not owner can\'t change owner.', async () => {153    await usingApi(async (api, privateKeyWrapper) => {154      const collectionId = await createCollectionExpectSuccess();155      const alice = privateKeyWrapper('//Alice');156      const bob = privateKeyWrapper('//Bob');157158      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);159      await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;160161      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);162      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);163164      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)165      await createCollectionExpectSuccess();166    });167  });168169  it('Collection admin can\'t change owner.', async () => {170    await usingApi(async (api, privateKeyWrapper) => {171      const collectionId = await createCollectionExpectSuccess();172      const alice = privateKeyWrapper('//Alice');173      const bob = privateKeyWrapper('//Bob');174175      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);176177      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);178      await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;179180      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);181      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);182183      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)184      await createCollectionExpectSuccess();185    });186  });187188  it('Can\'t change owner of a non-existing collection.', async () => {189    await usingApi(async (api, privateKeyWrapper) => {190      const collectionId = (1<<32) - 1;191      const alice = privateKeyWrapper('//Alice');192      const bob = privateKeyWrapper('//Bob');193194      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);195      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;196197      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)198      await createCollectionExpectSuccess();199    });200  });201202  it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {203    await usingApi(async (api, privateKeyWrapper) => {204      const collectionId = await createCollectionExpectSuccess();205      const alice = privateKeyWrapper('//Alice');206      const bob = privateKeyWrapper('//Bob');207      const charlie = privateKeyWrapper('//Charlie');208209      const collection = await queryCollectionExpectSuccess(api, collectionId);210      expect(collection.owner.toString()).to.be.deep.eq(alice.address);211212      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);213      await submitTransactionAsync(alice, changeOwnerTx);214215      const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);216      await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;217218      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);219      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);220221      await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');222      await confirmSponsorshipExpectFailure(collectionId, '//Alice');223      await removeCollectionSponsorExpectFailure(collectionId, '//Alice');224225      const collectionLimits = {226        accountTokenOwnershipLimit: 1,227        sponsoredMintSize: 1,228        tokenLimit: 1,229        sponsorTransferTimeout: 1,230        ownerCanTransfer: true,231        ownerCanDestroy: true,232      };233      const tx1 = api.tx.unique.setCollectionLimits(234        collectionId,235        collectionLimits,236      );237      await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;238239      await enableAllowListExpectFail(alice, collectionId);240      await setMintPermissionExpectFailure(alice, collectionId, true);241      await destroyCollectionExpectFailure(collectionId, '//Alice');242    });243  });244});