Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Storage Read costs for dev tests involved in #2786 #2915

Merged
merged 11 commits into from
Aug 29, 2024
4 changes: 4 additions & 0 deletions test/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export const RUNTIME_CONSTANTS = {
EXTRINSIC_GAS_LIMIT: 52_000_000n,
// Maximum Gas to PoV ratio used in the gasometer
GAS_PER_POV_BYTES: 16n,
// Storage read/write costs
STORAGE_READ_COST: 41_742_000n,
// Weight to gas convertion ratio
WEIGHT_TO_GAS_RATIO: 25_000n,
},
MOONRIVER: {
MIN_FEE_MULTIPLIER: 1_000_000_000_000_000_000n,
Expand Down
8 changes: 5 additions & 3 deletions test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
descendOriginFromAddress20,
injectHrmpMessage,
} from "../../../../helpers/xcm.js";
import { GAS_LIMIT_POV_RATIO } from "../../../../helpers/constants";
import { ConstantStore, GAS_LIMIT_POV_RATIO } from "../../../../helpers/constants";

describeSuite({
id: "D012706",
Expand All @@ -24,8 +24,10 @@ describeSuite({
let contracts: HeavyContract[];
const EXPECTED_POV_ROUGH = 350_000; // bytes
let balancesPalletIndex: number;
let STORAGE_READ_COST: bigint;

beforeAll(async function () {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
// Get Pallet balances index
const metadata = await context.polkadotJs().rpc.state.getMetadata();
const foundPallet = metadata.asLatest.pallets.find(
Expand Down Expand Up @@ -123,7 +125,7 @@ describeSuite({
Transact: {
originKind: "SovereignAccount",
requireWeightAtMost: {
refTime: 50_041_742_000,
refTime: 50_000_000_000n + STORAGE_READ_COST,
proofSize: GAS_LIMIT / GAS_LIMIT_POV_RATIO,
},
call: {
Expand Down Expand Up @@ -223,7 +225,7 @@ describeSuite({
Transact: {
originKind: "SovereignAccount",
requireWeightAtMost: {
refTime: 160_041_742_000,
refTime: 160_000_000_000n + STORAGE_READ_COST,
proofSize: GAS_LIMIT / GAS_LIMIT_POV_RATIO,
},
call: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
sendRawTransaction,
} from "@moonwall/util";
import { encodeFunctionData, fromHex } from "viem";
import { expectEVMResult, getSignatureParameters } from "../../../../helpers";
import { ConstantStore, expectEVMResult, getSignatureParameters } from "../../../../helpers";

describeSuite({
id: "D012822",
Expand Down Expand Up @@ -91,9 +91,12 @@ describeSuite({
.viem("public")
.getTransactionReceipt({ hash: batchSomeUntilFailureResult as `0x${string}` });

expect(batchAllReceipt["gasUsed"]).to.equal(45601n);
expect(batchSomeReceipt["gasUsed"]).to.equal(45601n);
expect(batchSomeUntilFailureReceipt["gasUsed"]).to.equal(45601n);
const STORAGE_READ_GAS_COST = // One storage read gas cost
ConstantStore(context).STORAGE_READ_COST / ConstantStore(context).WEIGHT_TO_GAS_RATIO;

expect(batchAllReceipt["gasUsed"]).to.equal(43932n + STORAGE_READ_GAS_COST);
expect(batchSomeReceipt["gasUsed"]).to.equal(43932n + STORAGE_READ_GAS_COST);
expect(batchSomeUntilFailureReceipt["gasUsed"]).to.equal(43932n + STORAGE_READ_GAS_COST);
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import "@moonbeam-network/api-augment";
import { describeSuite, expect } from "@moonwall/cli";
import { beforeAll, describeSuite, expect } from "@moonwall/cli";
import { GLMR, generateKeyringPair } from "@moonwall/util";
import { XcmVersionedXcm } from "@polkadot/types/lookup";
import { u8aToHex } from "@polkadot/util";
import { expectEVMResult, descendOriginFromAddress20 } from "../../../../helpers";
import { expectEVMResult, descendOriginFromAddress20, ConstantStore } from "../../../../helpers";

export const CLEAR_ORIGIN_WEIGHT = 5_194_000n;

Expand All @@ -12,6 +12,10 @@ describeSuite({
title: "Precompiles - xcm utils",
foundationMethods: "dev",
testCases: ({ context, it }) => {
let STORAGE_READ_COST;
beforeAll(async function () {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
});
it({
id: "T01",
title: "allows to retrieve parent-based ML account",
Expand Down Expand Up @@ -172,7 +176,7 @@ describeSuite({
{
Transact: {
originType: "SovereignAccount",
requireWeightAtMost: 566_742_000n, // 21_000 gas limit
requireWeightAtMost: 525_000_000n + STORAGE_READ_COST, // 21_000 gas limit
call: {
encoded: transferCallEncoded,
},
Expand Down Expand Up @@ -233,7 +237,7 @@ describeSuite({
{
Transact: {
originType: "SovereignAccount",
requireWeightAtMost: 566_742_000n, // 21_000 gas limit
requireWeightAtMost: 525_000_000n + STORAGE_READ_COST, // 21_000 gas limit
call: {
encoded: transferCallEncoded,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
injectHrmpMessageAndSeal,
descendOriginFromAddress20,
} from "../../../../helpers/xcm.js";
import { ConstantStore } from "../../../../helpers/constants.js";

describeSuite({
id: "D014020",
Expand All @@ -19,8 +20,10 @@ describeSuite({
let sendingAddress: `0x${string}`;
let descendAddress: `0x${string}`;
let random: KeyringPair;
let STORAGE_READ_COST: bigint;

beforeAll(async () => {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
Expand Down Expand Up @@ -53,8 +56,6 @@ describeSuite({

const amountToTransfer = transferredBalance / 10n;
const TX_GAS_LIMIT = 21_000;
// TODO: move this to the constant file
const STORAGE_READ_COST = 41_742_000n;

const xcmTransactions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
injectHrmpMessageAndSeal,
descendOriginFromAddress20,
} from "../../../../helpers/xcm.js";
import { ConstantStore } from "../../../../helpers/constants.js";

describeSuite({
id: "D014023",
Expand All @@ -19,8 +20,10 @@ describeSuite({
let sendingAddress: `0x${string}`;
let descendAddress: `0x${string}`;
let random: KeyringPair;
let STORAGE_READ_COST;

beforeAll(async () => {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
Expand Down Expand Up @@ -54,8 +57,6 @@ describeSuite({
const amountToTransfer = transferredBalance / 10n;

const GAS_LIMIT = 500_000;
// TODO: move this to the constant file
const STORAGE_READ_COST = 41_742_000n;

// We will put a very high gas limit. However, the weight accounted
// for the block should only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
weightMessage,
} from "../../../../helpers/xcm.js";
import { registerOldForeignAsset } from "../../../../helpers/assets.js";
import { ConstantStore } from "../../../../helpers/constants.js";

describeSuite({
id: "D014025",
Expand Down Expand Up @@ -54,7 +55,10 @@ describeSuite({

const assetsToTransfer = 100_000_000_000n;

let STORAGE_READ_COST: bigint;

beforeAll(async () => {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
const { contractAddress, abi } = await context.deployContract!("Incrementor");

contractDeployed = contractAddress;
Expand Down Expand Up @@ -171,8 +175,6 @@ describeSuite({
];

let expectedCalls = 0n;
// TODO: move this to the constant file
const STORAGE_READ_COST = 41_742_000n;

for (const xcmTransaction of xcmTransactions) {
expectedCalls++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
injectHrmpMessageAndSeal,
descendOriginFromAddress20,
} from "../../../../helpers/xcm.js";
import { ConstantStore } from "../../../../helpers/constants.js";

describeSuite({
id: "D014028",
Expand All @@ -21,8 +22,11 @@ describeSuite({
let sendingAddress: `0x${string}`;
let descendAddress: `0x${string}`;
let random: KeyringPair;
let STORAGE_READ_COST: bigint;

beforeAll(async () => {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;

const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address as `0x${string}`
Expand Down Expand Up @@ -72,8 +76,6 @@ describeSuite({

const amountToTransfer = transferredBalance / 10n;
const GAS_LIMIT = 21_000;
// TODO: move this to the constant file
const STORAGE_READ_COST = 41_742_000n;

const xcmTransactions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
injectHrmpMessageAndSeal,
descendOriginFromAddress20,
} from "../../../../helpers/xcm.js";
import { ConstantStore } from "../../../../helpers/constants.js";

describeSuite({
id: "D014117",
Expand All @@ -20,7 +21,10 @@ describeSuite({
let descendAddress: `0x${string}`;
let random: KeyringPair;

let STORAGE_READ_COST: bigint;

beforeAll(async () => {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
Expand Down Expand Up @@ -52,8 +56,6 @@ describeSuite({
.index.toNumber();

const amountToTransfer = transferredBalance / 10n;
// TODO: move this to the constant file
const STORAGE_READ_COST = 41_742_000n;

const xcmTransactions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
injectHrmpMessageAndSeal,
descendOriginFromAddress20,
} from "../../../../helpers/xcm.js";
import { ConstantStore } from "../../../../helpers/constants.js";

describeSuite({
id: "D014122",
Expand All @@ -22,7 +23,10 @@ describeSuite({
let descendAddress: `0x${string}`;
let random: KeyringPair;

let STORAGE_READ_COST: bigint;

beforeAll(async () => {
STORAGE_READ_COST = ConstantStore(context).STORAGE_READ_COST;
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address as `0x${string}`
Expand Down Expand Up @@ -72,9 +76,6 @@ describeSuite({

const amountToTransfer = transferredBalance / 10n;

// TODO: move this to the constant file
const STORAGE_READ_COST = 41_742_000n;

const xcmTransactions = [
{
V1: {
Expand Down
Loading