git.delta.rocks / unique-network / refs/commits / 8d3beac8f1a1

difftreelog

source

tests/src/removeCollectionSponsor.test.ts5.4 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } 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();50    await setCollectionSponsorExpectSuccess(collectionId, bob.address);51    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');52    await removeCollectionSponsorExpectSuccess(collectionId);5354    await usingApi(async (api) => {55      // Find unused address56      const zeroBalance = await findUnusedAddress(api);5758      // Mint token for unused address59      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6061      // Transfer this tokens from unused address to Alice - should fail62      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        await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);66      };67      await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");68      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());6970      expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;71    });72  });7374  it('Remove a sponsor after it was already removed', async () => {75    const collectionId = await createCollectionExpectSuccess();76    await setCollectionSponsorExpectSuccess(collectionId, bob.address);77    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');78    await removeCollectionSponsorExpectSuccess(collectionId);79    await removeCollectionSponsorExpectSuccess(collectionId);80  });8182  it('Remove sponsor in a collection that never had the sponsor set', async () => {83    const collectionId = await createCollectionExpectSuccess();84    await removeCollectionSponsorExpectSuccess(collectionId);85  });8687  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {88    const collectionId = await createCollectionExpectSuccess();89    await setCollectionSponsorExpectSuccess(collectionId, bob.address);90    await removeCollectionSponsorExpectSuccess(collectionId);91  });9293});9495describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {96  before(async () => {97    await usingApi(async (api) => {98      const keyring = new Keyring({ type: 'sr25519' });99      alice = keyring.addFromUri(`//Alice`);100      bob = keyring.addFromUri(`//Bob`);101      charlie = keyring.addFromUri(`//Charlie`);102    });103  });104105  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {106    // Find the collection that never existed107    const collectionId = 0;108    await usingApi(async (api) => {109      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;110    });111112    await removeCollectionSponsorExpectFailure(collectionId);113  });114115  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {116    const collectionId = await createCollectionExpectSuccess();117    await setCollectionSponsorExpectSuccess(collectionId, bob.address);118    await destroyCollectionExpectSuccess(collectionId);119    await removeCollectionSponsorExpectFailure(collectionId);120  });121122  it('Set - remove - confirm: fails', async () => {123    const collectionId = await createCollectionExpectSuccess();124    await setCollectionSponsorExpectSuccess(collectionId, bob.address);125    await removeCollectionSponsorExpectSuccess(collectionId);126    await confirmSponsorshipExpectFailure(collectionId, '//Bob');127  });128129  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {130    const collectionId = await createCollectionExpectSuccess();131    await setCollectionSponsorExpectSuccess(collectionId, bob.address);132    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');133    await removeCollectionSponsorExpectSuccess(collectionId);134    await confirmSponsorshipExpectFailure(collectionId, '//Bob');135  });136137});