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

difftreelog

source

tests/src/eth/collectionLimits.test.ts4.4 KiBsourcehistory
1import {IKeyringPair} from '@polkadot/types/types';2import {expect, itEth, usingEthPlaygrounds} from './util';345describe('Can set collection limits', () => {6  let donor: IKeyringPair;78  before(async () => {9    await usingEthPlaygrounds(async (_helper, privateKey) => {10      donor = await privateKey({filename: __filename});11    });12  });1314  [15    {case: 'nft' as const, method: 'createNFTCollection' as const},16    {case: 'rft' as const, method: 'createRFTCollection' as const},17    {case: 'ft' as const, method: 'createFTCollection' as const},18  ].map(testCase =>19    itEth(`for ${testCase.case}`, async ({helper}) => {20      const owner = await helper.eth.createAccountWithBalance(donor);21      const {collectionId, collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'FLO', 18);22      const limits = {23        accountTokenOwnershipLimit: 1000,24        sponsoredDataSize: 1024,25        sponsoredDataRateLimit: 30,26        tokenLimit: 1000000,27        sponsorTransferTimeout: 6,28        sponsorApproveTimeout: 6,29        ownerCanTransfer: 1,30        ownerCanDestroy: 0,31        transfersEnabled: 0,32      };33      34      const expectedLimits = {35        accountTokenOwnershipLimit: 1000,36        sponsoredDataSize: 1024,37        sponsoredDataRateLimit: {blocks: 30},38        tokenLimit: 1000000,39        sponsorTransferTimeout: 6,40        sponsorApproveTimeout: 6,41        ownerCanTransfer: true,42        ownerCanDestroy: false,43        transfersEnabled: false,44      };45     46      const collection = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);47      await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();48      await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();49      await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();50      await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();51      await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();52      await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();53      await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();54      await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();55      await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();56      57      const data = (await helper.rft.getData(collectionId))!;58      expect(data.raw.limits).to.deep.eq(expectedLimits);59      expect(await helper.collection.getEffectiveLimits(collectionId)).to.deep.eq(expectedLimits);60    }));61});6263describe('Cannot set invalid collection limits', () => {64  let donor: IKeyringPair;6566  before(async () => {67    await usingEthPlaygrounds(async (_helper, privateKey) => {68      donor = await privateKey({filename: __filename});69    });70  });7172  [73    {case: 'nft' as const, method: 'createNFTCollection' as const},74    {case: 'rft' as const, method: 'createRFTCollection' as const},75    {case: 'ft' as const, method: 'createFTCollection' as const},76  ].map(testCase =>77    itEth(`for ${testCase.case}`, async ({helper}) => {78      const invalidLimits = {79        accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),80        transfersEnabled: 3,81      };8283      const owner = await helper.eth.createAccountWithBalance(donor);84      const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, 'Limits', 'absolutely anything', 'ISNI', 18);85      const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.case, owner);86      await expect(collectionEvm.methods87        .setCollectionLimit('badLimit', '1')88        .call()).to.be.rejectedWith('unknown limit "badLimit"');89      90      await expect(collectionEvm.methods91        .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)92        .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);93      94      await expect(collectionEvm.methods95        .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)96        .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);97    }));98});99