git.delta.rocks / unique-network / refs/commits / 56ba79b07e8f

difftreelog

source

tests/src/setCollectionSponsor.test.ts5.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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, Pallets} from './util';1920describe('integration test: ext. setCollectionSponsor():', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;23  let charlie: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = await privateKey({filename: __filename});28      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);29    });30  });3132  itSub('Set NFT collection sponsor', async ({helper}) => {33    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});34    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;3536    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({37      Unconfirmed: bob.address,38    });39  });40  41  itSub('Set Fungible collection sponsor', async ({helper}) => {42    const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});43    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4445    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({46      Unconfirmed: bob.address,47    });48  });4950  itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {51    const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});52    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5354    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({55      Unconfirmed: bob.address,56    });57  });5859  itSub('Set the same sponsor repeatedly', async ({helper}) => {60    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});61    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;62    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6364    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({65      Unconfirmed: bob.address,66    });67  });6869  itSub('Replace collection sponsor', async ({helper}) => {70    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});71    await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;72    await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7374    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({75      Unconfirmed: charlie.address,76    });77  });78  79  itSub('Collection admin add sponsor', async ({helper}) => {80    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});81    await collection.addAdmin(alice, {Substrate: bob.address});82    await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8384    expect((await collection.getData())?.raw.sponsorship).to.deep.equal({85      Unconfirmed: charlie.address,86    });87  });88});8990describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {91  let alice: IKeyringPair;92  let bob: IKeyringPair;9394  before(async () => {95    await usingPlaygrounds(async (helper, privateKey) => {96      const donor = await privateKey({filename: __filename});97      [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);98    });99  });100101  itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {102    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});103    await expect(collection.setSponsor(bob, bob.address))104      .to.be.rejectedWith(/common\.NoPermission/);105  });106107  itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {108    const collectionId = (1 << 32) - 1;109    await expect(helper.collection.setSponsor(alice, collectionId, bob.address))110      .to.be.rejectedWith(/common\.CollectionNotFound/);111  });112113  itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {114    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});115    await collection.burn(alice);116    await expect(collection.setSponsor(alice, bob.address))117      .to.be.rejectedWith(/common\.CollectionNotFound/);118  });119});