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} from './util/helpers';27import {Keyring} from '@polkadot/api';28import {IKeyringPair} from '@polkadot/types/types';2930chai.use(chaiAsPromised);3132let alice: IKeyringPair;33let bob: IKeyringPair;34let charlie: IKeyringPair;3536describe('integration test: ext. setCollectionSponsor():', () => {3738 before(async () => {39 await usingApi(async () => {40 const keyring = new Keyring({type: 'sr25519'});41 alice = keyring.addFromUri('//Alice');42 bob = keyring.addFromUri('//Bob');43 });44 });4546 it('Set NFT collection sponsor', async () => {47 const collectionId = await createCollectionExpectSuccess();48 await setCollectionSponsorExpectSuccess(collectionId, bob.address);49 });50 it('Set Fungible collection sponsor', async () => {51 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});52 await setCollectionSponsorExpectSuccess(collectionId, bob.address);53 });54 it('Set ReFungible collection sponsor', async () => {55 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});56 await setCollectionSponsorExpectSuccess(collectionId, bob.address);57 });5859 it('Set the same sponsor repeatedly', async () => {60 const collectionId = await createCollectionExpectSuccess();61 await setCollectionSponsorExpectSuccess(collectionId, bob.address);62 await setCollectionSponsorExpectSuccess(collectionId, bob.address);63 });64 it('Replace collection sponsor', async () => {65 const collectionId = await createCollectionExpectSuccess();6667 const keyring = new Keyring({type: 'sr25519'});68 const charlie = keyring.addFromUri('//Charlie');69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);70 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);71 });72});7374describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {75 before(async () => {76 await usingApi(async () => {77 const keyring = new Keyring({type: 'sr25519'});78 alice = keyring.addFromUri('//Alice');79 bob = keyring.addFromUri('//Bob');80 charlie = keyring.addFromUri('//Charlie');81 });82 });8384 it('(!negative test!) Add sponsor with a non-owner', async () => {85 const collectionId = await createCollectionExpectSuccess();86 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');87 });88 it('(!negative test!) Add sponsor to a collection that never existed', async () => {89 90 let collectionId = 0;91 await usingApi(async (api) => {92 collectionId = await getCreatedCollectionCount(api) + 1;93 });9495 await setCollectionSponsorExpectFailure(collectionId, bob.address);96 });97 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {98 const collectionId = await createCollectionExpectSuccess();99 await destroyCollectionExpectSuccess(collectionId);100 await setCollectionSponsorExpectFailure(collectionId, bob.address);101 });102 it('(!negative test!) Collection admin add sponsor', async () => {103 const collectionId = await createCollectionExpectSuccess();104 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);105 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');106 });107});