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

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} from './util/helpers';3132chai.use(chaiAsPromised);33const expect = chai.expect;34353637describe('Integration Test getNextSponsored(collection_id, owner, item_id):', () => {38  let alice: IKeyringPair;39  let bob: IKeyringPair;4041  before(async () => {42    await usingApi(async (api, privateKeyWrapper) => {43      alice = privateKeyWrapper('//Alice');44      bob = privateKeyWrapper('//Bob');45    });46  });4748  it('NFT', async () => {49    await usingApi(async (api: ApiPromise) => {5051      // Not existing collection 52      expect(await getNextSponsored(api, 0, normalizeAccountId(alice), 0)).to.be.equal(-1);5354      const collectionId = await createCollectionExpectSuccess();55      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);5657      // Check with Disabled sponsoring state58      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);59      await setCollectionSponsorExpectSuccess(collectionId, bob.address);6061      // Check with Unconfirmed sponsoring state62      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);63      await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6465      // Check with Confirmed sponsoring state66      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(0);6768      // After transfer69      await transferExpectSuccess(collectionId, itemId, alice, bob, 1);70      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.lessThanOrEqual(5);7172      // Not existing token 73      expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId+1)).to.be.equal(-1);74    });75  });7677  it('Fungible', async () => {78    await usingApi(async (api: ApiPromise) => {7980      const createMode = 'Fungible';81      const funCollectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});82      await createItemExpectSuccess(alice, funCollectionId, createMode);83      await setCollectionSponsorExpectSuccess(funCollectionId, bob.address);84      await confirmSponsorshipExpectSuccess(funCollectionId, '//Bob');85      expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.equal(0);8687      await transferExpectSuccess(funCollectionId, 0, alice, bob, 10, 'Fungible');88      expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.lessThanOrEqual(5);89    });90  });9192  it('ReFungible', async () => {93    await usingApi(async (api: ApiPromise) => {9495      const createMode = 'ReFungible';96      const refunCollectionId = await createCollectionExpectSuccess({mode: {type: createMode}});97      const refunItemId = await createItemExpectSuccess(alice, refunCollectionId, createMode);98      await setCollectionSponsorExpectSuccess(refunCollectionId, bob.address);99      await confirmSponsorshipExpectSuccess(refunCollectionId, '//Bob');100      expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.equal(0);101102      await transferExpectSuccess(refunCollectionId, refunItemId, alice, bob, 10, 'ReFungible');103      expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.lessThanOrEqual(5);104105      // Not existing token 106      expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId+1)).to.be.equal(-1);107    });108  });109});