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

difftreelog

source

tests/src/calibrateApply.ts1.6 KiBsourcehistory
1import {readFile, writeFile} from 'fs/promises';2import path from 'path';3import usingApi from './.outdated/substrate/substrate-api';45const formatNumber = (num: string): string => num.split('').reverse().join('').replace(/([0-9]{3})/g, '$1_').split('').reverse().join('').replace(/^_/, '');67(async () => {8  let weightToFeeCoefficientOverride: string;9  let minGasPriceOverride: string;10  await usingApi(async (api, _privateKey) => {11    weightToFeeCoefficientOverride = (await api.query.configuration.weightToFeeCoefficientOverride() as any).toBigInt().toString();12    minGasPriceOverride = (await api.query.configuration.minGasPriceOverride() as any).toBigInt().toString();13  });14  const constantsFile = path.resolve(__dirname, '../../primitives/common/src/constants.rs');15  let constants = (await readFile(constantsFile)).toString();1617  let weight2feeFound = false;18  constants = constants.replace(/(\/\*<weight2fee>\*\/)[0-9_]+(\/\*<\/weight2fee>\*\/)/, (_f, p, s) => {19    weight2feeFound = true;20    return p+formatNumber(weightToFeeCoefficientOverride)+s;21  });22  if (!weight2feeFound) {23    throw new Error('failed to find weight2fee marker in source code');24  }2526  let minGasPriceFound = false;27  constants = constants.replace(/(\/\*<mingasprice>\*\/)[0-9_]+(\/\*<\/mingasprice>\*\/)/, (_f, p, s) => {28    minGasPriceFound = true;29    return p+formatNumber(minGasPriceOverride)+s;30  });31  if (!minGasPriceFound) {32    throw new Error('failed to find mingasprice marker in source code');33  }3435  await writeFile(constantsFile, constants);36})().catch(e => {37  console.log(e.stack);38});