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

difftreelog

source

tests/src/collision-tests/tokenLimitsOff.test.ts2.9 KiBsourcehistory
1import { IKeyringPair } from '@polkadot/types/types';2import BN from 'bn.js';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import privateKey from '../substrate/privateKey';6import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';7import {8  addToWhiteListExpectSuccess,9  createCollectionExpectSuccess,10  getCreateItemResult,11  setMintPermissionExpectSuccess,12  normalizeAccountId,13} from '../util/helpers';1415chai.use(chaiAsPromised);16const expect = chai.expect;17let Alice: IKeyringPair;18let Bob: IKeyringPair;19let Ferdie: IKeyringPair;2021const AccountTokenOwnershipLimit = 4;22const SponsoredMintSize = 4294967295;23const TokenLimit = 4;24const SponsorTimeout = 14400;25const OwnerCanTransfer = false;26const OwnerCanDestroy = false;2728before(async () => {29  await usingApi(async () => {30    Alice = privateKey('//Alice');31    Bob = privateKey('//Bob');32    Ferdie = privateKey('//Ferdie');33  });34});3536describe('Token limit exceeded collection: ', () => {37  // tslint:disable-next-line: max-line-length38  it('The number of tokens created in the collection from different addresses exceeds the allowed collection limit ', async () => {39    await usingApi(async (api) => {40      const collectionId = await createCollectionExpectSuccess();41      await setMintPermissionExpectSuccess(Alice, collectionId, true);42      await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);43      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);44      const setCollectionLim = api.tx.nft.setCollectionLimits(45        collectionId,46        {47          AccountTokenOwnershipLimit,48          SponsoredMintSize,49          TokenLimit,50          // tslint:disable-next-line: object-literal-sort-keys51          SponsorTimeout,52          OwnerCanTransfer,53          OwnerCanDestroy,54        },55      );56      const subTx = await submitTransactionAsync(Alice, setCollectionLim);57      const subTxTesult = getCreateItemResult(subTx);58      // tslint:disable-next-line:no-unused-expression59      expect(subTxTesult.success).to.be.true;60      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));61      await timeoutPromise(20000);6263      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];64      const mintItemOne = api.tx.nft65        .createMultipleItems(collectionId, normalizeAccountId(Ferdie.address), args);66      const mintItemTwo = api.tx.nft67        .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);68      await Promise.all([69        mintItemOne.signAndSend(Ferdie),70        mintItemTwo.signAndSend(Bob),71      ]);72      await timeoutPromise(20000);73      const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;74      expect(itemsListIndexAfter.toNumber()).to.be.equal(3);75      // TokenLimit = 4. The first transaction is successful. The second should fail.76      await timeoutPromise(20000);77    });78  });79});