git.delta.rocks / unique-network / refs/commits / 2df3f6b6e145

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';4import {makeNames} from './util';56const {dirname} = makeNames(import.meta.url);78const formatNumber = (num: string): string => num.split('').reverse().join('').replace(/([0-9]{3})/g, '$1_').split('').reverse().join('').replace(/^_/, '');910(async () => {11  let weightToFeeCoefficientOverride: string;12  let minGasPriceOverride: string;13  await usingApi(async (api, _privateKey) => {14    weightToFeeCoefficientOverride = (await api.query.configuration.weightToFeeCoefficientOverride() as any).toBigInt().toString();15    minGasPriceOverride = (await api.query.configuration.minGasPriceOverride() as any).toBigInt().toString();16  });17  const constantsFile = path.resolve(dirname, '../../primitives/common/src/constants.rs');18  let constants = (await readFile(constantsFile)).toString();1920  let weight2feeFound = false;21  constants = constants.replace(/(\/\*<weight2fee>\*\/)[0-9_]+(\/\*<\/weight2fee>\*\/)/, (_f, p, s) => {22    weight2feeFound = true;23    return p+formatNumber(weightToFeeCoefficientOverride)+s;24  });25  if(!weight2feeFound) {26    throw new Error('failed to find weight2fee marker in source code');27  }2829  let minGasPriceFound = false;30  constants = constants.replace(/(\/\*<mingasprice>\*\/)[0-9_]+(\/\*<\/mingasprice>\*\/)/, (_f, p, s) => {31    minGasPriceFound = true;32    return p+formatNumber(minGasPriceOverride)+s;33  });34  if(!minGasPriceFound) {35    throw new Error('failed to find mingasprice marker in source code');36  }3738  await writeFile(constantsFile, constants);39})().catch(e => {40  console.log(e.stack);41});