diff --git a/Cargo.lock b/Cargo.lock index 5657a4dd18f..bd0406bf2b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3088,7 +3088,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "async-trait", "fp-storage", @@ -3100,7 +3100,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "async-trait", "fp-consensus", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "async-trait", "ethereum", @@ -3146,7 +3146,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fc-db", "fc-storage", @@ -3169,7 +3169,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "ethereum", "ethereum-types", @@ -3215,6 +3215,7 @@ dependencies = [ "sp-state-machine", "sp-storage", "sp-timestamp", + "sp-trie", "substrate-prometheus-endpoint", "thiserror", "tokio", @@ -3223,7 +3224,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "ethereum", "ethereum-types", @@ -3238,7 +3239,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "ethereum", "ethereum-types", @@ -3428,7 +3429,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "hex", "impl-serde", @@ -3447,7 +3448,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "ethereum", "parity-scale-codec", @@ -3458,7 +3459,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "ethereum", "ethereum-types", @@ -3470,7 +3471,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "environmental", "evm", @@ -3486,7 +3487,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "ethereum", "ethereum-types", @@ -3502,7 +3503,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "frame-support", "parity-scale-codec", @@ -3514,7 +3515,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "parity-scale-codec", "serde", @@ -6616,6 +6617,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", + "sp-trie", "tokio", ] @@ -8584,7 +8586,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "environmental", "ethereum", @@ -8640,8 +8642,9 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ + "cumulus-primitives-storage-weight-reclaim", "environmental", "evm", "fp-account", @@ -8663,7 +8666,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "frame-support", "frame-system", @@ -8758,7 +8761,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", ] @@ -8766,7 +8769,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", "sp-core", @@ -8898,7 +8901,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", "frame-support", @@ -8974,7 +8977,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", "num", @@ -9219,7 +9222,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", "tiny-keccak", @@ -9228,7 +9231,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", "ripemd", @@ -9238,7 +9241,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-storage-cleaner" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "fp-evm", "frame-support", @@ -11976,7 +11979,7 @@ dependencies = [ [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "derive_more", "environmental", @@ -12005,7 +12008,7 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#439e782fb9754c38188158cd65d1eba6fe9f0e65" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-stable2407#56349814c1e029d99a9c433cc229e81d32cb0aff" dependencies = [ "case", "num_enum 0.7.3", diff --git a/client/rpc/debug/Cargo.toml b/client/rpc/debug/Cargo.toml index f4fbfcc7d5f..dc2944dc9c3 100644 --- a/client/rpc/debug/Cargo.toml +++ b/client/rpc/debug/Cargo.toml @@ -28,6 +28,7 @@ sp-blockchain = { workspace = true } sp-core = { workspace = true, features = [ "std" ] } sp-io = { workspace = true, features = [ "std" ] } sp-runtime = { workspace = true, features = [ "std" ] } +sp-trie = { workspace = true, features = [ "std" ] } # Frontier ethereum = { workspace = true, features = [ "std", "with-codec" ] } diff --git a/client/rpc/debug/src/lib.rs b/client/rpc/debug/src/lib.rs index 9a653bd659e..32517614c22 100644 --- a/client/rpc/debug/src/lib.rs +++ b/client/rpc/debug/src/lib.rs @@ -392,7 +392,15 @@ where }?; // Get ApiRef. This handle allow to keep changes between txs in an internal buffer. - let api = client.runtime_api(); + let mut api = client.runtime_api(); + + // Enable proof recording + api.record_proof(); + api.proof_recorder().map(|recorder| { + let ext = sp_trie::proof_size_extension::ProofSizeExt::new(recorder); + api.register_extension(ext); + }); + // Get Blockchain backend let blockchain = backend.blockchain(); // Get the header I want to work with. @@ -556,7 +564,15 @@ where Err(e) => return Err(e), }; // Get ApiRef. This handle allow to keep changes between txs in an internal buffer. - let api = client.runtime_api(); + let mut api = client.runtime_api(); + + // Enable proof recording + api.record_proof(); + api.proof_recorder().map(|recorder| { + let ext = sp_trie::proof_size_extension::ProofSizeExt::new(recorder); + api.register_extension(ext); + }); + // Get Blockchain backend let blockchain = backend.blockchain(); // Get the header I want to work with. @@ -762,7 +778,15 @@ where }?; // Get ApiRef. This handle allow to keep changes between txs in an internal buffer. - let api = client.runtime_api(); + let mut api = client.runtime_api(); + + // Enable proof recording + api.record_proof(); + api.proof_recorder().map(|recorder| { + let ext = sp_trie::proof_size_extension::ProofSizeExt::new(recorder); + api.register_extension(ext); + }); + // Get the header I want to work with. let Ok(hash) = client.expect_block_hash_from_id(&reference_id) else { return Err(internal_err("Block header not found")); diff --git a/test/moonwall.config.json b/test/moonwall.config.json index fbd15e67f91..7e5b42bebd7 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -346,7 +346,7 @@ { "name": "lazy_loading_moonbeam", "testFileDir": ["suites/lazy-loading"], - "include": ["**/*test*"], + "include": ["**/*test*.ts"], "timeout": 180000, "contracts": "contracts/", "runScripts": [ @@ -392,7 +392,7 @@ { "name": "dev_moonbeam", "testFileDir": ["suites/dev/moonbeam", "suites/dev/common"], - "include": ["**/*test*"], + "include": ["**/*test*.ts"], "timeout": 180000, "contracts": "contracts/", "runScripts": [ @@ -435,7 +435,7 @@ { "name": "dev_moonriver", "testFileDir": ["suites/dev/common"], - "include": ["**/*test*"], + "include": ["**/*test*.ts"], "timeout": 180000, "contracts": "contracts/", "runScripts": [ @@ -478,7 +478,7 @@ { "name": "dev_moonbase", "testFileDir": ["suites/dev/moonbase", "suites/dev/common"], - "include": ["**/*test*"], + "include": ["**/*test*.ts"], "timeout": 180000, "contracts": "contracts/", "runScripts": [ @@ -521,7 +521,7 @@ { "name": "dev_moonbase_tracing", "testFileDir": ["suites/tracing-tests"], - "include": ["**/*test*"], + "include": ["**/*test*.ts"], "contracts": "contracts/", "runScripts": [ "compile-contracts.ts compile", diff --git a/test/suites/dev/moonbase/test-gas/test-gas-estimation-contracts.ts b/test/suites/dev/moonbase/test-gas/test-gas-estimation-contracts.ts index 8c7f10dc155..0cd9aba06e2 100644 --- a/test/suites/dev/moonbase/test-gas/test-gas-estimation-contracts.ts +++ b/test/suites/dev/moonbase/test-gas/test-gas-estimation-contracts.ts @@ -149,21 +149,23 @@ describeSuite({ it({ id: "T05", title: "Should be able to estimate gas of infinite loop call", - timeout: 240000, + timeout: 60000, test: async function () { const { contractAddress, abi } = await deployCreateCompiledContract(context, "Looper"); expect( async () => - await context.viem().estimateGas({ - account: ALITH_ADDRESS, - to: contractAddress, - data: encodeFunctionData({ - abi: abi, - functionName: "infinite", - args: [], - }), - }) + await customDevRpcRequest("eth_estimateGas", [ + { + from: ALITH_ADDRESS, + to: contractAddress, + data: encodeFunctionData({ + abi: abi, + functionName: "infinite", + args: [], + }), + }, + ]) ).rejects.toThrowError("gas required exceeds allowance 6000000"); }, }); diff --git a/test/suites/dev/moonbase/test-gas/test-gas-estimation-multiply.ts b/test/suites/dev/moonbase/test-gas/test-gas-estimation-multiply.ts index a867ea70e4e..15b2ef79d9f 100644 --- a/test/suites/dev/moonbase/test-gas/test-gas-estimation-multiply.ts +++ b/test/suites/dev/moonbase/test-gas/test-gas-estimation-multiply.ts @@ -32,7 +32,8 @@ describeSuite({ value: 0n, }); - expect(estimatedGas).to.equal(22363n); + // Snapshot estimated gas + expect(estimatedGas).toMatchInlineSnapshot(`22363n`); }, }); @@ -52,7 +53,8 @@ describeSuite({ value: 0n, }); - expect(estimatedGas).to.equal(22363n); + // Snapshot estimated gas + expect(estimatedGas).toMatchInlineSnapshot(`22363n`); }, }); @@ -71,7 +73,7 @@ describeSuite({ value: 0n, }); - expect(estimatedGas).to.equal(22363n); + expect(estimatedGas).toMatchInlineSnapshot(`22363n`); }, }); @@ -91,7 +93,8 @@ describeSuite({ value: 0n, }); - expect(estimatedGas).to.equal(22363n); + // Snapshot estimated gas + expect(estimatedGas).toMatchInlineSnapshot(`22363n`); }, }); diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts index 60eaffb2cd1..be123caad7c 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts @@ -127,10 +127,24 @@ describeSuite({ .query.assets.approvals(assetId.toU8a(), erc20InstanceAddress, BALTATHAR_ADDRESS); expect(newApprovals.unwrap().amount.toBigInt()).to.equal(1000n); + const estimatedGas = await context.viem().estimateGas({ + account: BALTATHAR_ADDRESS, + to: ADDRESS_ERC20, + data: encodeFunctionData({ + abi: erc20Abi, + functionName: "transferFrom", + args: [erc20InstanceAddress, CHARLETH_ADDRESS, 1000], + }), + }); + + // Snapshot estimated gas + expect(estimatedGas).toMatchInlineSnapshot(`111252n`); + // this time we call directly from Baltathar the ERC20 contract const directBlock = await context.createBlock( createViemTransaction(context, { privateKey: BALTATHAR_PRIVATE_KEY, + gas: estimatedGas, to: ADDRESS_ERC20, data: encodeFunctionData({ functionName: "transferFrom", diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-proxy.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-proxy.ts index 3d7e8eec632..f89090e47f1 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-proxy.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-proxy.ts @@ -501,11 +501,7 @@ describeSuite({ // The account cannot be random otherwise the calldata might contain more // zero bytes and have a different gas cost const randomAccount = "0x1ced798a66b803d0dbb665680283980a939a6432"; - // The tx can create an account, so record 148 bytes of storage growth - // Storage growth ratio is 366 - // storage_gas = 148 * 366 = 54168 - // pov_gas = 5693 * 16 = 91088 - const expectedGas = 91_088n; + const rawTxn = await context.writePrecompile!({ precompileName: "Proxy", functionName: "addProxy", @@ -541,7 +537,11 @@ describeSuite({ const { gasUsed } = await context .viem() .getTransactionReceipt({ hash: result2!.hash as `0x${string}` }); - expect(gasUsed).to.equal(expectedGas); + const expectedMinimumPovGas = 59000n; + // pov_gas = proof_size * GAS_LIMIT_POV_RATIO + // proof size reclaim seems indeterministic + expect(gasUsed).toBeGreaterThan(expectedMinimumPovGas); + expect(gasUsed).toBeLessThan(expectedMinimumPovGas + 2000n); expect(await context.viem().getBalance({ address: randomAccount })).toBe(parseEther("5")); diff --git a/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery2.ts b/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery2.ts index 09ca9206694..31ca88862b8 100644 --- a/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery2.ts +++ b/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery2.ts @@ -47,7 +47,7 @@ describeSuite({ args: [0], account: BALTATHAR_ADDRESS, }); - expect(estimatedGas).toMatchInlineSnapshot(`303092n`); + expect(estimatedGas).toMatchInlineSnapshot(`295530n`); const rawTxn = await context.writePrecompile!({ precompileName: "Randomness", @@ -64,7 +64,7 @@ describeSuite({ fulFillReceipt = await context .viem() .getTransactionReceipt({ hash: result![1].hash as `0x${string}` }); - expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`280576n`); + expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`158480n`); }); it({ diff --git a/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery3.ts b/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery3.ts index b516570b897..6fcb4efee27 100644 --- a/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery3.ts +++ b/test/suites/dev/moonbase/test-randomness/test-randomness-babe-lottery3.ts @@ -110,7 +110,7 @@ describeSuite({ account: BALTATHAR_ADDRESS, }); log("Estimated Gas for startLottery", estimatedGas); - expect(estimatedGas).toMatchInlineSnapshot(`303092n`); + expect(estimatedGas).toMatchInlineSnapshot(`298280n`); const rawTxn = await context.writePrecompile!({ precompileName: "Randomness", diff --git a/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery4.ts b/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery4.ts index 44511974c03..44fe11620a9 100644 --- a/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery4.ts +++ b/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery4.ts @@ -47,7 +47,7 @@ describeSuite({ args: [0], }); log("Estimated Gas for startLottery", estimatedGas); - expect(estimatedGas).toMatchInlineSnapshot(`285461n`); + expect(estimatedGas).toMatchInlineSnapshot(`284196n`); const rawTxn = await context.writePrecompile!({ precompileName: "Randomness", diff --git a/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery5.ts b/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery5.ts index 5424b1e8e58..368480f16a4 100644 --- a/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery5.ts +++ b/test/suites/dev/moonbase/test-randomness/test-randomness-vrf-lottery5.ts @@ -48,7 +48,7 @@ describeSuite({ args: [0], }); - expect(estimatedGas).toMatchInlineSnapshot(`285461n`); + expect(estimatedGas).toMatchInlineSnapshot(`284196n`); const rawTxn = await context.writePrecompile!({ precompileName: "Randomness", @@ -63,7 +63,7 @@ describeSuite({ .viem() .getTransactionReceipt({ hash: result!.hash as `0x${string}` }); - expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`280576n`); + expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`164016n`); }); it({ id: "T01", diff --git a/test/suites/dev/moonbase/test-storage-growth/test-precompile-storage-growth.ts b/test/suites/dev/moonbase/test-storage-growth/test-precompile-storage-growth.ts index e15e487b8a9..b3cd42b7cff 100644 --- a/test/suites/dev/moonbase/test-storage-growth/test-precompile-storage-growth.ts +++ b/test/suites/dev/moonbase/test-storage-growth/test-precompile-storage-growth.ts @@ -6,6 +6,7 @@ import { FAITH_ADDRESS, FAITH_PRIVATE_KEY, PRECOMPILE_NATIVE_ERC20_ADDRESS, + PRECOMPILE_PROXY_ADDRESS, } from "@moonwall/util"; import { parseEther } from "ethers"; import { expectEVMResult } from "helpers/eth-transactions"; @@ -17,17 +18,26 @@ describeSuite({ foundationMethods: "dev", testCases: ({ context, it, log }) => { const newAccount = "0x1ced798a66b803d0dbb665680283980a939a6432"; - // The tx can create an account, so record 148 bytes of storage growth - // Storage growth ratio is 366 - // storage_gas = 148 * 366 = 54168 - // pov_gas = 5693 * 16 = 91088 - const expectedGas = 91_088n; it({ id: "T01", title: "should fail transfer due to insufficient gas required to cover the storage growth", test: async () => { const { abi: ierc20Abi } = fetchCompiledContract("IERC20"); + const { abi: proxyAbi } = fetchCompiledContract("Proxy"); + + const estimatedGas = await context.viem().estimateGas({ + account: FAITH_ADDRESS, + to: PRECOMPILE_PROXY_ADDRESS, + data: encodeFunctionData({ + abi: proxyAbi, + functionName: "addProxy", + args: [BALTATHAR_ADDRESS, CONTRACT_PROXY_TYPE_ANY, 0], + }), + }); + + // Snapshot estimated gas + expect(estimatedGas).toMatchInlineSnapshot(`102539n`); const rawTxn = await context.writePrecompile!({ precompileName: "Proxy", @@ -35,11 +45,32 @@ describeSuite({ args: [BALTATHAR_ADDRESS, CONTRACT_PROXY_TYPE_ANY, 0], privateKey: FAITH_PRIVATE_KEY, rawTxOnly: true, - gas: 1_000_000n, + gas: estimatedGas, }); const { result } = await context.createBlock(rawTxn); expectEVMResult(result!.events, "Succeed"); + const proxyProxyEstimatedGas = await context.viem().estimateGas({ + account: BALTATHAR_ADDRESS, + to: PRECOMPILE_PROXY_ADDRESS, + data: encodeFunctionData({ + abi: proxyAbi, + functionName: "proxy", + args: [ + FAITH_ADDRESS, + PRECOMPILE_NATIVE_ERC20_ADDRESS, + encodeFunctionData({ + abi: ierc20Abi, + functionName: "transfer", + args: [newAccount, parseEther("5")], + }), + ], + }), + }); + + // Snapshot estimated gas + expect(proxyProxyEstimatedGas).toMatchInlineSnapshot(`91908n`); + const balBefore = await context.viem().getBalance({ address: FAITH_ADDRESS }); const rawTxn2 = await context.writePrecompile!({ precompileName: "Proxy", @@ -55,7 +86,7 @@ describeSuite({ ], privateKey: BALTATHAR_PRIVATE_KEY, rawTxOnly: true, - gas: 40_000n, + gas: proxyProxyEstimatedGas - 10_000n, }); const { result: result2 } = await context.createBlock(rawTxn2); @@ -73,6 +104,28 @@ describeSuite({ test: async () => { const balBefore = await context.viem().getBalance({ address: FAITH_ADDRESS }); const { abi: ierc20Abi } = fetchCompiledContract("IERC20"); + const { abi: proxyAbi } = fetchCompiledContract("Proxy"); + + const estimatedGas = await context.viem().estimateGas({ + account: BALTATHAR_ADDRESS, + to: PRECOMPILE_PROXY_ADDRESS, + data: encodeFunctionData({ + abi: proxyAbi, + functionName: "proxy", + args: [ + FAITH_ADDRESS, + PRECOMPILE_NATIVE_ERC20_ADDRESS, + encodeFunctionData({ + abi: ierc20Abi, + functionName: "transfer", + args: [newAccount, parseEther("5")], + }), + ], + }), + }); + + // Snapshot estimated gas + expect(estimatedGas).toMatchInlineSnapshot(`91908n`); const rawTxn2 = await context.writePrecompile!({ precompileName: "Proxy", @@ -88,7 +141,7 @@ describeSuite({ ], privateKey: BALTATHAR_PRIVATE_KEY, rawTxOnly: true, - gas: expectedGas, + gas: estimatedGas, }); const { result } = await context.createBlock(rawTxn2); @@ -98,7 +151,12 @@ describeSuite({ const { gasUsed } = await context .viem() .getTransactionReceipt({ hash: result!.hash as `0x${string}` }); - expect(gasUsed).to.equal(expectedGas); + + // The tx can create an account, so record 148 bytes of storage growth + // Storage growth ratio is 366 + // storage_gas = 148 * 366 = 54168 + // pov_gas = proof_size * GAS_LIMIT_POV_RATIO + expect(gasUsed).toMatchInlineSnapshot(`58336n`); const balAfter = await context.viem().getBalance({ address: FAITH_ADDRESS }); expect(balBefore - balAfter).to.equal(parseEther("5"));