1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21 createCollectionExpectSuccess,22 setCollectionSponsorExpectSuccess,23 destroyCollectionExpectSuccess,24 confirmSponsorshipExpectSuccess,25 confirmSponsorshipExpectFailure,26 createItemExpectSuccess,27 findUnusedAddress,28 removeCollectionSponsorExpectSuccess,29 removeCollectionSponsorExpectFailure,30 normalizeAccountId,31 addCollectionAdminExpectSuccess,32 getCreatedCollectionCount,33} from './util/helpers';34import {IKeyringPair} from '@polkadot/types/types';3536chai.use(chaiAsPromised);37const expect = chai.expect;3839let alice: IKeyringPair;40let bob: IKeyringPair;4142describe('integration test: ext. removeCollectionSponsor():', () => {4344 before(async () => {45 await usingApi(async (api, privateKeyWrapper) => {46 alice = privateKeyWrapper('//Alice');47 bob = privateKeyWrapper('//Bob');48 });49 });5051 it('Removing NFT collection sponsor stops sponsorship', async () => {52 const collectionId = await createCollectionExpectSuccess();53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');55 await removeCollectionSponsorExpectSuccess(collectionId);5657 await usingApi(async (api, privateKeyWrapper) => {58 59 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);6061 62 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6364 65 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();66 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);67 const badTransaction = async function () {68 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);69 };70 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');71 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();7273 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);74 });75 });7677 it('Remove a sponsor after it was already removed', async () => {78 const collectionId = await createCollectionExpectSuccess();79 await setCollectionSponsorExpectSuccess(collectionId, bob.address);80 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');81 await removeCollectionSponsorExpectSuccess(collectionId);82 await removeCollectionSponsorExpectSuccess(collectionId);83 });8485 it('Remove sponsor in a collection that never had the sponsor set', async () => {86 const collectionId = await createCollectionExpectSuccess();87 await removeCollectionSponsorExpectSuccess(collectionId);88 });8990 it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {91 const collectionId = await createCollectionExpectSuccess();92 await setCollectionSponsorExpectSuccess(collectionId, bob.address);93 await removeCollectionSponsorExpectSuccess(collectionId);94 });9596});9798describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {99 before(async () => {100 await usingApi(async (api, privateKeyWrapper) => {101 alice = privateKeyWrapper('//Alice');102 bob = privateKeyWrapper('//Bob');103 });104 });105106 it('(!negative test!) Remove sponsor for a collection that never existed', async () => {107 108 let collectionId = 0;109 await usingApi(async (api) => {110 collectionId = await getCreatedCollectionCount(api) + 1;111 });112113 await removeCollectionSponsorExpectFailure(collectionId);114 });115116 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {117 const collectionId = await createCollectionExpectSuccess();118 await setCollectionSponsorExpectSuccess(collectionId, bob.address);119 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);120 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');121 });122123 it('(!negative test!) Remove sponsor for a collection by regular user', async () => {124 const collectionId = await createCollectionExpectSuccess();125 await setCollectionSponsorExpectSuccess(collectionId, bob.address);126 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');127 });128129 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {130 const collectionId = await createCollectionExpectSuccess();131 await setCollectionSponsorExpectSuccess(collectionId, bob.address);132 await destroyCollectionExpectSuccess(collectionId);133 await removeCollectionSponsorExpectFailure(collectionId);134 });135136 it('Set - remove - confirm: fails', async () => {137 const collectionId = await createCollectionExpectSuccess();138 await setCollectionSponsorExpectSuccess(collectionId, bob.address);139 await removeCollectionSponsorExpectSuccess(collectionId);140 await confirmSponsorshipExpectFailure(collectionId, '//Bob');141 });142143 it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {144 const collectionId = await createCollectionExpectSuccess();145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');147 await removeCollectionSponsorExpectSuccess(collectionId);148 await confirmSponsorshipExpectFailure(collectionId, '//Bob');149 });150151});