1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {IKeyringPair} from '@polkadot/types/types';20import {itSub, usingPlaygrounds, Pallets} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('integration test: ext. setCollectionSponsor():', () => {26 let alice: IKeyringPair;27 let bob: IKeyringPair;28 let charlie: IKeyringPair;2930 before(async () => {31 await usingPlaygrounds(async (helper, privateKey) => {32 const donor = privateKey('//Alice');33 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);34 });35 });3637 itSub('Set NFT collection sponsor', async ({helper}) => {38 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});39 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4041 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({42 Unconfirmed: bob.address,43 });44 });45 46 itSub('Set Fungible collection sponsor', async ({helper}) => {47 const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});48 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4950 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({51 Unconfirmed: bob.address,52 });53 });5455 itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {56 const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});57 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5859 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({60 Unconfirmed: bob.address,61 });62 });6364 itSub('Set the same sponsor repeatedly', async ({helper}) => {65 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});66 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;67 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6869 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({70 Unconfirmed: bob.address,71 });72 });7374 itSub('Replace collection sponsor', async ({helper}) => {75 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});76 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;77 await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7879 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({80 Unconfirmed: charlie.address,81 });82 });83 84 itSub('Collection admin add sponsor', async ({helper}) => {85 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});86 await collection.addAdmin(alice, {Substrate: bob.address});87 await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8889 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({90 Unconfirmed: charlie.address,91 });92 });93});9495describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {96 let alice: IKeyringPair;97 let bob: IKeyringPair;9899 before(async () => {100 await usingPlaygrounds(async (helper, privateKey) => {101 const donor = privateKey('//Alice');102 [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);103 });104 });105106 itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {107 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});108 await expect(collection.setSponsor(bob, bob.address))109 .to.be.rejectedWith(/common\.NoPermission/);110 });111112 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {113 const collectionId = (1 << 32) - 1;114 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))115 .to.be.rejectedWith(/common\.CollectionNotFound/);116 });117118 itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {119 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});120 await collection.burn(alice);121 await expect(collection.setSponsor(alice, bob.address))122 .to.be.rejectedWith(/common\.CollectionNotFound/);123 });124});