123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';10import {createCollectionExpectSuccess,11 addCollectionAdminExpectSuccess,12 setCollectionSponsorExpectSuccess,13 confirmSponsorshipExpectSuccess,14 removeCollectionSponsorExpectSuccess,15 enableAllowListExpectSuccess,16 setMintPermissionExpectSuccess,17 destroyCollectionExpectSuccess,18 setCollectionSponsorExpectFailure,19 confirmSponsorshipExpectFailure,20 removeCollectionSponsorExpectFailure,21 enableAllowListExpectFail,22 setMintPermissionExpectFailure,23 destroyCollectionExpectFailure,24 setPublicAccessModeExpectSuccess,25 queryCollectionExpectSuccess,26} from './util/helpers';2728chai.use(chaiAsPromised);29const expect = chai.expect;3031describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {32 it('Changing owner changes owner address', async () => {33 await usingApi(async api => {34 const collectionId = await createCollectionExpectSuccess();35 const alice = privateKey('//Alice');36 const bob = privateKey('//Bob');3738 const collection =await queryCollectionExpectSuccess(api, collectionId);39 expect(collection.owner.toString()).to.be.deep.eq(alice.address);4041 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);42 await submitTransactionAsync(alice, changeOwnerTx);4344 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);45 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);46 });47 });48});4950describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {51 it('Changing the owner of the collection is not allowed for the former owner', async () => {52 await usingApi(async api => {53 const collectionId = await createCollectionExpectSuccess();54 const alice = privateKey('//Alice');55 const bob = privateKey('//Bob');5657 const collection = await queryCollectionExpectSuccess(api, collectionId);58 expect(collection.owner.toString()).to.be.deep.eq(alice.address);5960 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);61 await submitTransactionAsync(alice, changeOwnerTx);6263 const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);64 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;6566 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);67 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);68 });69 });7071 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {72 await usingApi(async api => {73 const collectionId = await createCollectionExpectSuccess();74 const alice = privateKey('//Alice');75 const bob = privateKey('//Bob');76 const charlie = privateKey('//Charlie');7778 const collection = await queryCollectionExpectSuccess(api, collectionId);79 expect(collection.owner.toString()).to.be.deep.eq(alice.address);8081 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);82 await submitTransactionAsync(alice, changeOwnerTx);8384 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);85 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);8687 88 89 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');90 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');91 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');9293 94 const collectionLimits = {95 accountTokenOwnershipLimit: 1,96 sponsoredMintSize: 1,97 tokenLimit: 1,98 sponsorTransferTimeout: 1,99 ownerCanTransfer: true,100 ownerCanDestroy: true,101 };102 const tx1 = api.tx.unique.setCollectionLimits(103 collectionId,104 collectionLimits,105 );106 await submitTransactionAsync(bob, tx1);107108 await setPublicAccessModeExpectSuccess(bob, collectionId, 'AllowList');109 await enableAllowListExpectSuccess(bob, collectionId);110 await setMintPermissionExpectSuccess(bob, collectionId, true);111 await destroyCollectionExpectSuccess(collectionId, '//Bob');112 });113 });114115 it('New collectionOwner has access to changeCollectionOwner', async () => {116 await usingApi(async api => {117 const collectionId = await createCollectionExpectSuccess();118 const alice = privateKey('//Alice');119 const bob = privateKey('//Bob');120 const charlie = privateKey('//Charlie');121122 const collection = await queryCollectionExpectSuccess(api, collectionId);123 expect(collection.owner.toString()).to.be.deep.eq(alice.address);124125 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);126 await submitTransactionAsync(alice, changeOwnerTx);127128 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);129 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);130131 const changeOwnerTx2 = api.tx.unique.changeCollectionOwner(collectionId, charlie.address);132 await submitTransactionAsync(bob, changeOwnerTx2);133134 135 const collectionAfterOwnerChange2 = await queryCollectionExpectSuccess(api, collectionId);136 expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);137 });138 });139});140141describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {142 it('Not owner can\'t change owner.', async () => {143 await usingApi(async api => {144 const collectionId = await createCollectionExpectSuccess();145 const alice = privateKey('//Alice');146 const bob = privateKey('//Bob');147148 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);149 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;150151 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);152 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);153154 155 await createCollectionExpectSuccess();156 });157 });158159 it('Collection admin can\'t change owner.', async () => {160 await usingApi(async api => {161 const collectionId = await createCollectionExpectSuccess();162 const alice = privateKey('//Alice');163 const bob = privateKey('//Bob');164165 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);166167 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);168 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;169170 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);171 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);172173 174 await createCollectionExpectSuccess();175 });176 });177178 it('Can\'t change owner of a non-existing collection.', async () => {179 await usingApi(async api => {180 const collectionId = (1<<32) - 1;181 const alice = privateKey('//Alice');182 const bob = privateKey('//Bob');183184 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);185 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;186187 188 await createCollectionExpectSuccess();189 });190 });191192 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {193 await usingApi(async api => {194 const collectionId = await createCollectionExpectSuccess();195 const alice = privateKey('//Alice');196 const bob = privateKey('//Bob');197 const charlie = privateKey('//Charlie');198199 const collection = await queryCollectionExpectSuccess(api, collectionId);200 expect(collection.owner.toString()).to.be.deep.eq(alice.address);201202 const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);203 await submitTransactionAsync(alice, changeOwnerTx);204205 const badChangeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, alice.address);206 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;207208 const collectionAfterOwnerChange = await queryCollectionExpectSuccess(api, collectionId);209 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);210211 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');212 await confirmSponsorshipExpectFailure(collectionId, '//Alice');213 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');214215 const collectionLimits = {216 accountTokenOwnershipLimit: 1,217 sponsoredMintSize: 1,218 tokenLimit: 1,219 sponsorTransferTimeout: 1,220 ownerCanTransfer: true,221 ownerCanDestroy: true,222 };223 const tx1 = api.tx.unique.setCollectionLimits(224 collectionId,225 collectionLimits,226 );227 await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;228229 await enableAllowListExpectFail(alice, collectionId);230 await setMintPermissionExpectFailure(alice, collectionId, true);231 await destroyCollectionExpectFailure(collectionId, '//Alice');232 });233 });234});