123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi, submitTransactionExpectFailAsync} from './substrate/substrate-api';9import {10 createCollectionExpectSuccess,11 setCollectionSponsorExpectSuccess,12 destroyCollectionExpectSuccess,13 confirmSponsorshipExpectSuccess,14 confirmSponsorshipExpectFailure,15 createItemExpectSuccess,16 findUnusedAddress,17 removeCollectionSponsorExpectSuccess,18 removeCollectionSponsorExpectFailure,19 normalizeAccountId,20 addCollectionAdminExpectSuccess,21} from './util/helpers';22import {Keyring} from '@polkadot/api';23import {IKeyringPair} from '@polkadot/types/types';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728let alice: IKeyringPair;29let bob: IKeyringPair;3031describe('integration test: ext. removeCollectionSponsor():', () => {3233 before(async () => {34 await usingApi(async () => {35 const keyring = new Keyring({type: 'sr25519'});36 alice = keyring.addFromUri('//Alice');37 bob = keyring.addFromUri('//Bob');38 });39 });4041 it('Removing NFT collection sponsor stops sponsorship', async () => {42 const collectionId = await createCollectionExpectSuccess();43 await setCollectionSponsorExpectSuccess(collectionId, bob.address);44 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');45 await removeCollectionSponsorExpectSuccess(collectionId);4647 await usingApi(async (api) => {48 49 const zeroBalance = await findUnusedAddress(api);5051 52 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);5354 55 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();56 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);57 const badTransaction = async function () {58 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);59 };60 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');61 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();6263 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);64 });65 });6667 it('Remove a sponsor after it was already removed', async () => {68 const collectionId = await createCollectionExpectSuccess();69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);70 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');71 await removeCollectionSponsorExpectSuccess(collectionId);72 await removeCollectionSponsorExpectSuccess(collectionId);73 });7475 it('Remove sponsor in a collection that never had the sponsor set', async () => {76 const collectionId = await createCollectionExpectSuccess();77 await removeCollectionSponsorExpectSuccess(collectionId);78 });7980 it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {81 const collectionId = await createCollectionExpectSuccess();82 await setCollectionSponsorExpectSuccess(collectionId, bob.address);83 await removeCollectionSponsorExpectSuccess(collectionId);84 });8586});8788describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {89 before(async () => {90 await usingApi(async () => {91 const keyring = new Keyring({type: 'sr25519'});92 alice = keyring.addFromUri('//Alice');93 bob = keyring.addFromUri('//Bob');94 });95 });9697 it('(!negative test!) Remove sponsor for a collection that never existed', async () => {98 99 let collectionId = 0;100 await usingApi(async (api) => {101 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;102 });103104 await removeCollectionSponsorExpectFailure(collectionId);105 });106107 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {108 const collectionId = await createCollectionExpectSuccess();109 await setCollectionSponsorExpectSuccess(collectionId, bob.address);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);111 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');112 });113114 it('(!negative test!) Remove sponsor for a collection by regular user', async () => {115 const collectionId = await createCollectionExpectSuccess();116 await setCollectionSponsorExpectSuccess(collectionId, bob.address);117 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');118 });119120 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {121 const collectionId = await createCollectionExpectSuccess();122 await setCollectionSponsorExpectSuccess(collectionId, bob.address);123 await destroyCollectionExpectSuccess(collectionId);124 await removeCollectionSponsorExpectFailure(collectionId);125 });126127 it('Set - remove - confirm: fails', async () => {128 const collectionId = await createCollectionExpectSuccess();129 await setCollectionSponsorExpectSuccess(collectionId, bob.address);130 await removeCollectionSponsorExpectSuccess(collectionId);131 await confirmSponsorshipExpectFailure(collectionId, '//Bob');132 });133134 it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {135 const collectionId = await createCollectionExpectSuccess();136 await setCollectionSponsorExpectSuccess(collectionId, bob.address);137 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');138 await removeCollectionSponsorExpectSuccess(collectionId);139 await confirmSponsorshipExpectFailure(collectionId, '//Bob');140 });141142});