git.delta.rocks / unique-network / refs/commits / 7c4183b4cb3a

difftreelog

source

tests/src/setCollectionSponsor.test.ts4.3 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import 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    // Find the collection that never existed90    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});