123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";9import { 10 createCollectionExpectSuccess, 11 setCollectionSponsorExpectSuccess, 12 destroyCollectionExpectSuccess, 13 setCollectionSponsorExpectFailure,14 confirmSponsorshipExpectSuccess,15 confirmSponsorshipExpectFailure,16 createItemExpectSuccess,17 findUnusedAddress,18 getGenericResult,19 enableWhiteListExpectSuccess,20 enablePublicMintingExpectSuccess,21 addToWhiteListExpectSuccess,22 removeCollectionSponsorExpectSuccess,23 removeCollectionSponsorExpectFailure,24} from "./util/helpers";25import { Keyring } from "@polkadot/api";26import { IKeyringPair } from "@polkadot/types/types";27import type { AccountId } from '@polkadot/types/interfaces';28import { BigNumber } from 'bignumber.js';2930chai.use(chaiAsPromised);31const expect = chai.expect;3233let alice: IKeyringPair;34let bob: IKeyringPair;35let charlie: IKeyringPair;3637describe('integration test: ext. removeCollectionSponsor():', () => {3839 before(async () => {40 await usingApi(async (api) => {41 const keyring = new Keyring({ type: 'sr25519' });42 alice = keyring.addFromUri(`//Alice`);43 bob = keyring.addFromUri(`//Bob`);44 charlie = keyring.addFromUri(`//Charlie`);45 });46 });4748 it('Remove NFT collection sponsor stops sponsorship', async () => {49 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');50 await setCollectionSponsorExpectSuccess(collectionId, bob.address);51 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');52 await removeCollectionSponsorExpectSuccess(collectionId);5354 await usingApi(async (api) => {55 56 const zeroBalance = await findUnusedAddress(api);5758 59 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6061 62 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());63 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);64 const badTransaction = async function () { 65 console.log = function () {};66 console.error = function () {};67 await submitTransactionAsync(zeroBalance, zeroToAlice);68 delete console.log;69 delete console.error;70 };71 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");72 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());7374 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;75 });76 });7778 it('Remove a sponsor after it was already removed', async () => {79 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');80 await setCollectionSponsorExpectSuccess(collectionId, bob.address);81 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');82 await removeCollectionSponsorExpectSuccess(collectionId);83 await removeCollectionSponsorExpectSuccess(collectionId);84 });8586 it('Remove sponsor in a collection that never had the sponsor set', async () => {87 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');88 await removeCollectionSponsorExpectSuccess(collectionId);89 });9091 it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {92 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);94 await removeCollectionSponsorExpectSuccess(collectionId);95 });9697});9899describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {100 before(async () => {101 await usingApi(async (api) => {102 const keyring = new Keyring({ type: 'sr25519' });103 alice = keyring.addFromUri(`//Alice`);104 bob = keyring.addFromUri(`//Bob`);105 charlie = keyring.addFromUri(`//Charlie`);106 });107 });108109 it('(!negative test!) Remove sponsor for a collection that never existed', async () => {110 111 const collectionId = 0;112 await usingApi(async (api) => {113 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;114 });115116 await removeCollectionSponsorExpectFailure(collectionId);117 });118119 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {120 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');121 await setCollectionSponsorExpectSuccess(collectionId, bob.address);122 await destroyCollectionExpectSuccess(collectionId);123 await removeCollectionSponsorExpectFailure(collectionId);124 });125126 it('Set - remove - confirm: fails', async () => {127 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');128 await setCollectionSponsorExpectSuccess(collectionId, bob.address);129 await removeCollectionSponsorExpectSuccess(collectionId);130 await confirmSponsorshipExpectFailure(collectionId, '//Bob');131 });132133 it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {134 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');135 await setCollectionSponsorExpectSuccess(collectionId, bob.address);136 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');137 await removeCollectionSponsorExpectSuccess(collectionId);138 await confirmSponsorshipExpectFailure(collectionId, '//Bob');139 });140141});