1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi} from './substrate/substrate-api';20import {createCollectionExpectSuccess,21 setCollectionSponsorExpectSuccess,22 destroyCollectionExpectSuccess,23 setCollectionSponsorExpectFailure,24 addCollectionAdminExpectSuccess,25 getCreatedCollectionCount,26 requirePallets,27 Pallets,28} from './util/helpers';29import {IKeyringPair} from '@polkadot/types/types';3031chai.use(chaiAsPromised);3233let alice: IKeyringPair;34let bob: IKeyringPair;35let charlie: IKeyringPair;3637describe('integration test: ext. setCollectionSponsor():', () => {3839 before(async () => {40 await usingApi(async (api, privateKeyWrapper) => {41 alice = privateKeyWrapper('//Alice');42 bob = privateKeyWrapper('//Bob');43 charlie = privateKeyWrapper('//Charlie');44 });45 });4647 it('Set NFT collection sponsor', async () => {48 const collectionId = await createCollectionExpectSuccess();49 await setCollectionSponsorExpectSuccess(collectionId, bob.address);50 });51 it('Set Fungible collection sponsor', async () => {52 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);54 });55 it('Set ReFungible collection sponsor', async function() {56 await requirePallets(this, [Pallets.ReFungible]);5758 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});59 await setCollectionSponsorExpectSuccess(collectionId, bob.address);60 });6162 it('Set the same sponsor repeatedly', async () => {63 const collectionId = await createCollectionExpectSuccess();64 await setCollectionSponsorExpectSuccess(collectionId, bob.address);65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);66 });67 it('Replace collection sponsor', async () => {68 const collectionId = await createCollectionExpectSuccess();69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);70 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);71 });72 it('Collection admin add sponsor', async () => {73 const collectionId = await createCollectionExpectSuccess();74 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);75 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');76 });77});7879describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {80 before(async () => {81 await usingApi(async (api, privateKeyWrapper) => {82 alice = privateKeyWrapper('//Alice');83 bob = privateKeyWrapper('//Bob');84 charlie = privateKeyWrapper('//Charlie');85 });86 });8788 it('(!negative test!) Add sponsor with a non-owner', async () => {89 const collectionId = await createCollectionExpectSuccess();90 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');91 });92 it('(!negative test!) Add sponsor to a collection that never existed', async () => {93 94 let collectionId = 0;95 await usingApi(async (api) => {96 collectionId = await getCreatedCollectionCount(api) + 1;97 });9899 await setCollectionSponsorExpectFailure(collectionId, bob.address);100 });101 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {102 const collectionId = await createCollectionExpectSuccess();103 await destroyCollectionExpectSuccess(collectionId);104 await setCollectionSponsorExpectFailure(collectionId, bob.address);105 });106});