diff --git a/Cargo.lock b/Cargo.lock index 3d9585834e..3612469a21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3389,7 +3389,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "async-trait", "fp-storage", @@ -3401,7 +3401,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "async-trait", "fp-consensus", @@ -3417,7 +3417,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "async-trait", "ethereum", @@ -3447,7 +3447,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fc-db", "fc-storage", @@ -3470,7 +3470,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "ethereum", "ethereum-types", @@ -3524,7 +3524,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "ethereum", "ethereum-types", @@ -3539,7 +3539,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "ethereum", "ethereum-types", @@ -3733,7 +3733,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "hex", "impl-serde 0.4.0", @@ -3751,7 +3751,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "ethereum", "parity-scale-codec", @@ -3762,7 +3762,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "ethereum", "ethereum-types", @@ -3774,8 +3774,9 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ + "environmental", "evm", "frame-support", "num_enum 0.7.2", @@ -3789,7 +3790,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "ethereum", "ethereum-types", @@ -3805,7 +3806,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "frame-support", "parity-scale-codec", @@ -3817,7 +3818,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "parity-scale-codec", "serde", @@ -8777,7 +8778,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "environmental", "ethereum", @@ -8833,7 +8834,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "environmental", "evm", @@ -8858,7 +8859,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "frame-support", "frame-system", @@ -8953,7 +8954,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", ] @@ -8961,7 +8962,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", "sp-core", @@ -9093,7 +9094,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", "frame-support", @@ -9170,7 +9171,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", "num", @@ -9416,7 +9417,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", "tiny-keccak", @@ -9425,7 +9426,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", "ripemd", @@ -9435,7 +9436,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-storage-cleaner" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "fp-evm", "frame-support", @@ -12216,7 +12217,7 @@ dependencies = [ [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "derive_more", "environmental", @@ -12245,7 +12246,7 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#9a74ea7ae476886a6e840196e5603c411444c31c" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#42a7a8e179bb96401daf6c71728e6c71e38c8293" dependencies = [ "case", "num_enum 0.7.2", diff --git a/test/contracts/src/BloatedContract.sol b/test/contracts/src/BloatedContract.sol new file mode 100644 index 0000000000..0b843253ff --- /dev/null +++ b/test/contracts/src/BloatedContract.sol @@ -0,0 +1,13 @@ + +// SPDX-License-Identifier: GPL-3.0-only +pragma solidity ^0.8.24; + +contract BloatedContract { + string public constant HUGE = + "0009029190000120068200810084000002900009444026015071899001591001260845208240017000684720039550000028098850000070600000600003552005936017007053807100000041771580000244664000088007500007700000400000096706200270000267100001000969750000067700056830092002978180072930092092021000644480200750000008400830389708783012663109400001023405538004655400240000045404920000006600110094000113481000525400601812000000056007306626044000042720008605282710425473000027800233400300002500009102903167660730097009598200220053180002052169775049488200700750005660079099422811952047000025490610000097000342400467600000770830040000980026218502900078170000000620450000054000081000003552008290356000000000800003250415214008770723805244741000088000000000592636380007300084062950000018000000008777510000420180307006800190005410046470000416500004200291992003400000111189020270874000700000009900079000040000006000000010006712810006797000500210000067655604000004308300005800111313000032039850411100369100031870182209200019820120611924838009009678000920000000001855000308001341017097640019016027860099820094005600000330202920000615900060680004007000003612660000024005355620550005065000540002100041072059005000003907461062035012000096000028720026611364106886000000999800000001476288954000075200296302389837609535878931960004309600800000290000039000949095033429466000669329005000019420460820075940423086032007000361302000000060627242000320032000000002104000000950780090025075000000075250000990410503708408505037000000700000024090000083063002900144304000004200037007762004203857170057020062273802992604900120068910000750008806400093095005947000990000420088566045090000000015360410000081117690150530002403100036011830000000042051081800105000001066087053027074000009425610442298002698000156609707815450000439406500026330071080007653001100550630637749000000178000005304485000890000052110954284820000000035130"; + string store = ""; + + function doSomething() public { + store = HUGE; + } +} diff --git a/test/contracts/src/SubCallOOG.sol b/test/contracts/src/SubCallOOG.sol new file mode 100644 index 0000000000..48af33cbf4 --- /dev/null +++ b/test/contracts/src/SubCallOOG.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-3.0-only +pragma solidity >=0.8.3; + +interface IBloatedContract { + function doSomething() external; +} + +interface ILooper { + function incrementalLoop(uint256 n) external; +} + +contract SubCallOOG { + event SubCallSucceed(); + event SubCallFail(); + + function subCallPov(address[] memory addresses) public { + for (uint256 i = 0; i < addresses.length; i++) { + try IBloatedContract(addresses[i]).doSomething() { + emit SubCallSucceed(); + } catch (bytes memory) { + emit SubCallFail(); + } + } + } + + function subCallLooper(address target, uint256 n) public { + try ILooper(target).incrementalLoop(n) { + emit SubCallSucceed(); + } catch (bytes memory) { + emit SubCallFail(); + } + } +} diff --git a/test/suites/dev/moonbase/test-gas/test-gas-estimation-subcall-oog.ts b/test/suites/dev/moonbase/test-gas/test-gas-estimation-subcall-oog.ts new file mode 100644 index 0000000000..127b12bc9d --- /dev/null +++ b/test/suites/dev/moonbase/test-gas/test-gas-estimation-subcall-oog.ts @@ -0,0 +1,117 @@ +import "@moonbeam-network/api-augment"; +import { beforeAll, deployCreateCompiledContract, describeSuite, expect } from "@moonwall/cli"; +import { ALITH_ADDRESS } from "@moonwall/util"; +import { Abi, decodeEventLog, encodeFunctionData } from "viem"; + +describeSuite({ + id: "D011805", + title: "Estimate Gas - subCall", + foundationMethods: "dev", + testCases: ({ context, it, log }) => { + let looperAddress: `0x${string}`; + let subCallOogAbi: Abi; + let subCallOogAddress: `0x${string}`; + + const bloatedContracts: string[] = []; + const MAX_BLOATED_CONTRACTS = 15; + + beforeAll(async function () { + const { contractAddress: contractAddress2 } = await deployCreateCompiledContract( + context, + "Looper" + ); + looperAddress = contractAddress2; + + const { abi, contractAddress: contractAddress3 } = await deployCreateCompiledContract( + context, + "SubCallOOG" + ); + subCallOogAbi = abi; + subCallOogAddress = contractAddress3; + + // Deploy bloated contracts (test won't use more than what is needed for reaching max pov) + for (let i = 0; i <= MAX_BLOATED_CONTRACTS; i++) { + const { contractAddress } = await deployCreateCompiledContract(context, "BloatedContract"); + bloatedContracts.push(contractAddress); + } + }); + + it({ + id: "T01", + title: "gas estimation should make subcall OOG", + test: async function () { + const estimatedGas = await context.viem().estimateContractGas({ + account: ALITH_ADDRESS, + abi: subCallOogAbi, + address: subCallOogAddress, + functionName: "subCallLooper", + maxPriorityFeePerGas: 0n, + args: [looperAddress, 999], + value: 0n, + }); + + const txHash = await context.viem().sendTransaction({ + to: subCallOogAddress, + data: encodeFunctionData({ + abi: subCallOogAbi, + functionName: "subCallLooper", + args: [looperAddress, 999], + }), + txnType: "eip1559", + gasLimit: estimatedGas, + }); + + await context.createBlock(); + + const receipt = await context.viem().getTransactionReceipt({ hash: txHash }); + + const decoded = decodeEventLog({ + abi: subCallOogAbi, + data: receipt.logs[0].data, + topics: receipt.logs[0].topics, + }) as any; + + expect(decoded.eventName).to.equal("SubCallFail"); + }, + }); + + it({ + id: "T02", + title: "gas estimation should make pov-consuming subcall suceed", + test: async function () { + const estimatedGas = await context.viem().estimateContractGas({ + account: ALITH_ADDRESS, + abi: subCallOogAbi, + address: subCallOogAddress, + functionName: "subCallPov", + maxPriorityFeePerGas: 0n, + args: [bloatedContracts], + value: 0n, + }); + + log(`Estimated gas: ${estimatedGas}`); + + const txHash = await context.viem().sendTransaction({ + to: subCallOogAddress, + data: encodeFunctionData({ + abi: subCallOogAbi, + functionName: "subCallPov", + args: [bloatedContracts], + }), + txnType: "eip1559", + gasLimit: estimatedGas, + }); + + await context.createBlock(); + + const receipt = await context.viem().getTransactionReceipt({ hash: txHash }); + const decoded = decodeEventLog({ + abi: subCallOogAbi, + data: receipt.logs[bloatedContracts.length - 1].data, + topics: receipt.logs[bloatedContracts.length - 1].topics, + }) as any; + expect(decoded.eventName).to.equal("SubCallSucceed"); + }, + }); + }, +}); 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 ad7f12fd8a..aa807d2c02 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 @@ -1,8 +1,10 @@ import "@moonbeam-network/api-augment/moonbase"; import { beforeEach, describeSuite, expect, fetchCompiledContract } from "@moonwall/cli"; import { + BALTATHAR_ADDRESS, BALTATHAR_PRIVATE_KEY, CONTRACT_RANDOMNESS_STATUS_PENDING, + CONTRACT_RANDOMNESS_STATUS_READY, GLMR, createViemTransaction, } from "@moonwall/util"; @@ -23,13 +25,23 @@ describeSuite({ beforeEach(async function () { lotteryAddress = await setupLotteryWithParticipants(context, "BABE"); + const estimatedGas = await context.viem().estimateContractGas({ + address: lotteryAddress, + abi: fetchCompiledContract("RandomnessLotteryDemo").abi, + functionName: "startLottery", + value: 1n * GLMR, + }); + log("Estimated Gas for startLottery", estimatedGas); + expect(estimatedGas).toMatchInlineSnapshot(`218380n`); + await context.writeContract!({ contractName: "RandomnessLotteryDemo", contractAddress: lotteryAddress, functionName: "startLottery", - gas: 500_000n, value: 1n * GLMR, + gas: estimatedGas, }); + await context.createBlock(); }); @@ -72,13 +84,36 @@ describeSuite({ id: "T02", title: "should succeed to fulfill after the delay", test: async function () { - await context.createBlock(); + // await context.createBlock(); + + await context.createBlock([ + // Faking relay epoch + 2 in randomness storage + fakeBabeResultTransaction(context), + ]); + + expect( + await context.readPrecompile!({ + precompileName: "Randomness", + functionName: "getRequestStatus", + args: [0], + }) + ).toBe(CONTRACT_RANDOMNESS_STATUS_READY); + + const estimatedGas = await context.viem().estimateContractGas({ + address: "0x0000000000000000000000000000000000000809", // Randomness contract address + abi: fetchCompiledContract("Randomness").abi, + functionName: "fulfillRequest", + args: [0], + account: BALTATHAR_ADDRESS, + }); + log("Estimated Gas for startLottery", estimatedGas); + expect(estimatedGas).toMatchInlineSnapshot(`687763n`); const rawTxn = await context.writePrecompile!({ precompileName: "Randomness", functionName: "fulfillRequest", args: [0], - gas: 500_000n, + gas: estimatedGas, rawTxOnly: true, privateKey: BALTATHAR_PRIVATE_KEY, }); 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 73a7cee258..78bbeb2ec6 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 @@ -1,5 +1,5 @@ import "@moonbeam-network/api-augment"; -import { beforeAll, describeSuite } from "@moonwall/cli"; +import { beforeAll, describeSuite, expect, fetchCompiledContract } from "@moonwall/cli"; import { GLMR } from "@moonwall/util"; import { expectEVMResult, setupLotteryWithParticipants } from "../../../../helpers"; @@ -12,13 +12,24 @@ describeSuite({ beforeAll(async function () { lotteryContract = await setupLotteryWithParticipants(context, "VRF"); + + const estimatedGas = await context.viem().estimateContractGas({ + address: lotteryContract, + abi: fetchCompiledContract("RandomnessLotteryDemo").abi, + functionName: "startLottery", + value: 1n * GLMR, + }); + log("Estimated Gas for startLottery", estimatedGas); + expect(estimatedGas).toMatchInlineSnapshot(`218380n`); + await context.writeContract!({ contractAddress: lotteryContract, contractName: "RandomnessLotteryDemo", functionName: "startLottery", value: 1n * GLMR, - gas: 300_000n, + gas: estimatedGas, }); + await context.createBlock(); }); @@ -27,12 +38,22 @@ describeSuite({ title: "should succeed to fulfill after the delay", test: async function () { await context.createBlock(); + await context.createBlock(); + + const estimatedGas = await context.viem().estimateContractGas({ + address: "0x0000000000000000000000000000000000000809", // Randomness contract address + abi: fetchCompiledContract("Randomness").abi, + functionName: "fulfillRequest", + args: [0], + }); + log("Estimated Gas for startLottery", estimatedGas); + expect(estimatedGas).toMatchInlineSnapshot(`677344n`); const rawTxn = await context.writePrecompile!({ precompileName: "Randomness", functionName: "fulfillRequest", args: [0], - gas: 500_000n, + gas: estimatedGas, rawTxOnly: true, }); const { result } = await context.createBlock(rawTxn);