Skip to content

Commit

Permalink
Enable eth_call state override (#2219)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec authored Apr 12, 2023
1 parent 6772b27 commit 7776790
Show file tree
Hide file tree
Showing 5 changed files with 5,401 additions and 23 deletions.
47 changes: 26 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions node/service/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use sc_rpc_api::DenyUnsafe;
use sc_service::TaskManager;
use sc_transaction_pool::{ChainApi, Pool};
use sc_transaction_pool_api::TransactionPool;
use sp_api::{HeaderT, ProvideRuntimeApi};
use sp_api::{CallApiAt, HeaderT, ProvideRuntimeApi};
use sp_blockchain::{
Backend as BlockchainBackend, Error as BlockChainError, HeaderBackend, HeaderMetadata,
};
Expand Down Expand Up @@ -78,6 +78,18 @@ impl fc_rpc::EstimateGasAdapter for MoonbeamEGA {
}
}

pub struct MoonbeamEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);

impl<C, BE> fc_rpc::EthConfig<Block, C> for MoonbeamEthConfig<C, BE>
where
C: sc_client_api::StorageProvider<Block, BE> + Sync + Send + 'static,
BE: Backend<Block> + 'static,
{
type EstimateGasAdapter = MoonbeamEGA;
type RuntimeStorageOverride =
fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<Block, C, BE>;
}

/// Full client dependencies.
pub struct FullDeps<C, P, A: ChainApi, BE> {
/// The client instance to use.
Expand Down Expand Up @@ -162,6 +174,7 @@ where
C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,
C: BlockchainEvents<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: CallApiAt<Block>,
C: Send + Sync + 'static,
A: ChainApi<Block = Block> + 'static,
C::Api: RuntimeApiCollection<StateBackend = BE::State>,
Expand Down Expand Up @@ -233,7 +246,7 @@ where
fee_history_limit,
10,
)
.with_estimate_gas_adapter::<MoonbeamEGA>()
.replace_config::<MoonbeamEthConfig<C, BE>>()
.into_rpc(),
)?;

Expand Down
5,066 changes: 5,066 additions & 0 deletions tests/contracts/compiled/StateOverrideTest.json

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions tests/contracts/solidity/StateOverrideTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Smart contract to help test state override
contract StateOverrideTest {
/// @notice The maxmium allowed value
uint256 public MAX_ALLOWED = 3;
uint256 public availableFunds;
mapping(address => mapping(address => uint256)) public allowance;

address owner;

constructor(uint256 intialAmount) payable {
owner = msg.sender;
availableFunds = intialAmount;
}

function getBalance() external view returns (uint256) {
return address(this).balance;
}

function getSenderBalance() external view returns (uint256) {
return address(msg.sender).balance;
}

function getAllowance(address from, address who)
external
view
returns (uint256)
{
return allowance[from][who];
}

function setAllowance(address who, uint256 amount) external {
allowance[address(msg.sender)][who] = amount;
}
}
Loading

0 comments on commit 7776790

Please sign in to comment.