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

difftreelog

source

tests/src/removeCollectionSponsor.test.ts6.2 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 {IKeyringPair} from '@polkadot/types/types';3536chai.use(chaiAsPromised);37const expect = chai.expect;3839let alice: IKeyringPair;40let bob: IKeyringPair;4142describe('integration test: ext. removeCollectionSponsor():', () => {4344  before(async () => {45    await usingApi(async (api, privateKeyWrapper) => {46      alice = privateKeyWrapper('//Alice');47      bob = privateKeyWrapper('//Bob');48    });49  });5051  it('Removing NFT collection sponsor stops sponsorship', async () => {52    const collectionId = await createCollectionExpectSuccess();53    await setCollectionSponsorExpectSuccess(collectionId, bob.address);54    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');55    await removeCollectionSponsorExpectSuccess(collectionId);5657    await usingApi(async (api, privateKeyWrapper) => {58      // Find unused address59      const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);6061      // Mint token for unused address62      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6364      // Transfer this tokens from unused address to Alice - should fail65      const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();66      const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);67      const badTransaction = async function () {68        await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);69      };70      await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');71      const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();7273      expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);74    });75  });7677  it('Remove a sponsor after it was already removed', async () => {78    const collectionId = await createCollectionExpectSuccess();79    await setCollectionSponsorExpectSuccess(collectionId, bob.address);80    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');81    await removeCollectionSponsorExpectSuccess(collectionId);82    await removeCollectionSponsorExpectSuccess(collectionId);83  });8485  it('Remove sponsor in a collection that never had the sponsor set', async () => {86    const collectionId = await createCollectionExpectSuccess();87    await removeCollectionSponsorExpectSuccess(collectionId);88  });8990  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {91    const collectionId = await createCollectionExpectSuccess();92    await setCollectionSponsorExpectSuccess(collectionId, bob.address);93    await removeCollectionSponsorExpectSuccess(collectionId);94  });9596});9798describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {99  before(async () => {100    await usingApi(async (api, privateKeyWrapper) => {101      alice = privateKeyWrapper('//Alice');102      bob = privateKeyWrapper('//Bob');103    });104  });105106  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {107    // Find the collection that never existed108    let collectionId = 0;109    await usingApi(async (api) => {110      collectionId = await getCreatedCollectionCount(api) + 1;111    });112113    await removeCollectionSponsorExpectFailure(collectionId);114  });115116  it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {117    const collectionId = await createCollectionExpectSuccess();118    await setCollectionSponsorExpectSuccess(collectionId, bob.address);119    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);120    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');121  });122123  it('(!negative test!) Remove sponsor for a collection by regular user', async () => {124    const collectionId = await createCollectionExpectSuccess();125    await setCollectionSponsorExpectSuccess(collectionId, bob.address);126    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');127  });128129  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {130    const collectionId = await createCollectionExpectSuccess();131    await setCollectionSponsorExpectSuccess(collectionId, bob.address);132    await destroyCollectionExpectSuccess(collectionId);133    await removeCollectionSponsorExpectFailure(collectionId);134  });135136  it('Set - remove - confirm: fails', async () => {137    const collectionId = await createCollectionExpectSuccess();138    await setCollectionSponsorExpectSuccess(collectionId, bob.address);139    await removeCollectionSponsorExpectSuccess(collectionId);140    await confirmSponsorshipExpectFailure(collectionId, '//Bob');141  });142143  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {144    const collectionId = await createCollectionExpectSuccess();145    await setCollectionSponsorExpectSuccess(collectionId, bob.address);146    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');147    await removeCollectionSponsorExpectSuccess(collectionId);148    await confirmSponsorshipExpectFailure(collectionId, '//Bob');149  });150151});