1234567891011121314151617import {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 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 58 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);59 await setCollectionSponsorExpectSuccess(collectionId, bob.address);6061 62 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);63 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6465 66 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(0);6768 69 await transferExpectSuccess(collectionId, itemId, alice, bob, 1);70 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.lessThanOrEqual(5);7172 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 106 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId+1)).to.be.equal(-1);107 });108 });109});