From 80d6f17ad88252b772b0bd35064e2392494473e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?pablito=20=E3=83=86?= Date: Thu, 29 Aug 2024 09:57:58 -0300 Subject: [PATCH] Extract Storage Read costs for dev tests involved in #2786 (#2915) * add: storage read cost constant * update test-pov * update xcm-v3 tests * update xcm-v4 tests * add storage read gas cost to constants * update test-precompile * load constant in beforeAll * replace gas cost with weight to gas ratio --- test/helpers/constants.ts | 4 ++++ .../dev/moonbase/test-pov/test-xcm-to-evm-pov.ts | 8 +++++--- .../test-precompile/test-precompile-batch.ts | 11 +++++++---- .../test-precompile/test-precompile-xcm-utils.ts | 12 ++++++++---- .../test-mock-hrmp-transact-ethereum-1.ts | 5 +++-- .../test-mock-hrmp-transact-ethereum-12.ts | 5 +++-- .../test-mock-hrmp-transact-ethereum-3.ts | 6 ++++-- .../test-mock-hrmp-transact-ethereum-6.ts | 6 ++++-- .../test-mock-hrmp-transact-ethereum-1.ts | 6 ++++-- .../test-mock-hrmp-transact-ethereum-6.ts | 7 ++++--- 10 files changed, 46 insertions(+), 24 deletions(-) diff --git a/test/helpers/constants.ts b/test/helpers/constants.ts index 7a5200d265..f086a58ce7 100644 --- a/test/helpers/constants.ts +++ b/test/helpers/constants.ts @@ -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, diff --git a/test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts b/test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts index 1fa6a05931..22940a5a6a 100644 --- a/test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts +++ b/test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts @@ -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", @@ -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( @@ -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: { @@ -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: { diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-batch.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-batch.ts index 87d1330a2d..5800a2d149 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-batch.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-batch.ts @@ -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", @@ -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); }, }); diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-utils.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-utils.ts index d9000fe7eb..6b4dcf9b06 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-utils.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-utils.ts @@ -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; @@ -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", @@ -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, }, @@ -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, }, diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-1.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-1.ts index d3abd6d33f..15b97731f0 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-1.ts @@ -9,6 +9,7 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, } from "../../../../helpers/xcm.js"; +import { ConstantStore } from "../../../../helpers/constants.js"; describeSuite({ id: "D014020", @@ -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; @@ -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 = [ { diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-12.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-12.ts index 7787456b1b..37b7127cbf 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-12.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-12.ts @@ -9,6 +9,7 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, } from "../../../../helpers/xcm.js"; +import { ConstantStore } from "../../../../helpers/constants.js"; describeSuite({ id: "D014023", @@ -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; @@ -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 diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts index 66e4e12564..7dfe122534 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts @@ -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", @@ -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; @@ -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++; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-6.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-6.ts index 89a3916164..e3383798a0 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-6.ts @@ -9,6 +9,7 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, } from "../../../../helpers/xcm.js"; +import { ConstantStore } from "../../../../helpers/constants.js"; describeSuite({ id: "D014028", @@ -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}` @@ -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 = [ { diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-1.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-1.ts index 3a279a8887..22f0bb2b9e 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-1.ts @@ -9,6 +9,7 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, } from "../../../../helpers/xcm.js"; +import { ConstantStore } from "../../../../helpers/constants.js"; describeSuite({ id: "D014117", @@ -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; @@ -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 = [ { diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-6.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-6.ts index 1ffd09ad4b..ab1baf6c72 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-transact-ethereum-6.ts @@ -9,6 +9,7 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, } from "../../../../helpers/xcm.js"; +import { ConstantStore } from "../../../../helpers/constants.js"; describeSuite({ id: "D014122", @@ -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}` @@ -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: {