git.delta.rocks / unique-network / refs/commits / f52eddef5fcc

difftreelog

source

tests/src/setCollectionSponsor.test.ts3.7 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import 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} from './util/helpers';15import {Keyring} from '@polkadot/api';16import {IKeyringPair} from '@polkadot/types/types';1718chai.use(chaiAsPromised);1920let alice: IKeyringPair;21let bob: IKeyringPair;22let charlie: IKeyringPair;2324describe('integration test: ext. setCollectionSponsor():', () => {2526  before(async () => {27    await usingApi(async () => {28      const keyring = new Keyring({type: 'sr25519'});29      alice = keyring.addFromUri('//Alice');30      bob = keyring.addFromUri('//Bob');31    });32  });3334  it('Set NFT collection sponsor', async () => {35    const collectionId = await createCollectionExpectSuccess();36    await setCollectionSponsorExpectSuccess(collectionId, bob.address);37  });38  it('Set Fungible collection sponsor', async () => {39    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});40    await setCollectionSponsorExpectSuccess(collectionId, bob.address);41  });42  it('Set ReFungible collection sponsor', async () => {43    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});44    await setCollectionSponsorExpectSuccess(collectionId, bob.address);45  });4647  it('Set the same sponsor repeatedly', async () => {48    const collectionId = await createCollectionExpectSuccess();49    await setCollectionSponsorExpectSuccess(collectionId, bob.address);50    await setCollectionSponsorExpectSuccess(collectionId, bob.address);51  });52  it('Replace collection sponsor', async () => {53    const collectionId = await createCollectionExpectSuccess();5455    const keyring = new Keyring({type: 'sr25519'});56    const charlie = keyring.addFromUri('//Charlie');57    await setCollectionSponsorExpectSuccess(collectionId, bob.address);58    await setCollectionSponsorExpectSuccess(collectionId, charlie.address);59  });60});6162describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {63  before(async () => {64    await usingApi(async () => {65      const keyring = new Keyring({type: 'sr25519'});66      alice = keyring.addFromUri('//Alice');67      bob = keyring.addFromUri('//Bob');68      charlie = keyring.addFromUri('//Charlie');69    });70  });7172  it('(!negative test!) Add sponsor with a non-owner', async () => {73    const collectionId = await createCollectionExpectSuccess();74    await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');75  });76  it('(!negative test!) Add sponsor to a collection that never existed', async () => {77    // Find the collection that never existed78    let collectionId = 0;79    await usingApi(async (api) => {80      collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;81    });8283    await setCollectionSponsorExpectFailure(collectionId, bob.address);84  });85  it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {86    const collectionId = await createCollectionExpectSuccess();87    await destroyCollectionExpectSuccess(collectionId);88    await setCollectionSponsorExpectFailure(collectionId, bob.address);89  });90  it('(!negative test!) Collection admin add sponsor', async () => {91    const collectionId = await createCollectionExpectSuccess();92    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);93    await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');94  });95});