1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/index.js';19import {NON_EXISTENT_COLLECTION_ID} from '@unique/playgrounds/types.js';2021describe('integration test: ext. removeCollectionSponsor():', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;24 let bob: IKeyringPair;25 let charlie: IKeyringPair;2627 before(async () => {28 await usingPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({url: import.meta.url});30 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);31 });32 });3334 itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {35 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});36 await collection.setSponsor(alice, bob.address);37 await collection.confirmSponsorship(bob);38 await collection.removeSponsor(alice);3940 41 const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);4243 44 const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});4546 47 const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);48 await expect(token.transfer(zeroBalance, {Substrate: alice.address}))49 .to.be.rejectedWith('Inability to pay some fees');50 const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);5152 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);53 });5455 itSub('Remove a sponsor after it was already removed', async ({helper}) => {56 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});57 await collection.setSponsor(alice, bob.address);58 await collection.confirmSponsorship(bob);59 await expect(collection.removeSponsor(alice)).to.not.be.rejected;60 await expect(collection.removeSponsor(alice)).to.not.be.rejected;61 });6263 itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {64 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});65 await expect(collection.removeSponsor(alice)).to.not.be.rejected;66 });6768 itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {69 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});70 await collection.setSponsor(alice, bob.address);71 await expect(collection.removeSponsor(alice)).to.not.be.rejected;72 });7374 itSub('Remove a sponsor from a collection with collection admin permissions', async ({helper}) => {75 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});76 await collection.setSponsor(alice, bob.address);77 await collection.addAdmin(alice, {Substrate: charlie.address});78 await expect(collection.removeSponsor(charlie)).not.to.be.rejected;79 });80});8182describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {83 let alice: IKeyringPair;84 let bob: IKeyringPair;85 let charlie: IKeyringPair;8687 before(async () => {88 await usingPlaygrounds(async (helper, privateKey) => {89 const donor = await privateKey({url: import.meta.url});90 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);91 });92 });9394 itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {95 const collectionId = NON_EXISTENT_COLLECTION_ID;96 await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);97 });9899 itSub('(!negative test!) Remove sponsor for a collection by regular user', async ({helper}) => {100 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-2', tokenPrefix: 'RCS'});101 await collection.setSponsor(alice, bob.address);102 await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);103 });104105 itSub('(!negative test!) Remove sponsor in a destroyed collection', async ({helper}) => {106 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-3', tokenPrefix: 'RCS'});107 await collection.setSponsor(alice, bob.address);108 await collection.burn(alice);109 await expect(collection.removeSponsor(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);110 });111112 itSub('Set - remove - confirm: fails', async ({helper}) => {113 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});114 await collection.setSponsor(alice, bob.address);115 await collection.removeSponsor(alice);116 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);117 });118119 itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {120 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-5', tokenPrefix: 'RCS'});121 await collection.setSponsor(alice, bob.address);122 await collection.confirmSponsorship(bob);123 await collection.removeSponsor(alice);124 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);125 });126});