git.delta.rocks / unique-network / refs/commits / 1fd293482053

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';56export const PROPERTIES = Array(40)7  .fill(0)8  .map((_, i) => {9    return {10      key: `key_${i}`,11      value: Uint8Array.from(Buffer.from(`value_${i}`)),12    };13  });1415export const SUBS_PROPERTIES = Array(40)16  .fill(0)17  .map((_, i) => {18    return {19      key: `key_${i}`,20      value: `value_${i}`,21    };22  });2324export const PERMISSIONS: ITokenPropertyPermission[] = PROPERTIES.map((p) => {25  return {26    key: p.key,27    permission: {28      tokenOwner: true,29      collectionAdmin: true,30      mutable: true,31    },32  };33});3435export function convertToTokens(value: bigint, nominal = 1000_000_000_000_000_000n): number {36  return Number((value * 1000n) / nominal) / 1000;37}3839export async function createCollectionForBenchmarks(40  mode : TCollectionMode,41  helper: EthUniqueHelper,42  privateKey: (seed: string) => Promise<IKeyringPair>,43  ethSigner: string,44  proxyContract: string | null,45  permissions: ITokenPropertyPermission[],46) {47  const donor = await privateKey('//Alice');4849  const collection = await helper[mode].mintCollection(donor, {50    name: 'test mintToSubstrate',51    description: 'EVMHelpers',52    tokenPrefix: mode,53    ...(mode != 'ft' ? {54      tokenPropertyPermissions: [55        {56          key: 'url',57          permission: {58            tokenOwner: true,59            collectionAdmin: true,60            mutable: true,61          },62        },63        {64          key: 'URI',65          permission: {66            tokenOwner: true,67            collectionAdmin: true,68            mutable: true,69          },70        },71      ],72    } : {}),73    limits: {sponsorTransferTimeout: 0, sponsorApproveTimeout: 0},74    permissions: {mintMode: true},75  });7677  await collection.addToAllowList(donor, {78    Ethereum: helper.address.substrateToEth(donor.address),79  });80  await collection.addToAllowList(donor, {Substrate: donor.address});81  await collection.addAdmin(donor, {Ethereum: ethSigner});82  await collection.addAdmin(donor, {83    Ethereum: helper.address.substrateToEth(donor.address),84  });8586  if (proxyContract) {87    await collection.addToAllowList(donor, {Ethereum: proxyContract});88    await collection.addAdmin(donor, {Ethereum: proxyContract});89  }90  if (collection instanceof UniqueNFTCollection || collection instanceof UniqueRFTCollection)91    await collection.setTokenPropertyPermissions(donor, permissions);9293  return collection;94}