Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/tests/test-assets/test-assets-sufficients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describeDevMoonbeam(
});
},
"Legacy",
"moonbase",
true
);

Expand Down Expand Up @@ -267,6 +268,7 @@ describeDevMoonbeam(
});
},
"Legacy",
"moonbase",
true
);

Expand Down Expand Up @@ -407,5 +409,6 @@ describeDevMoonbeam(
});
},
"Legacy",
"moonbase",
true
);
3 changes: 3 additions & 0 deletions tests/tests/test-eth-tx/test-eth-tx-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describeDevMoonbeam(
});
},
"Legacy",
"moonbase",
false
);

Expand Down Expand Up @@ -76,6 +77,7 @@ describeDevMoonbeam(
});
},
"EIP2930",
"moonbase",
false
);

Expand Down Expand Up @@ -123,5 +125,6 @@ describeDevMoonbeam(
});
},
"EIP1559",
"moonbase",
false
);
121 changes: 121 additions & 0 deletions tests/tests/test-fees/test-length-fees.ts
Original file line number Diff line number Diff line change
@@ -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;
};
14 changes: 12 additions & 2 deletions tests/util/dev-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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}`,
Expand Down
11 changes: 6 additions & 5 deletions tests/util/setup-dev-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -81,6 +81,7 @@ export function describeDevMoonbeam(
title: string,
cb: (context: DevTestContext) => void,
ethTransactionType: EthTransactionType = "Legacy",
runtime: RuntimeChain = "moonbase",
withWasm?: boolean
) {
describe(title, function () {
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}