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

difftreelog

source

tests/src/benchmarks/utils/common.ts2.6 KiBsourcehistory
1import {EthUniqueHelper} from '../../eth/util';2import {ITokenPropertyPermission, TCollectionMode} from '../../util/playgrounds/types';3import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';4import {IKeyringPair} from '@polkadot/types/types';5import {ContractImports} from '../../eth/util/playgrounds/types';67export const PROPERTIES = Array(40)8  .fill(0)9  .map((_, i) => {10    return {11      key: `key_${i}`,12      value: Uint8Array.from(Buffer.from(`value_${i}`)),13    };14  });1516export const SUBS_PROPERTIES = Array(40)17  .fill(0)18  .map((_, i) => {19    return {20      key: `key_${i}`,21      value: `value_${i}`,22    };23  });2425export const PERMISSIONS: ITokenPropertyPermission[] = PROPERTIES.map((p) => {26  return {27    key: p.key,28    permission: {29      tokenOwner: true,30      collectionAdmin: true,31      mutable: true,32    },33  };34});3536export function convertToTokens(value: bigint, nominal = 1000_000_000_000_000_000n): number {37  return Number((value * 1000n) / nominal) / 1000;38}3940export async function createCollectionForBenchmarks(41  mode : TCollectionMode,42  helper: EthUniqueHelper,43  privateKey: (seed: string) => Promise<IKeyringPair>,44  ethSigner: string,45  proxyContract: string | null,46  permissions: ITokenPropertyPermission[],47) {48  const donor = await privateKey('//Alice');4950  const collection = await helper[mode].mintCollection(donor, {51    name: 'test mintToSubstrate',52    description: 'EVMHelpers',53    tokenPrefix: mode,54    ...(mode != 'ft' ? {55      tokenPropertyPermissions: [56        {57          key: 'url',58          permission: {59            tokenOwner: true,60            collectionAdmin: true,61            mutable: true,62          },63        },64        {65          key: 'URI',66          permission: {67            tokenOwner: true,68            collectionAdmin: true,69            mutable: true,70          },71        },72      ],73    } : {}),74    limits: {sponsorTransferTimeout: 0, sponsorApproveTimeout: 0},75    permissions: {mintMode: true},76  });7778  await collection.addToAllowList(donor, {79    Ethereum: helper.address.substrateToEth(donor.address),80  });81  await collection.addToAllowList(donor, {Substrate: donor.address});82  await collection.addAdmin(donor, {Ethereum: ethSigner});83  await collection.addAdmin(donor, {84    Ethereum: helper.address.substrateToEth(donor.address),85  });8687  if (proxyContract) {88    await collection.addToAllowList(donor, {Ethereum: proxyContract});89    await collection.addAdmin(donor, {Ethereum: proxyContract});90  }91  if (collection instanceof UniqueNFTCollection || collection instanceof UniqueRFTCollection)92    await collection.setTokenPropertyPermissions(donor, permissions);9394  return collection;95}