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

difftreelog

source

tests/src/change-collection-owner.test.ts10.7 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 privateKey from './substrate/privateKey';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {createCollectionExpectSuccess,22  addCollectionAdminExpectSuccess,23  setCollectionSponsorExpectSuccess,24  confirmSponsorshipExpectSuccess,25  removeCollectionSponsorExpectSuccess,26  enableAllowListExpectSuccess,27  setMintPermissionExpectSuccess,28  destroyCollectionExpectSuccess,29  setCollectionSponsorExpectFailure,30  confirmSponsorshipExpectFailure,31  removeCollectionSponsorExpectFailure,32  enableAllowListExpectFail,33  setMintPermissionExpectFailure,34  destroyCollectionExpectFailure,35  setPublicAccessModeExpectSuccess,36  queryCollectionExpectSuccess,37} from './util/helpers';3839chai.use(chaiAsPromised);40const expect = chai.expect;4142describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {43  it('Changing owner changes owner address', async () => {44    await usingApi(async api => {45      const collectionId = await createCollectionExpectSuccess();46      const alice = privateKey('//Alice');47      const bob = privateKey('//Bob');4849      const collection =await queryCollectionExpectSuccess(api, collectionId);50      expect(collection.owner.toString()).to.be.deep.eq(alice.address);5152      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);53      await submitTransactionAsync(alice, changeOwnerTx);5455      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);56      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);57    });58  });59});6061describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {62  it('Changing the owner of the collection is not allowed for the former owner', async () => {63    await usingApi(async api => {64      const collectionId = await createCollectionExpectSuccess();65      const alice = privateKey('//Alice');66      const bob = privateKey('//Bob');6768      const collection = await queryCollectionExpectSuccess(api, collectionId);69      expect(collection.owner.toString()).to.be.deep.eq(alice.address);7071      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);72      await submitTransactionAsync(alice, changeOwnerTx);7374      const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);75      await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;7677      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);78      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);79    });80  });8182  it('New collectionOwner has access to sponsorship management operations in the collection', async () => {83    await usingApi(async api => {84      const collectionId = await createCollectionExpectSuccess();85      const alice = privateKey('//Alice');86      const bob = privateKey('//Bob');87      const charlie = privateKey('//Charlie');8889      const collection = await queryCollectionExpectSuccess(api, collectionId);90      expect(collection.owner.toString()).to.be.deep.eq(alice.address);9192      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);93      await submitTransactionAsync(alice, changeOwnerTx);9495      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);96      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);9798      // After changing the owner of the collection, all privileged methods are available to the new owner99      // The new owner of the collection has access to sponsorship management operations in the collection100      await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');101      await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');102      await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');103104      // The new owner of the collection has access to operations for managing the collection parameters105      const collectionLimits = {106        accountTokenOwnershipLimit: 1,107        sponsoredMintSize: 1,108        tokenLimit: 1,109        sponsorTransferTimeout: 1,110        ownerCanTransfer: true,111        ownerCanDestroy: true,112      };113      const tx1 = api.tx.unique.setCollectionLimits(114        collectionId,115        collectionLimits,116      );117      await submitTransactionAsync(bob, tx1);118119      await setPublicAccessModeExpectSuccess(bob, collectionId, 'AllowList');120      await enableAllowListExpectSuccess(bob, collectionId);121      await setMintPermissionExpectSuccess(bob, collectionId, true);122      await destroyCollectionExpectSuccess(collectionId, '//Bob');123    });124  });125126  it('New collectionOwner has access to changeCollectionOwner', async () => {127    await usingApi(async api => {128      const collectionId = await createCollectionExpectSuccess();129      const alice = privateKey('//Alice');130      const bob = privateKey('//Bob');131      const charlie = privateKey('//Charlie');132133      const collection = await queryCollectionExpectSuccess(api, collectionId);134      expect(collection.owner.toString()).to.be.deep.eq(alice.address);135136      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);137      await submitTransactionAsync(alice, changeOwnerTx);138139      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);140      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);141142      const changeOwnerTx2 = api.tx.unique.changeCollectionOwner(collectionId, charlie.address);143      await submitTransactionAsync(bob, changeOwnerTx2);144145      // ownership lost146      const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);147      expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);148    });149  });150});151152describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {153  it('Not owner can\'t change owner.', async () => {154    await usingApi(async api => {155      const collectionId = await createCollectionExpectSuccess();156      const alice = privateKey('//Alice');157      const bob = privateKey('//Bob');158159      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);160      await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;161162      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);163      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);164165      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)166      await createCollectionExpectSuccess();167    });168  });169170  it('Collection admin can\'t change owner.', async () => {171    await usingApi(async api => {172      const collectionId = await createCollectionExpectSuccess();173      const alice = privateKey('//Alice');174      const bob = privateKey('//Bob');175176      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);177178      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);179      await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;180181      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);182      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);183184      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)185      await createCollectionExpectSuccess();186    });187  });188189  it('Can\'t change owner of a non-existing collection.', async () => {190    await usingApi(async api => {191      const collectionId = (1<<32) - 1;192      const alice = privateKey('//Alice');193      const bob = privateKey('//Bob');194195      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);196      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;197198      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)199      await createCollectionExpectSuccess();200    });201  });202203  it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {204    await usingApi(async api => {205      const collectionId = await createCollectionExpectSuccess();206      const alice = privateKey('//Alice');207      const bob = privateKey('//Bob');208      const charlie = privateKey('//Charlie');209210      const collection = await queryCollectionExpectSuccess(api, collectionId);211      expect(collection.owner.toString()).to.be.deep.eq(alice.address);212213      const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);214      await submitTransactionAsync(alice, changeOwnerTx);215216      const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);217      await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;218219      const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);220      expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);221222      await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');223      await confirmSponsorshipExpectFailure(collectionId, '//Alice');224      await removeCollectionSponsorExpectFailure(collectionId, '//Alice');225226      const collectionLimits = {227        accountTokenOwnershipLimit: 1,228        sponsoredMintSize: 1,229        tokenLimit: 1,230        sponsorTransferTimeout: 1,231        ownerCanTransfer: true,232        ownerCanDestroy: true,233      };234      const tx1 = api.tx.unique.setCollectionLimits(235        collectionId,236        collectionLimits,237      );238      await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;239240      await enableAllowListExpectFail(alice, collectionId);241      await setMintPermissionExpectFailure(alice, collectionId, true);242      await destroyCollectionExpectFailure(collectionId, '//Alice');243    });244  });245});