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

difftreelog

source

tests/src/removeCollectionSponsor.test.ts6.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, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21  createCollectionExpectSuccess,22  setCollectionSponsorExpectSuccess,23  destroyCollectionExpectSuccess,24  confirmSponsorshipExpectSuccess,25  confirmSponsorshipExpectFailure,26  createItemExpectSuccess,27  findUnusedAddress,28  removeCollectionSponsorExpectSuccess,29  removeCollectionSponsorExpectFailure,30  normalizeAccountId,31  addCollectionAdminExpectSuccess,32  getCreatedCollectionCount,33} from './util/helpers';34import {Keyring} from '@polkadot/api';35import {IKeyringPair} from '@polkadot/types/types';3637chai.use(chaiAsPromised);38const expect = chai.expect;3940let alice: IKeyringPair;41let bob: IKeyringPair;4243describe('integration test: ext. removeCollectionSponsor():', () => {4445  before(async () => {46    await usingApi(async () => {47      const keyring = new Keyring({type: 'sr25519'});48      alice = keyring.addFromUri('//Alice');49      bob = keyring.addFromUri('//Bob');50    });51  });5253  it('Removing NFT collection sponsor stops sponsorship', async () => {54    const collectionId = await createCollectionExpectSuccess();55    await setCollectionSponsorExpectSuccess(collectionId, bob.address);56    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');57    await removeCollectionSponsorExpectSuccess(collectionId);5859    await usingApi(async (api) => {60      // Find unused address61      const zeroBalance = await findUnusedAddress(api);6263      // Mint token for unused address64      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6566      // Transfer this tokens from unused address to Alice - should fail67      const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();68      const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);69      const badTransaction = async function () {70        await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);71      };72      await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');73      const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();7475      expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);76    });77  });7879  it('Remove a sponsor after it was already removed', async () => {80    const collectionId = await createCollectionExpectSuccess();81    await setCollectionSponsorExpectSuccess(collectionId, bob.address);82    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');83    await removeCollectionSponsorExpectSuccess(collectionId);84    await removeCollectionSponsorExpectSuccess(collectionId);85  });8687  it('Remove sponsor in a collection that never had the sponsor set', async () => {88    const collectionId = await createCollectionExpectSuccess();89    await removeCollectionSponsorExpectSuccess(collectionId);90  });9192  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {93    const collectionId = await createCollectionExpectSuccess();94    await setCollectionSponsorExpectSuccess(collectionId, bob.address);95    await removeCollectionSponsorExpectSuccess(collectionId);96  });9798});99100describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {101  before(async () => {102    await usingApi(async () => {103      const keyring = new Keyring({type: 'sr25519'});104      alice = keyring.addFromUri('//Alice');105      bob = keyring.addFromUri('//Bob');106    });107  });108109  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {110    // Find the collection that never existed111    let collectionId = 0;112    await usingApi(async (api) => {113      collectionId = await getCreatedCollectionCount(api) + 1;114    });115116    await removeCollectionSponsorExpectFailure(collectionId);117  });118119  it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {120    const collectionId = await createCollectionExpectSuccess();121    await setCollectionSponsorExpectSuccess(collectionId, bob.address);122    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);123    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');124  });125126  it('(!negative test!) Remove sponsor for a collection by regular user', async () => {127    const collectionId = await createCollectionExpectSuccess();128    await setCollectionSponsorExpectSuccess(collectionId, bob.address);129    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');130  });131132  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {133    const collectionId = await createCollectionExpectSuccess();134    await setCollectionSponsorExpectSuccess(collectionId, bob.address);135    await destroyCollectionExpectSuccess(collectionId);136    await removeCollectionSponsorExpectFailure(collectionId);137  });138139  it('Set - remove - confirm: fails', async () => {140    const collectionId = await createCollectionExpectSuccess();141    await setCollectionSponsorExpectSuccess(collectionId, bob.address);142    await removeCollectionSponsorExpectSuccess(collectionId);143    await confirmSponsorshipExpectFailure(collectionId, '//Bob');144  });145146  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {147    const collectionId = await createCollectionExpectSuccess();148    await setCollectionSponsorExpectSuccess(collectionId, bob.address);149    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');150    await removeCollectionSponsorExpectSuccess(collectionId);151    await confirmSponsorshipExpectFailure(collectionId, '//Bob');152  });153154});