git.delta.rocks / unique-network / refs/commits / 7319c348eee5

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;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      donor = await privateKey({filename: __filename});28      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);29    });30  });3132  itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {33    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});34    await collection.setSponsor(alice, bob.address);35    await collection.confirmSponsorship(bob);36    await collection.removeSponsor(alice);3738    // Find unused address39    const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);4041    // Mint token for unused address42    const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});4344    // Transfer this tokens from unused address to Alice - should fail45    const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);46    await expect(token.transfer(zeroBalance, {Substrate: alice.address}))47      .to.be.rejectedWith('Inability to pay some fees');48    const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);4950    expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);51  });5253  itSub('Remove a sponsor after it was already removed', async ({helper}) => {54    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});55    await collection.setSponsor(alice, bob.address);56    await collection.confirmSponsorship(bob);57    await expect(collection.removeSponsor(alice)).to.not.be.rejected;58    await expect(collection.removeSponsor(alice)).to.not.be.rejected;59  });6061  itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {62    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});63    await expect(collection.removeSponsor(alice)).to.not.be.rejected;64  });6566  itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {67    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});68    await collection.setSponsor(alice, bob.address);69    await expect(collection.removeSponsor(alice)).to.not.be.rejected;70  });7172});7374describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {75  let alice: IKeyringPair;76  let bob: IKeyringPair;77  let charlie: IKeyringPair;7879  before(async () => {80    await usingPlaygrounds(async (helper, privateKey) => {81      const donor = await privateKey({filename: __filename});82      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);83    });84  });8586  itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {87    const collectionId = (1 << 32) - 1;88    await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);89  });9091  itSub('(!negative test!) Remove sponsor for a collection with collection admin permissions', async ({helper}) => {92    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});93    await collection.setSponsor(alice, bob.address);94    await collection.addAdmin(alice, {Substrate: charlie.address});95    await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);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(/unique\.ConfirmUnsetSponsorFail/);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(/unique\.ConfirmUnsetSponsorFail/);124  });125});