difftreelog
change-collection-owner migrated
in: master
1 file changed
tests/src/change-collection-owner.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import chai from 'chai';18import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {createCollectionExpectSuccess,20import {usingPlaygrounds} from './util/playgrounds';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';372138chai.use(chaiAsPromised);22chai.use(chaiAsPromised);39const expect = chai.expect;23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKey) => {29 donor = privateKey('//Alice');30 });31});403241describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {33describe('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 });4242 it('Changing owner changes owner address', async () => {43 it('Changing owner changes owner address', async () => {43 await usingApi(async (api, privateKeyWrapper) => {44 await usingPlaygrounds(async (helper) => {44 const collectionId = await createCollectionExpectSuccess();45 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});45 const alice = privateKeyWrapper('//Alice');46 const bob = privateKeyWrapper('//Bob');4748 const collection =await queryCollectionExpectSuccess(api, collectionId);46 const beforeChanging = await helper.collection.getData(collection.collectionId);49 expect(collection.owner.toString()).to.be.deep.eq(alice.address);47 expect(beforeChanging?.normalizedOwner).to.be.equal(alice.address);504851 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);49 await collection.changeOwner(alice, bob.address);52 await submitTransactionAsync(alice, changeOwnerTx);5354 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);50 const afterChanging = await helper.collection.getData(collection.collectionId);55 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);51 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);56 });52 });57 });53 });58});54});595560describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {56describe('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 });6661 it('Changing the owner of the collection is not allowed for the former owner', async () => {67 it('Changing the owner of the collection is not allowed for the former owner', async () => {62 await usingApi(async (api, privateKeyWrapper) => {68 await usingPlaygrounds(async (helper) => {63 const collectionId = await createCollectionExpectSuccess();64 const alice = privateKeyWrapper('//Alice');65 const bob = privateKeyWrapper('//Bob');6667 const collection = await queryCollectionExpectSuccess(api, collectionId);69 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});68 expect(collection.owner.toString()).to.be.deep.eq(alice.address);697070 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);71 await collection.changeOwner(alice, bob.address);71 await submitTransactionAsync(alice, changeOwnerTx);727273 const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);73 const changeOwnerTx = async () => collection.changeOwner(alice, alice.address);74 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;74 await expect(changeOwnerTx()).to.be.rejected;757576 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);76 const afterChanging = await helper.collection.getData(collection.collectionId);77 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);77 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);78 });78 });79 });79 });808081 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {81 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {82 await usingApi(async (api, privateKeyWrapper) => {82 await usingPlaygrounds(async (helper) => {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);83 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});89 expect(collection.owner.toString()).to.be.deep.eq(alice.address);9091 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);84 await collection.changeOwner(alice, bob.address);92 await submitTransactionAsync(alice, changeOwnerTx);938594 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);86 const afterChanging = await helper.collection.getData(collection.collectionId);95 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);87 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);968897 // 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');89 await collection.setSponsor(bob, charlie.address);100 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');90 await collection.confirmSponsorship(charlie);101 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');91 await collection.removeSponsor(bob);102103 // The new owner of the collection has access to operations for managing the collection parameters104 const collectionLimits = {92 const limits = {105 accountTokenOwnershipLimit: 1,93 accountTokenOwnershipLimit: 1,106 sponsoredMintSize: 1,107 tokenLimit: 1,94 tokenLimit: 1,108 sponsorTransferTimeout: 1,95 sponsorTransferTimeout: 1,109 ownerCanTransfer: true,96 ownerCanDestroy: true,110 ownerCanDestroy: true,97 ownerCanTransfer: true,111 };98 };99100 await collection.setLimits(bob, limits);112 const tx1 = api.tx.unique.setCollectionLimits(101 const gotLimits = await collection.getEffectiveLimits();113 collectionId,114 collectionLimits,115 );116 await submitTransactionAsync(bob, tx1);102 expect(gotLimits).to.be.deep.contains(limits);117103118 await setPublicAccessModeExpectSuccess(bob, collectionId, 'AllowList');104 await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});105119 await enableAllowListExpectSuccess(bob, collectionId);106 await collection.burn(bob);120 await setMintPermissionExpectSuccess(bob, collectionId, true);107 const collectionData = await helper.collection.getData(collection.collectionId);121 await destroyCollectionExpectSuccess(collectionId, '//Bob');108 expect(collectionData).to.be.null;122 });109 });123 });110 });124111125 it('New collectionOwner has access to changeCollectionOwner', async () => {112 it('New collectionOwner has access to changeCollectionOwner', async () => {126 await usingApi(async (api, privateKeyWrapper) => {113 await usingPlaygrounds(async (helper) => {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);114 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});133 expect(collection.owner.toString()).to.be.deep.eq(alice.address);134135 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);115 await collection.changeOwner(alice, 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);116 await collection.changeOwner(bob, charlie.address);142 await submitTransactionAsync(bob, changeOwnerTx2);143144 // ownership lost145 const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);117 const collectionData = await collection.getData();146 expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);118 expect(collectionData?.normalizedOwner).to.be.equal(charlie.address);147 });119 });148 });120 });149});121});150122151describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {123describe('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 });133152 it('Not owner can\'t change owner.', async () => {134 it('Not owner can\'t change owner.', async () => {153 await usingApi(async (api, privateKeyWrapper) => {135 await usingPlaygrounds(async (helper) => {154 const collectionId = await createCollectionExpectSuccess();136 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});155 const alice = privateKeyWrapper('//Alice');156 const bob = privateKeyWrapper('//Bob');157158 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);137 const changeOwnerTx = async () => collection.changeOwner(bob, bob.address);159 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;138 await expect(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 });139 });167 });140 });168141169 it('Collection admin can\'t change owner.', async () => {142 it('Collection admin can\'t change owner.', async () => {170 await usingApi(async (api, privateKeyWrapper) => {143 await usingPlaygrounds(async (helper) => {171 const collectionId = await createCollectionExpectSuccess();144 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});172 const alice = privateKeyWrapper('//Alice');173 const bob = privateKeyWrapper('//Bob');174175 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);145 await collection.addAdmin(alice, {Substrate: bob.address});176177 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);146 const changeOwnerTx = async () => collection.changeOwner(bob, bob.address);178 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;147 await expect(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 });148 });186 });149 });187150188 it('Can\'t change owner of a non-existing collection.', async () => {151 it('Can\'t change owner of a non-existing collection.', async () => {189 await usingApi(async (api, privateKeyWrapper) => {152 await usingPlaygrounds(async (helper) => {190 const collectionId = (1<<32) - 1;153 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);154 const changeOwnerTx = async () => helper.collection.changeOwner(bob, collectionId, bob.address);195 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;155 await expect(changeOwnerTx()).to.be.rejected;196197 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)198 await createCollectionExpectSuccess();199 });156 });200 });157 });201158202 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {159 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {203 await usingApi(async (api, privateKeyWrapper) => {160 await usingPlaygrounds(async (helper) => {204 const collectionId = await createCollectionExpectSuccess();161 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});205 const alice = privateKeyWrapper('//Alice');162 await collection.changeOwner(alice, bob.address);163206 const bob = privateKeyWrapper('//Bob');164 const changeOwnerTx = async () => collection.changeOwner(alice, alice.address);207 const charlie = privateKeyWrapper('//Charlie');165 await expect(changeOwnerTx()).to.be.rejected;208166209 const collection = await queryCollectionExpectSuccess(api, collectionId);167 const afterChanging = await helper.collection.getData(collection.collectionId);210 expect(collection.owner.toString()).to.be.deep.eq(alice.address);168 expect(afterChanging?.normalizedOwner).to.be.equal(bob.address);211169212 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);170 const setSponsorTx = async () => collection.setSponsor(alice, charlie.address);213 await submitTransactionAsync(alice, changeOwnerTx);171 const confirmSponsorshipTx = async () => collection.confirmSponsorship(alice);214215 const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);172 const removeSponsorTx = async () => collection.removeSponsor(alice);216 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;173 await expect(setSponsorTx()).to.be.rejected;217218 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);219 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);174 await expect(confirmSponsorshipTx()).to.be.rejected;220221 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');175 await expect(removeSponsorTx()).to.be.rejected;222 await confirmSponsorshipExpectFailure(collectionId, '//Alice');223 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');224176225 const collectionLimits = {177 const limits = {226 accountTokenOwnershipLimit: 1,178 accountTokenOwnershipLimit: 1,227 sponsoredMintSize: 1,228 tokenLimit: 1,179 tokenLimit: 1,229 sponsorTransferTimeout: 1,180 sponsorTransferTimeout: 1,230 ownerCanTransfer: true,181 ownerCanDestroy: true,231 ownerCanDestroy: true,182 ownerCanTransfer: true,232 };183 };184233 const tx1 = api.tx.unique.setCollectionLimits(185 const setLimitsTx = async () => collection.setLimits(alice, limits);234 collectionId,235 collectionLimits,236 );237 await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;186 await expect(setLimitsTx()).to.be.rejected;238187239 await enableAllowListExpectFail(alice, collectionId);188 const setPermissionTx = async () => collection.setPermissions(alice, {access: 'AllowList', mintMode: true});189 await expect(setPermissionTx()).to.be.rejected;190240 await setMintPermissionExpectFailure(alice, collectionId, true);191 const burnTx = async () => collection.burn(alice);241 await destroyCollectionExpectFailure(collectionId, '//Alice');192 await expect(burnTx()).to.be.rejected;242 });193 });243 });194 });244});195});