1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, Pallets} from './util/playgrounds';1920describe('integration test: ext. setCollectionSponsor():', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;23 let charlie: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = privateKey('//Alice');28 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);29 });30 });3132 itSub('Set NFT collection sponsor', async ({helper}) => {33 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});34 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;3536 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({37 Unconfirmed: bob.address,38 });39 });40 41 itSub('Set Fungible collection sponsor', async ({helper}) => {42 const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});43 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4445 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({46 Unconfirmed: bob.address,47 });48 });4950 itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {51 const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});52 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5354 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({55 Unconfirmed: bob.address,56 });57 });5859 itSub('Set the same sponsor repeatedly', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});61 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;62 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6364 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({65 Unconfirmed: bob.address,66 });67 });6869 itSub('Replace collection sponsor', async ({helper}) => {70 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});71 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;72 await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7374 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({75 Unconfirmed: charlie.address,76 });77 });78 79 itSub('Collection admin add sponsor', async ({helper}) => {80 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});81 await collection.addAdmin(alice, {Substrate: bob.address});82 await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8384 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({85 Unconfirmed: charlie.address,86 });87 });88});8990describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {91 let alice: IKeyringPair;92 let bob: IKeyringPair;9394 before(async () => {95 await usingPlaygrounds(async (helper, privateKey) => {96 const donor = privateKey('//Alice');97 [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);98 });99 });100101 itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {102 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});103 await expect(collection.setSponsor(bob, bob.address))104 .to.be.rejectedWith(/common\.NoPermission/);105 });106107 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {108 const collectionId = (1 << 32) - 1;109 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))110 .to.be.rejectedWith(/common\.CollectionNotFound/);111 });112113 itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {114 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});115 await collection.burn(alice);116 await expect(collection.setSponsor(alice, bob.address))117 .to.be.rejectedWith(/common\.CollectionNotFound/);118 });119});