123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi} from './substrate/substrate-api';9import {createCollectionExpectSuccess,10 setCollectionSponsorExpectSuccess,11 destroyCollectionExpectSuccess,12 setCollectionSponsorExpectFailure,13 addCollectionAdminExpectSuccess,14 getCreatedCollectionCount,15} from './util/helpers';16import {Keyring} from '@polkadot/api';17import {IKeyringPair} from '@polkadot/types/types';1819chai.use(chaiAsPromised);2021let alice: IKeyringPair;22let bob: IKeyringPair;23let charlie: IKeyringPair;2425describe('integration test: ext. setCollectionSponsor():', () => {2627 before(async () => {28 await usingApi(async () => {29 const keyring = new Keyring({type: 'sr25519'});30 alice = keyring.addFromUri('//Alice');31 bob = keyring.addFromUri('//Bob');32 });33 });3435 it('Set NFT collection sponsor', async () => {36 const collectionId = await createCollectionExpectSuccess();37 await setCollectionSponsorExpectSuccess(collectionId, bob.address);38 });39 it('Set Fungible collection sponsor', async () => {40 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});41 await setCollectionSponsorExpectSuccess(collectionId, bob.address);42 });43 it('Set ReFungible collection sponsor', async () => {44 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});45 await setCollectionSponsorExpectSuccess(collectionId, bob.address);46 });4748 it('Set the same sponsor repeatedly', async () => {49 const collectionId = await createCollectionExpectSuccess();50 await setCollectionSponsorExpectSuccess(collectionId, bob.address);51 await setCollectionSponsorExpectSuccess(collectionId, bob.address);52 });53 it('Replace collection sponsor', async () => {54 const collectionId = await createCollectionExpectSuccess();5556 const keyring = new Keyring({type: 'sr25519'});57 const charlie = keyring.addFromUri('//Charlie');58 await setCollectionSponsorExpectSuccess(collectionId, bob.address);59 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);60 });61});6263describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {64 before(async () => {65 await usingApi(async () => {66 const keyring = new Keyring({type: 'sr25519'});67 alice = keyring.addFromUri('//Alice');68 bob = keyring.addFromUri('//Bob');69 charlie = keyring.addFromUri('//Charlie');70 });71 });7273 it('(!negative test!) Add sponsor with a non-owner', async () => {74 const collectionId = await createCollectionExpectSuccess();75 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');76 });77 it('(!negative test!) Add sponsor to a collection that never existed', async () => {78 79 let collectionId = 0;80 await usingApi(async (api) => {81 collectionId = await getCreatedCollectionCount(api) + 1;82 });8384 await setCollectionSponsorExpectFailure(collectionId, bob.address);85 });86 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {87 const collectionId = await createCollectionExpectSuccess();88 await destroyCollectionExpectSuccess(collectionId);89 await setCollectionSponsorExpectFailure(collectionId, bob.address);90 });91 it('(!negative test!) Collection admin add sponsor', async () => {92 const collectionId = await createCollectionExpectSuccess();93 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);94 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');95 });96});