git.delta.rocks / unique-network / refs/commits / 6bd537d868d3

difftreelog

source

tests/src/nextSponsoring.test.ts4.6 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 {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {default as usingApi} from './substrate/substrate-api';22import {23  createCollectionExpectSuccess,24  setCollectionSponsorExpectSuccess,25  confirmSponsorshipExpectSuccess,26  createItemExpectSuccess,27  transferExpectSuccess,28  normalizeAccountId,29  getNextSponsored,30  requirePallets,31  Pallets,32} from './util/helpers';3334chai.use(chaiAsPromised);35const expect = chai.expect;36373839describe('Integration Test getNextSponsored(collection_id, owner, item_id):', () => {40  let alice: IKeyringPair;41  let bob: IKeyringPair;4243  before(async () => {44    await usingApi(async (api, privateKeyWrapper) => {45      alice = privateKeyWrapper('//Alice');46      bob = privateKeyWrapper('//Bob');47    });48  });4950  it('NFT', async () => {51    await usingApi(async (api: ApiPromise) => {5253      // Not existing collection 54      expect(await getNextSponsored(api, 0, normalizeAccountId(alice), 0)).to.be.equal(-1);5556      const collectionId = await createCollectionExpectSuccess();57      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);5859      // Check with Disabled sponsoring state60      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);61      await setCollectionSponsorExpectSuccess(collectionId, bob.address);6263      // Check with Unconfirmed sponsoring state64      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);65      await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6667      // Check with Confirmed sponsoring state68      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(0);6970      // After transfer71      await transferExpectSuccess(collectionId, itemId, alice, bob, 1);72      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.lessThanOrEqual(5);7374      // Not existing token 75      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId+1)).to.be.equal(-1);76    });77  });7879  it('Fungible', async () => {80    await usingApi(async (api: ApiPromise) => {8182      const createMode = 'Fungible';83      const funCollectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});84      await createItemExpectSuccess(alice, funCollectionId, createMode);85      await setCollectionSponsorExpectSuccess(funCollectionId, bob.address);86      await confirmSponsorshipExpectSuccess(funCollectionId, '//Bob');87      expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.equal(0);8889      await transferExpectSuccess(funCollectionId, 0, alice, bob, 10, 'Fungible');90      expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.lessThanOrEqual(5);91    });92  });9394  it('ReFungible', async function() {95    await requirePallets(this, [Pallets.ReFungible]);9697    await usingApi(async (api: ApiPromise) => {9899      const createMode = 'ReFungible';100      const refunCollectionId = await createCollectionExpectSuccess({mode: {type: createMode}});101      const refunItemId = await createItemExpectSuccess(alice, refunCollectionId, createMode);102      await setCollectionSponsorExpectSuccess(refunCollectionId, bob.address);103      await confirmSponsorshipExpectSuccess(refunCollectionId, '//Bob');104      expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.equal(0);105106      await transferExpectSuccess(refunCollectionId, refunItemId, alice, bob, 10, 'ReFungible');107      expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.lessThanOrEqual(5);108109      // Not existing token 110      expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId+1)).to.be.equal(-1);111    });112  });113});