123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi } from './substrate/substrate-api';9import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from './util/helpers';10import { Keyring } from '@polkadot/api';11import { IKeyringPair } from '@polkadot/types/types';1213chai.use(chaiAsPromised);1415let bob: IKeyringPair;1617describe('integration test: ext. setCollectionSponsor():', () => {1819 before(async () => {20 await usingApi(async () => {21 const keyring = new Keyring({ type: 'sr25519' });22 bob = keyring.addFromUri('//Bob');23 });24 });2526 it('Set NFT collection sponsor', async () => {27 const collectionId = await createCollectionExpectSuccess();28 await setCollectionSponsorExpectSuccess(collectionId, bob.address);29 });30 it('Set Fungible collection sponsor', async () => {31 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'Fungible', decimalPoints: 0} });32 await setCollectionSponsorExpectSuccess(collectionId, bob.address);33 });34 it('Set ReFungible collection sponsor', async () => {35 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible'} });36 await setCollectionSponsorExpectSuccess(collectionId, bob.address);37 });3839 it('Set the same sponsor repeatedly', async () => {40 const collectionId = await createCollectionExpectSuccess();41 await setCollectionSponsorExpectSuccess(collectionId, bob.address);42 await setCollectionSponsorExpectSuccess(collectionId, bob.address);43 });44 it('Replace collection sponsor', async () => {45 const collectionId = await createCollectionExpectSuccess();4647 const keyring = new Keyring({ type: 'sr25519' });48 const charlie = keyring.addFromUri('//Charlie');49 await setCollectionSponsorExpectSuccess(collectionId, bob.address);50 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);51 });52});5354describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {55 before(async () => {56 await usingApi(async () => {57 const keyring = new Keyring({ type: 'sr25519' });58 bob = keyring.addFromUri('//Bob');59 });60 });6162 it('(!negative test!) Add sponsor with a non-owner', async () => {63 const collectionId = await createCollectionExpectSuccess();64 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');65 });66 it('(!negative test!) Add sponsor to a collection that never existed', async () => {67 68 let collectionId = 0;69 await usingApi(async (api) => {70 collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;71 });7273 await setCollectionSponsorExpectFailure(collectionId, bob.address);74 });75 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {76 const collectionId = await createCollectionExpectSuccess();77 await destroyCollectionExpectSuccess(collectionId);78 await setCollectionSponsorExpectFailure(collectionId, bob.address);79 });80});