git.delta.rocks / unique-network / refs/commits / 0d80db5a418a

difftreelog

source

tests/src/removeCollectionSponsor.test.ts5.1 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, 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} from './util/helpers';21import { Keyring } from '@polkadot/api';22import { IKeyringPair } from '@polkadot/types/types';23import { BigNumber } from 'bignumber.js';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('Remove 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      // Find unused address49      const zeroBalance = await findUnusedAddress(api);5051      // Mint token for unused address52      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);5354      // Transfer this tokens from unused address to Alice - should fail55      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());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 BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());6263      expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;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    // Find the collection that never existed99    let collectionId = 0;100    await usingApi(async (api) => {101      collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;102    });103104    await removeCollectionSponsorExpectFailure(collectionId);105  });106107  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {108    const collectionId = await createCollectionExpectSuccess();109    await setCollectionSponsorExpectSuccess(collectionId, bob.address);110    await destroyCollectionExpectSuccess(collectionId);111    await removeCollectionSponsorExpectFailure(collectionId);112  });113114  it('Set - remove - confirm: fails', async () => {115    const collectionId = await createCollectionExpectSuccess();116    await setCollectionSponsorExpectSuccess(collectionId, bob.address);117    await removeCollectionSponsorExpectSuccess(collectionId);118    await confirmSponsorshipExpectFailure(collectionId, '//Bob');119  });120121  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {122    const collectionId = await createCollectionExpectSuccess();123    await setCollectionSponsorExpectSuccess(collectionId, bob.address);124    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');125    await removeCollectionSponsorExpectSuccess(collectionId);126    await confirmSponsorshipExpectFailure(collectionId, '//Bob');127  });128129});