From 2ae249ad482da31c8673c339d37fec8ae9d5fcd3 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:03:46 +0000 Subject: [PATCH] Smoke tests: fix dynamic fee checks (#3093) * fix smoke test (S06C400) * refactor * Fix MIN_BASE_FEE for moonbase runtimes --- test/helpers/constants.ts | 25 ++++++++++++++---- test/suites/smoke/test-dynamic-fees.ts | 35 +++----------------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/test/helpers/constants.ts b/test/helpers/constants.ts index 3fa84ae462..239dccc0a0 100644 --- a/test/helpers/constants.ts +++ b/test/helpers/constants.ts @@ -79,11 +79,16 @@ export const RUNTIME_CONSTANTS = { GENESIS_FEE_MULTIPLIER: 8_000_000_000_000_000_000n, MIN_FEE_MULTIPLIER: 100_000_000_000_000_000n, MAX_FEE_MULTIPLIER: 100_000_000_000_000_000_000_000n, - WEIGHT_FEE: (50n * KILOWEI * MOONBASE_CONSTANTS.SUPPLY_FACTOR) / 4n, + WEIGHT_FEE: new RuntimeConstant({ + 3400: (50n * KILOWEI * MOONBASE_CONSTANTS.SUPPLY_FACTOR) / 4n, + 0: 50n * KILOWEI * MOONBASE_CONSTANTS.SUPPLY_FACTOR, + }), GENESIS_BASE_FEE: new RuntimeConstant({ 3400: 2_500_000_000n, 0: 10_000_000_000n }), - MIN_BASE_FEE: new RuntimeConstant({ 3400: 312_500_000n, 0: 1_250_000_000n }), - MAX_BASE_FEE: new RuntimeConstant({ 3400: 31_250_000_000_000n, 0: 125_000_000_000_000n }), + // (MinimumMultiplier = 0.1) * WEIGHT_FEE * WEIGHT_PER_GAS + MIN_BASE_FEE: new RuntimeConstant({ 3400: 31_250_000n, 0: 125_000_000n }), + // (MaximumMultiplier = 100_000) * WEIGHT_FEE * WEIGHT_PER_GAS + MAX_BASE_FEE: new RuntimeConstant({ 3400: 3_125_000_000_000n, 0: 12_500_000_000_000n }), TARGET_FILL_PERMILL: new RuntimeConstant({ 3000: 350_000n, 2801: 500_000n, 0: 250_000n }), // Deadline for block production in milliseconds @@ -107,10 +112,15 @@ export const RUNTIME_CONSTANTS = { GENESIS_FEE_MULTIPLIER: 10_000_000_000_000_000_000n, MIN_FEE_MULTIPLIER: 1_000_000_000_000_000_000n, MAX_FEE_MULTIPLIER: 100_000_000_000_000_000_000_000n, - WEIGHT_FEE: (50n * KILOWEI * MOONRIVER_CONSTANTS.SUPPLY_FACTOR) / 4n, + WEIGHT_FEE: new RuntimeConstant({ + 3400: (50n * KILOWEI * MOONRIVER_CONSTANTS.SUPPLY_FACTOR) / 4n, + 0: 50n * KILOWEI * MOONRIVER_CONSTANTS.SUPPLY_FACTOR, + }), GENESIS_BASE_FEE: new RuntimeConstant({ 3400: 3_125_000_000n, 0: 12_500_000_000n }), + // (MinimumMultiplier = 1) * WEIGHT_FEE * WEIGHT_PER_GAS MIN_BASE_FEE: new RuntimeConstant({ 3400: 312_500_000n, 0: 1_250_000_000n }), + // (MaximumMultiplier = 100_000) * WEIGHT_FEE * WEIGHT_PER_GAS MAX_BASE_FEE: new RuntimeConstant({ 3400: 31_250_000_000_000n, 0: 125_000_000_000_000n }), TARGET_FILL_PERMILL: new RuntimeConstant({ 3000: 350_000n, 2801: 500_000n, 0: 250_000n }), @@ -139,10 +149,15 @@ export const RUNTIME_CONSTANTS = { GENESIS_FEE_MULTIPLIER: 8_000_000_000_000_000_000n, MIN_FEE_MULTIPLIER: 1_000_000_000_000_000_000n, MAX_FEE_MULTIPLIER: 100_000_000_000_000_000_000_000n, - WEIGHT_FEE: (50n * KILOWEI * MOONBEAM_CONSTANTS.SUPPLY_FACTOR) / 4n, + WEIGHT_FEE: new RuntimeConstant({ + 3400: (50n * KILOWEI * MOONBEAM_CONSTANTS.SUPPLY_FACTOR) / 4n, + 0: 50n * KILOWEI * MOONBEAM_CONSTANTS.SUPPLY_FACTOR, + }), GENESIS_BASE_FEE: new RuntimeConstant({ 3400: 250_000_000_000n, 0: 1_000_000_000_000n }), + // (MinimumMultiplier = 1) * WEIGHT_FEE * WEIGHT_PER_GAS MIN_BASE_FEE: new RuntimeConstant({ 3400: 31_250_000_000n, 0: 125_000_000_000n }), + // (MaximumMultiplier = 100_000) * WEIGHT_FEE * WEIGHT_PER_GAS MAX_BASE_FEE: new RuntimeConstant({ 3400: 3_125_000_000_000_000n, 0: 12_500_000_000_000_000n }), TARGET_FILL_PERMILL: new RuntimeConstant({ 3000: 350_000n, 2801: 500_000n, 0: 250_000n }), diff --git a/test/suites/smoke/test-dynamic-fees.ts b/test/suites/smoke/test-dynamic-fees.ts index 12fa4d4975..0494975e4b 100644 --- a/test/suites/smoke/test-dynamic-fees.ts +++ b/test/suites/smoke/test-dynamic-fees.ts @@ -1,6 +1,6 @@ import "@moonbeam-network/api-augment/moonbase"; import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { WEIGHT_PER_GAS, getBlockArray, WEIGHT_FEE } from "@moonwall/util"; +import { WEIGHT_PER_GAS, getBlockArray } from "@moonwall/util"; import { ApiPromise } from "@polkadot/api"; import { GenericExtrinsic } from "@polkadot/types"; import type { u128, u32 } from "@polkadot/types-codec"; @@ -123,25 +123,6 @@ describeSuite({ const specName = version.specName; runtime = specName.toUpperCase() as any; - if ( - specVersion.toNumber() < 2200 && - (specName.toString() == "moonbase" || specName.toString() == "moonriver") - ) { - log( - `Runtime ${specName.toString()} version ` + - `${specVersion.toString()} is less than 2200, skipping test suite.` - ); - skipAll = true; - } - - if (specVersion.toNumber() < 2300 && specName.toString() == "moonbeam") { - log( - `Runtime ${specName.toString()} version ` + - `${specVersion.toString()} is less than 2300, skipping test suite.` - ); - skipAll = true; - } - targetFillPermill = RUNTIME_CONSTANTS[runtime].TARGET_FILL_PERMILL.get( specVersion.toNumber() ); @@ -323,22 +304,14 @@ describeSuite({ log("Skipping test suite due to runtime version"); return; } - const supplyFactor = ConstantStore(context).SUPPLY_FACTOR; - const weightFee = ConstantStore(context).WEIGHT_FEE; + const weightFee = ConstantStore(context).WEIGHT_FEE.get(specVersion.toNumber()); const failures = blockData .map(({ blockNum, nextFeeMultiplier, baseFeePerGasInGwei }) => { const baseFeePerGasInWei = ethers.parseUnits(baseFeePerGasInGwei, "gwei"); - let expectedBaseFeePerGasInWei = - (nextFeeMultiplier.toBigInt() * WEIGHT_FEE * WEIGHT_PER_GAS * supplyFactor) / - ethers.parseEther("1"); - // The min_gas_price was divided by 4 on runtime 3400 - if (specVersion.toNumber() > 3300) { - expectedBaseFeePerGasInWei = - (nextFeeMultiplier.toBigInt() * weightFee * WEIGHT_PER_GAS) / - ethers.parseEther("1"); - } + const expectedBaseFeePerGasInWei = + (nextFeeMultiplier.toBigInt() * weightFee * WEIGHT_PER_GAS) / ethers.parseEther("1"); const valid = baseFeePerGasInWei == expectedBaseFeePerGasInWei; return { blockNum, baseFeePerGasInGwei, valid, expectedBaseFeePerGasInWei };