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";12import type { AccountId } from '@polkadot/types/interfaces';1314chai.use(chaiAsPromised);15const expect = chai.expect;1617let bob: IKeyringPair;1819describe('integration test: ext. setCollectionSponsor():', () => {2021 before(async () => {22 await usingApi(async (api) => {23 const keyring = new Keyring({ type: 'sr25519' });24 bob = keyring.addFromUri(`//Bob`);25 });26 });2728 it('Set NFT collection sponsor', async () => {29 const collectionId = await createCollectionExpectSuccess();30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);31 });32 it('Set Fungible collection sponsor', async () => {33 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);35 });36 it('Set ReFungible collection sponsor', async () => {37 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);39 });4041 it('Set the same sponsor repeatedly', async () => {42 const collectionId = await createCollectionExpectSuccess();43 await setCollectionSponsorExpectSuccess(collectionId, bob.address);44 await setCollectionSponsorExpectSuccess(collectionId, bob.address);45 });46 it('Replace collection sponsor', async () => {47 const collectionId = await createCollectionExpectSuccess();4849 const keyring = new Keyring({ type: 'sr25519' });50 const charlie = keyring.addFromUri(`//Charlie`);51 await setCollectionSponsorExpectSuccess(collectionId, bob.address);52 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);53 });54});5556describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {57 before(async () => {58 await usingApi(async (api) => {59 const keyring = new Keyring({ type: 'sr25519' });60 bob = keyring.addFromUri(`//Bob`);61 });62 });6364 it('(!negative test!) Add sponsor with a non-owner', async () => {65 const collectionId = await createCollectionExpectSuccess();66 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');67 });68 it('(!negative test!) Add sponsor to a collection that never existed', async () => {69 70 const collectionId = 0;71 await usingApi(async (api) => {72 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;73 });7475 await setCollectionSponsorExpectFailure(collectionId, bob.address);76 });77 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {78 const collectionId = await createCollectionExpectSuccess();79 await destroyCollectionExpectSuccess(collectionId);80 await setCollectionSponsorExpectFailure(collectionId, bob.address);81 });82});