Skip to content

Commit

Permalink
refactor: remove unnecessary console logs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Jan 8, 2025
1 parent 42e0a69 commit 6a0346b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 66 deletions.
17 changes: 0 additions & 17 deletions test/helpers/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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) -
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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;
};
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -157,36 +159,31 @@ 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();

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`
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6a0346b

Please sign in to comment.