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 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 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 60 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);61 await setCollectionSponsorExpectSuccess(collectionId, bob.address);6263 64 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);65 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6667 68 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(0);6970 71 await transferExpectSuccess(collectionId, itemId, alice, bob, 1);72 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.lessThanOrEqual(5);7374 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 110 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId+1)).to.be.equal(-1);111 });112 });113});