-
Notifications
You must be signed in to change notification settings - Fork 69
internal/ethapi: eth_simulateV1 #27720 #1606
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
Conversation
|
Used test contracts and commands Test Contract// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title Comprehensive Simulation Test Contract
/// @notice Designed for testing eth_simulateV1 behavior on various scenarios.
contract SimulateTest {
uint256 public counter;
mapping(address => uint256) public balances;
event Updated(address indexed user, uint256 newValue);
event Deposited(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event HeavyLoopExecuted(uint256 iterations);
/// @notice Scenario 1: Normal successful execution
function increment(uint256 value) public {
counter += value;
emit Updated(msg.sender, counter);
}
/// @notice Scenario 2: Revert with reason
function forceRevert() public pure {
require(false, "Manual revert triggered");
}
/// @notice Scenario 3: Gas heavy function for gas limit testing
function heavyComputation(uint256 loops) public {
uint256 sum = 0;
for (uint256 i = 0; i < loops; i++) {
sum += i;
}
emit HeavyLoopExecuted(loops);
}
/// @notice Simple deposit to test state writes and overrides
function deposit() public payable {
balances[msg.sender] += msg.value;
emit Deposited(msg.sender, msg.value);
}
/// @notice Withdraw to test state reads and conditional revert
function withdraw(uint256 amount) public {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
emit Withdrawn(msg.sender, amount);
}
/// @notice Helper: returns current balance of sender
function getMyBalance() public view returns (uint256) {
return balances[msg.sender];
}
/// @notice Helper: resets state (for dev/local tests only)
function reset() public {
counter = 0;
balances[msg.sender] = 0;
}
}
1. Normal ExecutionRequest Command curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_simulateV1",
"params": [
{
"blockStateCalls": [
{
"blockOverrides": {
"baseFeePerGas": "0x9"
},
"stateOverrides": {
"0x873C36f9Fd02e0C57a393aFE80D14f244fE04378": {
"balance": "0x4a817c800"
}
},
"calls": [
{
"from": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",
"to": "0xD3Ff9f036BC01A3c7F59213C254B9b9bb5187Eb2",
"data": "0x7cf5dab00000000000000000000000000000000000000000000000000000000000000001",
"maxFeePerGas": "0xf"
}
]
}
],
"validation": true,
"traceTransfers": true
},
"latest"
],
"id": 1
}' | jq2. Revert
curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_simulateV1",
"params": [
{
"blockStateCalls": [
{
"blockOverrides": { "baseFeePerGas": "0x9" },
"stateOverrides": {
"0x873C36f9Fd02e0C57a393aFE80D14f244fE04378": { "balance": "0x4a817c800" }
},
"calls": [
{
"from": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",
"to": "0xD3Ff9f036BC01A3c7F59213C254B9b9bb5187Eb2",
"data": "0x11cf11ae",
"maxFeePerGas": "0xf"
}
]
}
],
"validation": true,
"traceTransfers": true
},
"latest"
],
"id": 2
}' | jq3. Gas Limit Exceeded
curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_simulateV1",
"params": [
{
"blockStateCalls": [
{
"calls": [
{
"from": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",
"to": "0xD3Ff9f036BC01A3c7F59213C254B9b9bb5187Eb2",
"gasLimit": "0x2710",
"data": "0x69d4622b00000000000000000000000000000000000000000000000000000000000f4240"
}
]
}
]
},
"latest"
],
"id": 3
}' | jq
4. No
|
Proposed changes
Ref: ethereum#27720
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that