1234567891011121314151617import {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});