git.delta.rocks / unique-network / refs/commits / 8613e5ea84e4

difftreelog

source

tests/src/removeCollectionSponsor.test.ts6.0 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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('integration test: ext. removeCollectionSponsor():', () => {21  let donor: IKeyringPair;22  let alice: IKeyringPair;23  let bob: IKeyringPair;24  let charlie: IKeyringPair;2526  before(async () => {27    await usingPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({url: import.meta.url});29      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30    });31  });3233  itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {34    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});35    await collection.setSponsor(alice, bob.address);36    await collection.confirmSponsorship(bob);37    await collection.removeSponsor(alice);3839    // Find unused address40    const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);4142    // Mint token for unused address43    const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});4445    // Transfer this tokens from unused address to Alice - should fail46    const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);47    await expect(token.transfer(zeroBalance, {Substrate: alice.address}))48      .to.be.rejectedWith('Inability to pay some fees');49    const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);5051    expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);52  });5354  itSub('Remove a sponsor after it was already removed', async ({helper}) => {55    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});56    await collection.setSponsor(alice, bob.address);57    await collection.confirmSponsorship(bob);58    await expect(collection.removeSponsor(alice)).to.not.be.rejected;59    await expect(collection.removeSponsor(alice)).to.not.be.rejected;60  });6162  itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {63    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});64    await expect(collection.removeSponsor(alice)).to.not.be.rejected;65  });6667  itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {68    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});69    await collection.setSponsor(alice, bob.address);70    await expect(collection.removeSponsor(alice)).to.not.be.rejected;71  });7273  itSub('Remove a sponsor from a collection with collection admin permissions', async ({helper}) => {74    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});75    await collection.setSponsor(alice, bob.address);76    await collection.addAdmin(alice, {Substrate: charlie.address});77    await expect(collection.removeSponsor(charlie)).not.to.be.rejected;78  });79});8081describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {82  let alice: IKeyringPair;83  let bob: IKeyringPair;84  let charlie: IKeyringPair;8586  before(async () => {87    await usingPlaygrounds(async (helper, privateKey) => {88      const donor = await privateKey({url: import.meta.url});89      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);90    });91  });9293  itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {94    const collectionId = (1 << 32) - 1;95    await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);96  });9798  itSub('(!negative test!) Remove sponsor for a collection by regular user', async ({helper}) => {99    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-2', tokenPrefix: 'RCS'});100    await collection.setSponsor(alice, bob.address);101    await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);102  });103104  itSub('(!negative test!) Remove sponsor in a destroyed collection', async ({helper}) => {105    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-3', tokenPrefix: 'RCS'});106    await collection.setSponsor(alice, bob.address);107    await collection.burn(alice);108    await expect(collection.removeSponsor(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);109  });110111  itSub('Set - remove - confirm: fails', async ({helper}) => {112    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});113    await collection.setSponsor(alice, bob.address);114    await collection.removeSponsor(alice);115    await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);116  });117118  itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {119    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-5', tokenPrefix: 'RCS'});120    await collection.setSponsor(alice, bob.address);121    await collection.confirmSponsorship(bob);122    await collection.removeSponsor(alice);123    await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmSponsorshipFail/);124  });125});