1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, Pallets} from '@unique/test-utils/util.js';19import {NON_EXISTENT_COLLECTION_ID} from '@unique-nft/playgrounds/types.js';2021describe('integration test: ext. setCollectionSponsor():', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = await privateKey({url: import.meta.url});29 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30 });31 });3233 itSub('Set NFT collection sponsor', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});35 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;3637 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({38 Unconfirmed: bob.address,39 });40 });4142 itSub('Set Fungible collection sponsor', async ({helper}) => {43 const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});44 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4546 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({47 Unconfirmed: bob.address,48 });49 });5051 itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {52 const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});53 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5455 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({56 Unconfirmed: bob.address,57 });58 });5960 itSub('Set the same sponsor repeatedly', async ({helper}) => {61 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});62 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;63 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6465 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({66 Unconfirmed: bob.address,67 });68 });6970 itSub('Replace collection sponsor', async ({helper}) => {71 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});72 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;73 await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7475 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({76 Unconfirmed: charlie.address,77 });78 });7980 itSub('Collection admin add sponsor', async ({helper}) => {81 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});82 await collection.addAdmin(alice, {Substrate: bob.address});83 await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8485 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({86 Unconfirmed: charlie.address,87 });88 });89});9091describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {92 let alice: IKeyringPair;93 let bob: IKeyringPair;9495 before(async () => {96 await usingPlaygrounds(async (helper, privateKey) => {97 const donor = await privateKey({url: import.meta.url});98 [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);99 });100 });101102 itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {103 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});104 await expect(collection.setSponsor(bob, bob.address))105 .to.be.rejectedWith(/common\.NoPermission/);106 });107108 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {109 const collectionId = NON_EXISTENT_COLLECTION_ID;110 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))111 .to.be.rejectedWith(/common\.CollectionNotFound/);112 });113114 itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {115 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});116 await collection.burn(alice);117 await expect(collection.setSponsor(alice, bob.address))118 .to.be.rejectedWith(/common\.CollectionNotFound/);119 });120});