diff --git a/test/helpers/block.ts b/test/helpers/block.ts index f2585c6bda..228c50bab6 100644 --- a/test/helpers/block.ts +++ b/test/helpers/block.ts @@ -179,8 +179,6 @@ export const verifyBlockFees = async ( await context.viem().getBlock({ blockNumber: BigInt(number - 1) }) ).baseFeePerGas!; - console.log("baseFeePerGas", baseFeePerGas); - let priorityFee; let gasFee; // Transaction is an enum now with as many variants as supported transaction types. @@ -195,31 +193,21 @@ export const verifyBlockFees = async ( gasFee = ethTxWrapper.asEip1559.maxFeePerGas.toBigInt(); } - console.log("priorityFee", priorityFee); - console.log("gasFee", gasFee); - let effectiveTipPerGas = gasFee - baseFeePerGas; if (effectiveTipPerGas > priorityFee) { effectiveTipPerGas = priorityFee; } - console.log("effectiveTipPerGas", effectiveTipPerGas); - // Calculate the fees paid for the base fee and tip fee independently. // Only the base fee is subject to the split between burn and treasury. const baseFeesPaid = gasUsed * baseFeePerGas; const tipAsFeesPaid = gasUsed * effectiveTipPerGas; - console.log("baseFeesPaid", baseFeesPaid); - console.log("tipAsFeesPaid", tipAsFeesPaid); - const { burnt: baseFeePortionsBurnt } = calculateFeePortions( feesTreasuryProportion, baseFeesPaid ); - console.log("baseFeesPaid", baseFeesPaid); - console.log("tipAsFeesPaid", tipAsFeesPaid); txFees += baseFeesPaid + tipAsFeesPaid; txBurnt += baseFeePortionsBurnt; } else { @@ -290,11 +278,6 @@ export const verifyBlockFees = async ( await api.at(blockDetails.block.hash) ).query.system.account(origin)) as any; - console.log("origin", origin); - console.log("txFees", txFees); - console.log("diff", (((fromBalance.data.free.toBigInt() as any) - - toBalance.data.free.toBigInt()) as any) - expectedBalanceDiff); - expect(txFees.toString()).to.eq( ( (((fromBalance.data.free.toBigInt() as any) - diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index c36baad201..880df3abda 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -1,19 +1,20 @@ -import {describeSuite, expect, extractInfo, TransactionTypes} from "@moonwall/cli"; +import { describeSuite, expect, extractInfo, TransactionTypes } from "@moonwall/cli"; import { alith, ALITH_ADDRESS, baltathar, - BALTATHAR_ADDRESS, BALTATHAR_PRIVATE_KEY, CHARLETH_ADDRESS, + BALTATHAR_PRIVATE_KEY, + CHARLETH_ADDRESS, createRawTransfer, extractFee, Perbill, TREASURY_ACCOUNT, WEIGHT_PER_GAS, } from "@moonwall/util"; -import {parameterType, UNIT} from "./test-parameters"; -import {BN} from "@polkadot/util"; -import {calculateFeePortions, ConstantStore, verifyLatestBlockFees} from "../../../../helpers"; -import {parseGwei, parseWei} from "viem"; +import { parameterType, UNIT } from "./test-parameters"; +import { BN } from "@polkadot/util"; +import { calculateFeePortions, ConstantStore, verifyLatestBlockFees } from "../../../../helpers"; +import { parseGwei } from "viem"; interface TestCase { proportion: Perbill; @@ -27,7 +28,7 @@ describeSuite({ id: "DTemp03", title: "Parameters - RuntimeConfig", foundationMethods: "dev", - testCases: ({it, context, log}) => { + testCases: ({ it, context, log }) => { let testCounter = 0; const collatorAddress = ALITH_ADDRESS; const senderPrivateKey = BALTATHAR_PRIVATE_KEY; @@ -39,7 +40,7 @@ describeSuite({ proportion: new Perbill(0), transfer_amount: 10n * UNIT, tipAmount: 1n * UNIT, - priorityFeePerGas: parseGwei('1'), + priorityFeePerGas: parseGwei("1"), }, { proportion: new Perbill(1, 100), @@ -57,13 +58,13 @@ describeSuite({ proportion: new Perbill(400, 1000), transfer_amount: 10n * UNIT, tipAmount: 2n * UNIT, - priorityFeePerGas: parseGwei('2'), + priorityFeePerGas: parseGwei("2"), }, { proportion: new Perbill(500, 1000), transfer_amount: 10n * UNIT, tipAmount: 1n * UNIT, - priorityFeePerGas: parseGwei('1'), + priorityFeePerGas: parseGwei("1"), }, { proportion: new Perbill(963, 1000), @@ -98,8 +99,8 @@ describeSuite({ const calcIssuanceDecrease = (feeWithTip: bigint, maybeTip?: bigint): bigint => { const tip = maybeTip ?? 0n; const feeWithoutTip = feeWithTip - tip; - const {burnt: feeBurnt} = calculateFeePortions(treasuryPerbill, feeWithoutTip); - const {burnt: tipBurnt} = calculateFeePortions(treasuryPerbill, tip); + const { burnt: feeBurnt } = calculateFeePortions(treasuryPerbill, feeWithoutTip); + const { burnt: tipBurnt } = calculateFeePortions(treasuryPerbill, tip); return feeBurnt + tipBurnt; }; @@ -113,13 +114,11 @@ describeSuite({ `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Ethereum ` + `${txnType} transfers with ${withTip ? "" : "no "}tip`, test: async () => { - const {specVersion} = context.polkadotJs().consts.system.version; + const { specVersion } = context.polkadotJs().consts.system.version; const GENESIS_BASE_FEE = ConstantStore(context).GENESIS_BASE_FEE.get( specVersion.toNumber() ); - const WEIGHT_FEE = ConstantStore(context).WEIGHT_FEE.get( - specVersion.toNumber() - ); + const WEIGHT_FEE = ConstantStore(context).WEIGHT_FEE.get(specVersion.toNumber()); const param = parameterType( context, @@ -132,21 +131,24 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); - const balBefore = await context.viem().getBalance({address: TREASURY_ACCOUNT}); - const collatorBalBefore = await context.viem().getBalance({address: collatorAddress}); + const balBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const collatorBalBefore = await context + .viem() + .getBalance({ address: collatorAddress }); const issuanceBefore = ( await context.polkadotJs().query.balances.totalIssuance() ).toBigInt(); - const nextFeeMultiplier = (await context.polkadotJs().query.transactionPayment.nextFeeMultiplier()).toBigInt(); - const baseFee = nextFeeMultiplier * (WEIGHT_FEE * WEIGHT_PER_GAS) / 1_000_000_000_000_000_000n; - - console.log("baseFee:", baseFee); + const nextFeeMultiplier = ( + await context.polkadotJs().query.transactionPayment.nextFeeMultiplier() + ).toBigInt(); + const baseFee = + (nextFeeMultiplier * (WEIGHT_FEE * WEIGHT_PER_GAS)) / 1_000_000_000_000_000_000n; - const {result} = await context.createBlock( + const { result } = await context.createBlock( await createRawTransfer(context, receiver, t.transfer_amount, { privateKey: senderPrivateKey, type: txnType, @@ -157,12 +159,12 @@ describeSuite({ const receipt = await context .viem("public") - .getTransactionReceipt({hash: result!.hash as `0x${string}`}); - - console.log("receipt:", receipt); + .getTransactionReceipt({ hash: result!.hash as `0x${string}` }); - const balAfter = await context.viem().getBalance({address: TREASURY_ACCOUNT}); - const collatorBalAfter = await context.viem().getBalance({address: collatorAddress}); + const balAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const collatorBalAfter = await context + .viem() + .getBalance({ address: collatorAddress }); const issuanceAfter = ( await context.polkadotJs().query.balances.totalIssuance() ).toBigInt(); @@ -170,23 +172,18 @@ describeSuite({ const treasuryIncrease = balAfter - balBefore; const issuanceDecrease = issuanceBefore - issuanceAfter; const collatorIncrease = collatorBalAfter - collatorBalBefore; - const tipPaid = withTip ? (() => { - let priorityPerGas = (GENESIS_BASE_FEE - baseFee); - if (priorityPerGas > t.priorityFeePerGas) { - priorityPerGas = t.priorityFeePerGas; - } - return BigInt(priorityPerGas) * BigInt(receipt!.gasUsed); - })() : 0n; + const tipPaid = withTip + ? (() => { + let priorityPerGas = GENESIS_BASE_FEE - baseFee; + if (priorityPerGas > t.priorityFeePerGas) { + priorityPerGas = t.priorityFeePerGas; + } + return BigInt(priorityPerGas) * BigInt(receipt!.gasUsed); + })() + : 0n; const fee = extractFee(result?.events)!.amount.toBigInt(); const feeWithoutTip = fee - tipPaid; - console.log("treasuryIncrease:", treasuryIncrease); - console.log("issuanceDecrease:", issuanceDecrease); - console.log("collatorIncrease:", collatorIncrease); - console.log("total fees :", fee); - console.log("feeWithoutTip :", feeWithoutTip); - console.log("tipPaid :", tipPaid); - expect( treasuryIncrease + issuanceDecrease, `Sum of TreasuryIncrease and IssuanceDecrease should be equal to the fees without tip` @@ -234,23 +231,23 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); - const balanceBefore = await context.viem().getBalance({address: TREASURY_ACCOUNT}); + const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); const issuanceBefore = ( await context.polkadotJs().query.balances.totalIssuance() ).toBigInt(); - const {result} = await context.createBlock( + const { result } = await context.createBlock( context .polkadotJs() .tx.balances.transferKeepAlive(receiver, t.transfer_amount) - .signAsync(senderKeyPair, {tip: withTip ? t.tipAmount : 0n}), - {allowFailures: false} + .signAsync(senderKeyPair, { tip: withTip ? t.tipAmount : 0n }), + { allowFailures: false } ); - const balanceAfter = await context.viem().getBalance({address: TREASURY_ACCOUNT}); + const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); const issuanceAfter = ( await context.polkadotJs().query.balances.totalIssuance() ).toBigInt();