diff --git a/tests/tests/test-assets/test-assets-sufficients.ts b/tests/tests/test-assets/test-assets-sufficients.ts index b09ac26db9c..70c89c0bd8b 100644 --- a/tests/tests/test-assets/test-assets-sufficients.ts +++ b/tests/tests/test-assets/test-assets-sufficients.ts @@ -144,6 +144,7 @@ describeDevMoonbeam( }); }, "Legacy", + "moonbase", true ); @@ -267,6 +268,7 @@ describeDevMoonbeam( }); }, "Legacy", + "moonbase", true ); @@ -407,5 +409,6 @@ describeDevMoonbeam( }); }, "Legacy", + "moonbase", true ); diff --git a/tests/tests/test-eth-tx/test-eth-tx-types.ts b/tests/tests/test-eth-tx/test-eth-tx-types.ts index 58b160e24f1..b184b866818 100644 --- a/tests/tests/test-eth-tx/test-eth-tx-types.ts +++ b/tests/tests/test-eth-tx/test-eth-tx-types.ts @@ -30,6 +30,7 @@ describeDevMoonbeam( }); }, "Legacy", + "moonbase", false ); @@ -76,6 +77,7 @@ describeDevMoonbeam( }); }, "EIP2930", + "moonbase", false ); @@ -123,5 +125,6 @@ describeDevMoonbeam( }); }, "EIP1559", + "moonbase", false ); diff --git a/tests/tests/test-fees/test-length-fees.ts b/tests/tests/test-fees/test-length-fees.ts new file mode 100644 index 00000000000..0741facf58a --- /dev/null +++ b/tests/tests/test-fees/test-length-fees.ts @@ -0,0 +1,121 @@ +import "@moonbeam-network/api-augment"; +import { expect } from "chai"; +import { TREASURY_ACCOUNT } from "../../util/constants"; +import { describeDevMoonbeam } from "../../util/setup-dev-tests"; +import { createTransfer } from "../../util/transactions"; +import { baltathar } from "../../util/accounts"; + +describeDevMoonbeam( + "Substrate Length Fees - Transaction (Moonbase)", + (context) => { + it("should have low balance transfer fees", async () => { + const fee = await testBalanceTransfer(context); + expect(fee).to.equal(14_325_001_520_875n); + }); + }, + "Legacy", + "moonbase" +); + +describeDevMoonbeam( + "Substrate Length Fees - Transaction (Moonbase)", + (context) => { + it("should have expensive runtime-upgrade fees", async () => { + const fee = await testRuntimeUpgrade(context); + expect(fee).to.equal(9_226_795_065_723_667_008n); + }); + }, + "Legacy", + "moonbase" +); + +describeDevMoonbeam( + "Substrate Length Fees - Transaction (Moonriver)", + (context) => { + it("should have low balance transfer fees", async () => { + const fee = await testBalanceTransfer(context); + expect(fee).to.equal(28_535_001_520_875n); + }); + }, + "Legacy", + "moonriver" +); + +describeDevMoonbeam( + "Substrate Length Fees - Transaction (Moonriver)", + (context) => { + it("should have expensive runtime-upgrade fees", async () => { + const fee = await testRuntimeUpgrade(context); + expect(fee).to.equal(9_226_801_365_723_667_008n); + }); + }, + "Legacy", + "moonriver" +); + +describeDevMoonbeam( + "Substrate Length Fees - Transaction (Moonbeam)", + (context) => { + it("should have low balance transfer fees", async () => { + const fee = await testBalanceTransfer(context); + expect(fee).to.equal(2_853_500_152_087_500n); + }); + }, + "Legacy", + "moonbeam" +); + +describeDevMoonbeam( + "Substrate Length Fees - Transaction (Moonbeam)", + (context) => { + it("should have expensive runtime-upgrade fees", async () => { + const fee = await testRuntimeUpgrade(context); + expect(fee).to.equal(922_680_136_572_366_700_800n); + }); + }, + "Legacy", + "moonbeam" +); + +// define our tests here so we can DRY. +// each test submits some txn then measures and returns the fees charged. + +const testBalanceTransfer = async (context) => { + let initialBalance = ( + await context.polkadotApi.query.system.account(baltathar.address) + ).data.free.toBigInt(); + + // send a balance transfer to self and see what our fees end up being + await context.createBlock( + context.polkadotApi.tx.balances.transfer(baltathar.address, 1).signAsync(baltathar) + ); + + let afterBalance = ( + await context.polkadotApi.query.system.account(baltathar.address) + ).data.free.toBigInt(); + + const fee = initialBalance - afterBalance; + return fee; +}; + +const testRuntimeUpgrade = async (context) => { + const initialBalance = ( + await context.polkadotApi.query.system.account(baltathar.address) + ).data.free.toBigInt(); + + // generate a mock runtime upgrade hex string + let size = 4194304; // 2MB bytes represented in hex + let hex = "0x" + "F".repeat(size); + + // send an enactAuthorizedUpgrade. we expect this to fail, but we just want to see that it was + // included in a block (not rejected) and was charged based on its length + await context.polkadotApi.tx.parachainSystem.enactAuthorizedUpgrade(hex).signAndSend(baltathar); + await context.createBlock(); + + let afterBalance = ( + await context.polkadotApi.query.system.account(baltathar.address) + ).data.free.toBigInt(); + + const fee = initialBalance - afterBalance; + return fee; +}; diff --git a/tests/util/dev-node.ts b/tests/util/dev-node.ts index 3620960f491..746671c0a15 100644 --- a/tests/util/dev-node.ts +++ b/tests/util/dev-node.ts @@ -37,6 +37,8 @@ export async function findAvailablePorts() { }; } +export type RuntimeChain = "moonbase" | "moonriver" | "moonbeam"; + // Stores if the node has already started. // It is used when a test file contains multiple describeDevMoonbeam. Those are // executed within the same PID and so would generate a race condition if started @@ -45,7 +47,10 @@ let nodeStarted = false; // This will start a moonbeam dev node, only 1 at a time (check every 100ms). // This will prevent race condition on the findAvailablePorts which uses the PID of the process -export async function startMoonbeamDevNode(withWasm?: boolean): Promise<{ +export async function startMoonbeamDevNode( + withWasm?: boolean, + runtime: RuntimeChain = "moonbase" +): Promise<{ p2pPort: number; rpcPort: number; wsPort: number; @@ -73,8 +78,13 @@ export async function startMoonbeamDevNode(withWasm?: boolean): Promise<{ ETHAPI_CMD != "" ? `${ETHAPI_CMD}` : `--ethapi=txpool`, `--no-telemetry`, `--no-prometheus`, - `--dev`, + `--force-authoring`, + `--rpc-cors=all`, + `--alice`, + `--chain=${runtime}-dev`, `--sealing=manual`, + `--in-peers=0`, + `--out-peers=0`, `-l${MOONBEAM_LOG}`, `--port=${p2pPort}`, `--rpc-port=${rpcPort}`, diff --git a/tests/util/setup-dev-tests.ts b/tests/util/setup-dev-tests.ts index d7ef46177f7..08d454d4bf6 100644 --- a/tests/util/setup-dev-tests.ts +++ b/tests/util/setup-dev-tests.ts @@ -7,7 +7,7 @@ import { RegistryError } from "@polkadot/types/types"; import { EventRecord } from "@polkadot/types/interfaces"; import { ethers } from "ethers"; -import { startMoonbeamDevNode } from "./dev-node"; +import { startMoonbeamDevNode, RuntimeChain } from "./dev-node"; import { provideWeb3Api, provideEthersApi, @@ -81,6 +81,7 @@ export function describeDevMoonbeam( title: string, cb: (context: DevTestContext) => void, ethTransactionType: EthTransactionType = "Legacy", + runtime: RuntimeChain = "moonbase", withWasm?: boolean ) { describe(title, function () { @@ -98,7 +99,7 @@ export function describeDevMoonbeam( before("Starting Moonbeam Test Node", async function () { this.timeout(SPAWNING_TIME); const init = !DEBUG_MODE - ? await startMoonbeamDevNode(withWasm) + ? await startMoonbeamDevNode(withWasm, runtime) : { runningNode: null, p2pPort: 19931, @@ -273,7 +274,7 @@ export function describeDevMoonbeamAllEthTxTypes( withWasm?: boolean ) { let wasm = withWasm !== undefined ? withWasm : false; - describeDevMoonbeam(title + " (Legacy)", cb, "Legacy", wasm); - describeDevMoonbeam(title + " (EIP1559)", cb, "EIP1559", wasm); - describeDevMoonbeam(title + " (EIP2930)", cb, "EIP2930", wasm); + describeDevMoonbeam(title + " (Legacy)", cb, "Legacy", "moonbase", wasm); + describeDevMoonbeam(title + " (EIP1559)", cb, "EIP1559", "moonbase", wasm); + describeDevMoonbeam(title + " (EIP2930)", cb, "EIP2930", "moonbase", wasm); }