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

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} from '../util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;16let Alice: IKeyringPair;17let Bob: IKeyringPair;18let Ferdie: IKeyringPair;1920const AccountTokenOwnershipLimit = 4;21const SponsoredMintSize = 4294967295;22const TokenLimit = 4;23const SponsorTimeout = 14400;24const OwnerCanTransfer = false;25const OwnerCanDestroy = false;2627before(async () => {28  await usingApi(async () => {29    Alice = privateKey('//Alice');30    Bob = privateKey('//Bob');31    Ferdie = privateKey('//Ferdie');32  });33});3435describe('Token limit exceeded collection: ', () => {36  // tslint:disable-next-line: max-line-length37  it('The number of tokens created in the collection from different addresses exceeds the allowed collection limit ', async () => {38    await usingApi(async (api) => {39      const collectionId = await createCollectionExpectSuccess();40      await setMintPermissionExpectSuccess(Alice, collectionId, true);41      await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);42      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);43      const setCollectionLim = api.tx.nft.setCollectionLimits(44        collectionId,45        {46          AccountTokenOwnershipLimit,47          SponsoredMintSize,48          TokenLimit,49          // tslint:disable-next-line: object-literal-sort-keys50          SponsorTimeout,51          OwnerCanTransfer,52          OwnerCanDestroy,53        },54      );55      const subTx = await submitTransactionAsync(Alice, setCollectionLim);56      const subTxTesult = getCreateItemResult(subTx);57      // tslint:disable-next-line:no-unused-expression58      expect(subTxTesult.success).to.be.true;59      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));60      await timeoutPromise(10000);6162      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];63      const mintItemOne = api.tx.nft64        .createMultipleItems(collectionId, Ferdie.address, args);65      const mintItemTwo = api.tx.nft66        .createMultipleItems(collectionId, Bob.address, args);67      await Promise.all([68        mintItemOne.signAndSend(Ferdie),69        mintItemTwo.signAndSend(Bob),70      ]);71      await timeoutPromise(10000);72      const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;73      expect(itemsListIndexAfter.toNumber()).to.be.equal(3);74      // TokenLimit = 4. The first transaction is successful. The second should fail.75      await timeoutPromise(10000);76    });77  });78});