difftreelog
CORE-161. Change collection owner integration tests
in: master
3 files changed
tests/src/change-collection-owner.test.tsdiffbeforeafterboth8import privateKey from './substrate/privateKey';8import privateKey from './substrate/privateKey';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';10import { createCollectionExpectSuccess, 11 addCollectionAdminExpectSuccess,12 setCollectionSponsorExpectSuccess,13 confirmSponsorshipExpectSuccess,14 removeCollectionSponsorExpectSuccess,15 enableWhiteListExpectSuccess,16 setMintPermissionExpectSuccess,17 destroyCollectionExpectSuccess,18} from './util/helpers';111912chai.use(chaiAsPromised);20chai.use(chaiAsPromised);31 });39 });32});40});4142describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {43 it('Changing the owner of the collection is not allowed for the former owner', async () => {44 await usingApi(async api => {45 const collectionId = await createCollectionExpectSuccess();46 const alice = privateKey('//Alice');47 const bob = privateKey('//Bob');4849 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();50 expect(collection.Owner).to.be.deep.eq(alice.address);5152 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);53 await submitTransactionAsync(alice, changeOwnerTx);5455 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);56 await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;5758 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();59 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);60 });61 });6263 it('New collectionOwner has access to sponsorship management operations in the collection', async () => {64 await usingApi(async api => {65 const collectionId = await createCollectionExpectSuccess();66 const alice = privateKey('//Alice');67 const bob = privateKey('//Bob');68 const charlie = privateKey('//Charlie');6970 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();71 expect(collection.Owner).to.be.deep.eq(alice.address);7273 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);74 await submitTransactionAsync(alice, changeOwnerTx);7576 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();77 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);7879 // After changing the owner of the collection, all privileged methods are available to the new owner80 // The new owner of the collection has access to sponsorship management operations in the collection81 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');82 await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');83 await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');8485 // The new owner of the collection has access to operations for managing the collection parameters86 const collectionLimits = {87 AccountTokenOwnershipLimit: 1,88 SponsoredMintSize: 1,89 TokenLimit: 1,90 SponsorTimeout: 1,91 OwnerCanTransfer: true,92 OwnerCanDestroy: true,93 };94 const tx1 = api.tx.nft.setCollectionLimits(95 collectionId,96 collectionLimits,97 );98 await submitTransactionAsync(bob, tx1);99100 await enableWhiteListExpectSuccess(bob, collectionId);101 await setMintPermissionExpectSuccess(bob, collectionId, true);102 await destroyCollectionExpectSuccess(collectionId, '//Bob');103 });104 });105});3310634describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {107describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {35 it('Not owner can\'t change owner.', async () => {108 it('Not owner can\'t change owner.', async () => {82 });155 });83 });156 });157158 it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {159 await usingApi(async api => {160 const collectionId = await createCollectionExpectSuccess();161 const alice = privateKey('//Alice');162 const bob = privateKey('//Bob');163 const charlie = privateKey('//Charlie');164165 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();166 expect(collection.Owner).to.be.deep.eq(alice.address);167168 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);169 await submitTransactionAsync(alice, changeOwnerTx);170171 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);172 await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;173174 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();175 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);176177 await expect(setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Alice')).to.be.rejected;178 await expect(confirmSponsorshipExpectSuccess(collectionId, '//Alice')).to.be.rejected;179 await expect(removeCollectionSponsorExpectSuccess(collectionId, '//Alice')).to.be.rejected;180181 const collectionLimits = {182 AccountTokenOwnershipLimit: 1,183 SponsoredMintSize: 1,184 TokenLimit: 1,185 SponsorTimeout: 1,186 OwnerCanTransfer: true,187 OwnerCanDestroy: true,188 };189 const tx1 = api.tx.nft.setCollectionLimits(190 collectionId,191 collectionLimits,192 );193 await expect(submitTransactionAsync(alice, tx1)).to.be.rejected;194195 await expect(enableWhiteListExpectSuccess(alice, collectionId)).to.be.rejected;196 await expect(setMintPermissionExpectSuccess(alice, collectionId, true)).to.be.rejected;197 await expect(destroyCollectionExpectSuccess(collectionId, '//Alice')).to.be.rejected;198 });199 });84});200});85201tests/src/setChainLimits.test.tsdiffbeforeafterboth13 IChainLimits,13 IChainLimits,14} from './util/helpers';14} from './util/helpers';151516describe.only('Negative Integration Test setChainLimits', () => {16describe('Negative Integration Test setChainLimits', () => {17 let alice: IKeyringPair;17 let alice: IKeyringPair;18 let bob: IKeyringPair;18 let bob: IKeyringPair;19 let dave: IKeyringPair;19 let dave: IKeyringPair;tests/src/util/helpers.tsdiffbeforeafterboth431 });431 });432}432}433433434export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {434export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {435 await usingApi(async (api) => {435 await usingApi(async (api) => {436436437 // Run the transaction437 // Run the transaction438 const alicePrivateKey = privateKey('//Alice');438 const senderPrivateKey = privateKey(sender);439 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);439 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);440 const events = await submitTransactionAsync(alicePrivateKey, tx);440 const events = await submitTransactionAsync(senderPrivateKey, tx);441 const result = getGenericResult(events);441 const result = getGenericResult(events);442442443 // Get the collection443 // Get the collection451 });451 });452}452}453453454export async function removeCollectionSponsorExpectSuccess(collectionId: number) {454export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {455 await usingApi(async (api) => {455 await usingApi(async (api) => {456456457 // Run the transaction457 // Run the transaction458 const alicePrivateKey = privateKey('//Alice');458 const alicePrivateKey = privateKey(sender);459 const tx = api.tx.nft.removeCollectionSponsor(collectionId);459 const tx = api.tx.nft.removeCollectionSponsor(collectionId);460 const events = await submitTransactionAsync(alicePrivateKey, tx);460 const events = await submitTransactionAsync(alicePrivateKey, tx);461 const result = getGenericResult(events);461 const result = getGenericResult(events);