1234567891011121314151617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import privateKey from './substrate/privateKey';22import {default as usingApi} from './substrate/substrate-api';23import {24 createCollectionExpectSuccess,25 setCollectionSponsorExpectSuccess,26 confirmSponsorshipExpectSuccess,27 createItemExpectSuccess,28 transferExpectSuccess,29 normalizeAccountId,30 getNextSponsored,31} from './util/helpers';3233chai.use(chaiAsPromised);34const expect = chai.expect;35363738describe('Integration Test getNextSponsored(collection_id, owner, item_id):', () => {39 let alice: IKeyringPair;40 let bob: IKeyringPair;4142 before(async () => {43 await usingApi(async () => {44 alice = privateKey('//Alice');45 bob = privateKey('//Bob');46 });47 });4849 it('NFT', async () => {50 await usingApi(async (api: ApiPromise) => {5152 53 expect(await getNextSponsored(api, 0, normalizeAccountId(alice), 0)).to.be.equal(-1);5455 const collectionId = await createCollectionExpectSuccess();56 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);5758 59 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);60 await setCollectionSponsorExpectSuccess(collectionId, bob.address);6162 63 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(-1);64 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6566 67 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.equal(0);6869 70 await transferExpectSuccess(collectionId, itemId, alice, bob, 1);71 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId)).to.be.lessThanOrEqual(5);7273 74 expect(await getNextSponsored(api, collectionId, normalizeAccountId(alice), itemId+1)).to.be.equal(-1);75 });76 });7778 it('Fungible', async () => {79 await usingApi(async (api: ApiPromise) => {8081 const createMode = 'Fungible';82 const funCollectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});83 await createItemExpectSuccess(alice, funCollectionId, createMode);84 await setCollectionSponsorExpectSuccess(funCollectionId, bob.address);85 await confirmSponsorshipExpectSuccess(funCollectionId, '//Bob');86 expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.equal(0);8788 await transferExpectSuccess(funCollectionId, 0, alice, bob, 10, 'Fungible');89 expect(await getNextSponsored(api, funCollectionId, normalizeAccountId(alice), 0)).to.be.lessThanOrEqual(5);90 });91 });9293 it('ReFungible', async () => {94 await usingApi(async (api: ApiPromise) => {9596 const createMode = 'ReFungible';97 const refunCollectionId = await createCollectionExpectSuccess({mode: {type: createMode}});98 const refunItemId = await createItemExpectSuccess(alice, refunCollectionId, createMode);99 await setCollectionSponsorExpectSuccess(refunCollectionId, bob.address);100 await confirmSponsorshipExpectSuccess(refunCollectionId, '//Bob');101 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.equal(0);102103 await transferExpectSuccess(refunCollectionId, refunItemId, alice, bob, 10, 'ReFungible');104 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId)).to.be.lessThanOrEqual(5);105106 107 expect(await getNextSponsored(api, refunCollectionId, normalizeAccountId(alice), refunItemId+1)).to.be.equal(-1);108 });109 });110});