git.delta.rocks / unique-network / refs/commits / 980a35f96807

difftreelog

source

tests/src/removeCollectionSponsor.test.ts5.7 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  addCollectionAdminExpectSuccess,21  getCreatedCollectionCount,22} from './util/helpers';23import {Keyring} from '@polkadot/api';24import {IKeyringPair} from '@polkadot/types/types';2526chai.use(chaiAsPromised);27const expect = chai.expect;2829let alice: IKeyringPair;30let bob: IKeyringPair;3132describe('integration test: ext. removeCollectionSponsor():', () => {3334  before(async () => {35    await usingApi(async () => {36      const keyring = new Keyring({type: 'sr25519'});37      alice = keyring.addFromUri('//Alice');38      bob = keyring.addFromUri('//Bob');39    });40  });4142  it('Removing NFT collection sponsor stops sponsorship', async () => {43    const collectionId = await createCollectionExpectSuccess();44    await setCollectionSponsorExpectSuccess(collectionId, bob.address);45    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');46    await removeCollectionSponsorExpectSuccess(collectionId);4748    await usingApi(async (api) => {49      // Find unused address50      const zeroBalance = await findUnusedAddress(api);5152      // Mint token for unused address53      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);5455      // Transfer this tokens from unused address to Alice - should fail56      const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();57      const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);58      const badTransaction = async function () {59        await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);60      };61      await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');62      const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();6364      expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);65    });66  });6768  it('Remove a sponsor after it was already removed', async () => {69    const collectionId = await createCollectionExpectSuccess();70    await setCollectionSponsorExpectSuccess(collectionId, bob.address);71    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');72    await removeCollectionSponsorExpectSuccess(collectionId);73    await removeCollectionSponsorExpectSuccess(collectionId);74  });7576  it('Remove sponsor in a collection that never had the sponsor set', async () => {77    const collectionId = await createCollectionExpectSuccess();78    await removeCollectionSponsorExpectSuccess(collectionId);79  });8081  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {82    const collectionId = await createCollectionExpectSuccess();83    await setCollectionSponsorExpectSuccess(collectionId, bob.address);84    await removeCollectionSponsorExpectSuccess(collectionId);85  });8687});8889describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {90  before(async () => {91    await usingApi(async () => {92      const keyring = new Keyring({type: 'sr25519'});93      alice = keyring.addFromUri('//Alice');94      bob = keyring.addFromUri('//Bob');95    });96  });9798  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {99    // Find the collection that never existed100    let collectionId = 0;101    await usingApi(async (api) => {102      collectionId = await getCreatedCollectionCount(api) + 1;103    });104105    await removeCollectionSponsorExpectFailure(collectionId);106  });107108  it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {109    const collectionId = await createCollectionExpectSuccess();110    await setCollectionSponsorExpectSuccess(collectionId, bob.address);111    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);112    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');113  });114115  it('(!negative test!) Remove sponsor for a collection by regular user', async () => {116    const collectionId = await createCollectionExpectSuccess();117    await setCollectionSponsorExpectSuccess(collectionId, bob.address);118    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');119  });120121  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {122    const collectionId = await createCollectionExpectSuccess();123    await setCollectionSponsorExpectSuccess(collectionId, bob.address);124    await destroyCollectionExpectSuccess(collectionId);125    await removeCollectionSponsorExpectFailure(collectionId);126  });127128  it('Set - remove - confirm: fails', async () => {129    const collectionId = await createCollectionExpectSuccess();130    await setCollectionSponsorExpectSuccess(collectionId, bob.address);131    await removeCollectionSponsorExpectSuccess(collectionId);132    await confirmSponsorshipExpectFailure(collectionId, '//Bob');133  });134135  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {136    const collectionId = await createCollectionExpectSuccess();137    await setCollectionSponsorExpectSuccess(collectionId, bob.address);138    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');139    await removeCollectionSponsorExpectSuccess(collectionId);140    await confirmSponsorshipExpectFailure(collectionId, '//Bob');141  });142143});