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

difftreelog

change-collection-owner migrated

rkv2022-09-09parent: #5401624.patch.diff
in: master

1 file changed

modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
before · tests/src/change-collection-owner.test.ts
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});
after · tests/src/change-collection-owner.test.ts
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 {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28  await usingPlaygrounds(async (_, privateKey) => {29    donor = privateKey('//Alice');30  });31});3233describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {34  let alice: IKeyringPair;35  let bob: IKeyringPair;3637  before(async () => {38    await usingPlaygrounds(async (helper) => {39      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);40    });41  });4243  it('Changing owner changes owner address', async () => {44    await usingPlaygrounds(async (helper) => {45      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});46      const beforeChanging = await helper.collection.getData(collection.collectionId);47      expect(beforeChanging?.normalizedOwner).to.be.equal(alice.address);4849      await collection.changeOwner(alice, bob.address);50      const afterChanging = await helper.collection.getData(collection.collectionId);51      expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);52    });53  });54});5556describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {57  let alice: IKeyringPair;58  let bob: IKeyringPair;59  let charlie: IKeyringPair;6061  before(async () => {62    await usingPlaygrounds(async (helper) => {63      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);64    });65  });6667  it('Changing the owner of the collection is not allowed for the former owner', async () => {68    await usingPlaygrounds(async (helper) => {69      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});7071      await collection.changeOwner(alice, bob.address);7273      const changeOwnerTx = async () => collection.changeOwner(alice, alice.address);74      await expect(changeOwnerTx()).to.be.rejected;7576      const afterChanging = await helper.collection.getData(collection.collectionId);77      expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);78    });79  });8081  it('New collectionOwner has access to sponsorship management operations in the collection', async () => {82    await usingPlaygrounds(async (helper) => {83      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});84      await collection.changeOwner(alice, bob.address);8586      const afterChanging = await helper.collection.getData(collection.collectionId);87      expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);8889      await collection.setSponsor(bob, charlie.address);90      await collection.confirmSponsorship(charlie);91      await collection.removeSponsor(bob);92      const limits = {93        accountTokenOwnershipLimit: 1,94        tokenLimit: 1,95        sponsorTransferTimeout: 1,96        ownerCanDestroy: true,97        ownerCanTransfer: true,98      };99100      await collection.setLimits(bob, limits);101      const gotLimits = await collection.getEffectiveLimits();102      expect(gotLimits).to.be.deep.contains(limits);103104      await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});105106      await collection.burn(bob);107      const collectionData = await helper.collection.getData(collection.collectionId);108      expect(collectionData).to.be.null;109    });110  });111112  it('New collectionOwner has access to changeCollectionOwner', async () => {113    await usingPlaygrounds(async (helper) => {114      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});115      await collection.changeOwner(alice, bob.address);116      await collection.changeOwner(bob, charlie.address);117      const collectionData = await collection.getData();118      expect(collectionData?.normalizedOwner).to.be.equal(charlie.address);119    });120  });121});122123describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {124  let alice: IKeyringPair;125  let bob: IKeyringPair;126  let charlie: IKeyringPair;127128  before(async () => {129    await usingPlaygrounds(async (helper) => {130      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);131    });132  });133134  it('Not owner can\'t change owner.', async () => {135    await usingPlaygrounds(async (helper) => {136      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});137      const changeOwnerTx = async () => collection.changeOwner(bob, bob.address);138      await expect(changeOwnerTx()).to.be.rejected;139    });140  });141142  it('Collection admin can\'t change owner.', async () => {143    await usingPlaygrounds(async (helper) => {144      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});145      await collection.addAdmin(alice, {Substrate: bob.address});146      const changeOwnerTx = async () => collection.changeOwner(bob, bob.address);147      await expect(changeOwnerTx()).to.be.rejected;148    });149  });150151  it('Can\'t change owner of a non-existing collection.', async () => {152    await usingPlaygrounds(async (helper) => {153      const collectionId = (1 << 32) - 1;154      const changeOwnerTx = async () => helper.collection.changeOwner(bob, collectionId, bob.address);155      await expect(changeOwnerTx()).to.be.rejected;156    });157  });158159  it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {160    await usingPlaygrounds(async (helper) => {161      const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});162      await collection.changeOwner(alice, bob.address);163164      const changeOwnerTx = async () => collection.changeOwner(alice, alice.address);165      await expect(changeOwnerTx()).to.be.rejected;166167      const afterChanging = await helper.collection.getData(collection.collectionId);168      expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);169170      const setSponsorTx = async () => collection.setSponsor(alice, charlie.address);171      const confirmSponsorshipTx = async () => collection.confirmSponsorship(alice);172      const removeSponsorTx = async () => collection.removeSponsor(alice);173      await expect(setSponsorTx()).to.be.rejected;174      await expect(confirmSponsorshipTx()).to.be.rejected;175      await expect(removeSponsorTx()).to.be.rejected;176177      const limits = {178        accountTokenOwnershipLimit: 1,179        tokenLimit: 1,180        sponsorTransferTimeout: 1,181        ownerCanDestroy: true,182        ownerCanTransfer: true,183      };184185      const setLimitsTx = async () => collection.setLimits(alice, limits);186      await expect(setLimitsTx()).to.be.rejected;187188      const setPermissionTx = async () => collection.setPermissions(alice, {access: 'AllowList', mintMode: true});189      await expect(setPermissionTx()).to.be.rejected;190191      const burnTx = async () => collection.burn(alice);192      await expect(burnTx()).to.be.rejected;193    });194  });195});