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

difftreelog

source

tests/src/removeCollectionSponsor.test.ts6.1 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 {IKeyringPair} from '@polkadot/types/types';20import {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('integration test: ext. removeCollectionSponsor():', () => {26  let donor: IKeyringPair;27  let alice: IKeyringPair;28  let bob: IKeyringPair;2930  before(async () => {31    await usingPlaygrounds(async (helper, privateKey) => {32      donor = privateKey('//Alice');33      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);34    });35  });3637  itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {38    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});39    await collection.setSponsor(alice, bob.address);40    await collection.confirmSponsorship(bob);41    await collection.removeSponsor(alice);4243    // Find unused address44    const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);4546    // Mint token for unused address47    const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});4849    // Transfer this tokens from unused address to Alice - should fail50    const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);51    await expect(token.transfer(zeroBalance, {Substrate: alice.address}))52      .to.be.rejectedWith('Inability to pay some fees');53    const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);5455    expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);56  });5758  itSub('Remove a sponsor after it was already removed', async ({helper}) => {59    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});60    await collection.setSponsor(alice, bob.address);61    await collection.confirmSponsorship(bob);62    await expect(collection.removeSponsor(alice)).to.not.be.rejected;63    await expect(collection.removeSponsor(alice)).to.not.be.rejected;64  });6566  itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {67    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});68    await expect(collection.removeSponsor(alice)).to.not.be.rejected;69  });7071  itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {72    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});73    await collection.setSponsor(alice, bob.address);74    await expect(collection.removeSponsor(alice)).to.not.be.rejected;75  });7677});7879describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {80  let alice: IKeyringPair;81  let bob: IKeyringPair;82  let charlie: IKeyringPair;8384  before(async () => {85    await usingPlaygrounds(async (helper, privateKey) => {86      const donor = privateKey('//Alice');87      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);88    });89  });9091  itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {92    const collectionId = (1 << 32) - 1;93    await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);94  });9596  itSub('(!negative test!) Remove sponsor for a collection with collection admin permissions', async ({helper}) => {97    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});98    await collection.setSponsor(alice, bob.address);99    await collection.addAdmin(alice, {Substrate: charlie.address});100    await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);101  });102103  itSub('(!negative test!) Remove sponsor for a collection by regular user', async ({helper}) => {104    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-2', tokenPrefix: 'RCS'});105    await collection.setSponsor(alice, bob.address);106    await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);107  });108109  itSub('(!negative test!) Remove sponsor in a destroyed collection', async ({helper}) => {110    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-3', tokenPrefix: 'RCS'});111    await collection.setSponsor(alice, bob.address);112    await collection.burn(alice);113    await expect(collection.removeSponsor(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);114  });115116  itSub('Set - remove - confirm: fails', async ({helper}) => {117    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});118    await collection.setSponsor(alice, bob.address);119    await collection.removeSponsor(alice);120    await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);121  });122123  itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {124    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-5', tokenPrefix: 'RCS'});125    await collection.setSponsor(alice, bob.address);126    await collection.confirmSponsorship(bob);127    await collection.removeSponsor(alice);128    await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);129  });130});