git.delta.rocks / unique-network / refs/commits / e3aef6f9aee5

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  normalizeAccountId,25} from "./util/helpers";26import { Keyring } from "@polkadot/api";27import { IKeyringPair } from "@polkadot/types/types";28import type { AccountId } from '@polkadot/types/interfaces';29import { BigNumber } from 'bignumber.js';3031chai.use(chaiAsPromised);32const expect = chai.expect;3334let alice: IKeyringPair;35let bob: IKeyringPair;36let charlie: IKeyringPair;3738describe('integration test: ext. removeCollectionSponsor():', () => {3940  before(async () => {41    await usingApi(async (api) => {42      const keyring = new Keyring({ type: 'sr25519' });43      alice = keyring.addFromUri(`//Alice`);44      bob = keyring.addFromUri(`//Bob`);45      charlie = keyring.addFromUri(`//Charlie`);46    });47  });4849  it('Remove NFT collection sponsor stops sponsorship', async () => {50    const collectionId = await createCollectionExpectSuccess();51    await setCollectionSponsorExpectSuccess(collectionId, bob.address);52    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');53    await removeCollectionSponsorExpectSuccess(collectionId);5455    await usingApi(async (api) => {56      // Find unused address57      const zeroBalance = await findUnusedAddress(api);5859      // Mint token for unused address60      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6162      // Transfer this tokens from unused address to Alice - should fail63      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());64      const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);65      const badTransaction = async function () { 66        await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);67      };68      await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");69      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());7071      expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;72    });73  });7475  it('Remove a sponsor after it was already removed', async () => {76    const collectionId = await createCollectionExpectSuccess();77    await setCollectionSponsorExpectSuccess(collectionId, bob.address);78    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');79    await removeCollectionSponsorExpectSuccess(collectionId);80    await removeCollectionSponsorExpectSuccess(collectionId);81  });8283  it('Remove sponsor in a collection that never had the sponsor set', async () => {84    const collectionId = await createCollectionExpectSuccess();85    await removeCollectionSponsorExpectSuccess(collectionId);86  });8788  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {89    const collectionId = await createCollectionExpectSuccess();90    await setCollectionSponsorExpectSuccess(collectionId, bob.address);91    await removeCollectionSponsorExpectSuccess(collectionId);92  });9394});9596describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {97  before(async () => {98    await usingApi(async (api) => {99      const keyring = new Keyring({ type: 'sr25519' });100      alice = keyring.addFromUri(`//Alice`);101      bob = keyring.addFromUri(`//Bob`);102      charlie = keyring.addFromUri(`//Charlie`);103    });104  });105106  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {107    // Find the collection that never existed108    const collectionId = 0;109    await usingApi(async (api) => {110      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;111    });112113    await removeCollectionSponsorExpectFailure(collectionId);114  });115116  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {117    const collectionId = await createCollectionExpectSuccess();118    await setCollectionSponsorExpectSuccess(collectionId, bob.address);119    await destroyCollectionExpectSuccess(collectionId);120    await removeCollectionSponsorExpectFailure(collectionId);121  });122123  it('Set - remove - confirm: fails', async () => {124    const collectionId = await createCollectionExpectSuccess();125    await setCollectionSponsorExpectSuccess(collectionId, bob.address);126    await removeCollectionSponsorExpectSuccess(collectionId);127    await confirmSponsorshipExpectFailure(collectionId, '//Bob');128  });129130  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {131    const collectionId = await createCollectionExpectSuccess();132    await setCollectionSponsorExpectSuccess(collectionId, bob.address);133    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');134    await removeCollectionSponsorExpectSuccess(collectionId);135    await confirmSponsorshipExpectFailure(collectionId, '//Bob');136  });137138});