Struct era_test_node::node::InMemoryNode
source · pub struct InMemoryNode<S> { /* private fields */ }
Expand description
In-memory node, that can be used for local & unit testing. It also supports the option of forking testnet/mainnet. All contents are removed when object is destroyed.
Implementations§
source§impl<S: ForkSource + Debug> InMemoryNode<S>
impl<S: ForkSource + Debug> InMemoryNode<S>
pub fn new( fork: Option<ForkDetails<S>>, show_calls: ShowCalls, show_storage_logs: ShowStorageLogs, show_vm_details: ShowVMDetails, show_gas_details: ShowGasDetails, resolve_hashes: bool, system_contracts_options: &Options ) -> Self
pub fn get_inner(&self) -> Arc<RwLock<InMemoryNodeInner<S>>>
sourcepub fn apply_txs(&self, txs: Vec<L2Tx>) -> Result<(), String>
pub fn apply_txs(&self, txs: Vec<L2Tx>) -> Result<(), String>
Applies multiple transactions - but still one per L1 batch.
sourcepub fn set_rich_account(&self, address: H160)
pub fn set_rich_account(&self, address: H160)
Adds a lot of tokens to a given account.
sourcepub fn run_l2_tx_inner(
&self,
l2_tx: L2Tx,
execution_mode: TxExecutionMode
) -> Result<(HashMap<StorageKey, H256>, VmExecutionResultAndLogs, Vec<Call>, Block<TransactionVariant>, HashMap<U256, Vec<U256>>, BlockContext), String>
pub fn run_l2_tx_inner( &self, l2_tx: L2Tx, execution_mode: TxExecutionMode ) -> Result<(HashMap<StorageKey, H256>, VmExecutionResultAndLogs, Vec<Call>, Block<TransactionVariant>, HashMap<U256, Vec<U256>>, BlockContext), String>
Executes the given L2 transaction and returns all the VM logs.
Trait Implementations§
source§impl<S: ForkSource + Debug> Default for InMemoryNode<S>
impl<S: ForkSource + Debug> Default for InMemoryNode<S>
source§impl<S: Send + Sync + 'static + ForkSource + Debug> EthNamespaceT for InMemoryNode<S>
impl<S: Send + Sync + 'static + ForkSource + Debug> EthNamespaceT for InMemoryNode<S>
source§fn call(
&self,
req: CallRequest,
_block: Option<BlockIdVariant>
) -> BoxFuture<Result<Bytes>>
fn call( &self, req: CallRequest, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<Bytes>>
source§fn get_balance(
&self,
address: Address,
_block: Option<BlockIdVariant>
) -> BoxFuture<Result<U256, Error>>
fn get_balance( &self, address: Address, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<U256, Error>>
source§fn get_block_by_number(
&self,
block_number: BlockNumber,
full_transactions: bool
) -> BoxFuture<Result<Option<Block<TransactionVariant>>>>
fn get_block_by_number( &self, block_number: BlockNumber, full_transactions: bool ) -> BoxFuture<Result<Option<Block<TransactionVariant>>>>
Returns a block by its number.
Arguments
block_number
- ABlockNumber
enum variant representing the block number to retrieve.full_transactions
- A boolean value indicating whether to retrieve full transactions or not.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an Option
of zksync_types::api::Block<zksync_types::api::TransactionVariant>
.
source§fn get_code(
&self,
address: Address,
_block: Option<BlockIdVariant>
) -> BoxFuture<Result<Bytes>>
fn get_code( &self, address: Address, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<Bytes>>
source§fn get_transaction_count(
&self,
address: Address,
_block: Option<BlockIdVariant>
) -> BoxFuture<Result<U256>>
fn get_transaction_count( &self, address: Address, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<U256>>
source§fn get_transaction_receipt(
&self,
hash: H256
) -> BoxFuture<Result<Option<TransactionReceipt>>>
fn get_transaction_receipt( &self, hash: H256 ) -> BoxFuture<Result<Option<TransactionReceipt>>>
source§fn send_raw_transaction(&self, tx_bytes: Bytes) -> BoxFuture<Result<H256>>
fn send_raw_transaction(&self, tx_bytes: Bytes) -> BoxFuture<Result<H256>>
source§fn get_block_by_hash(
&self,
hash: H256,
full_transactions: bool
) -> BoxFuture<Result<Option<Block<TransactionVariant>>>>
fn get_block_by_hash( &self, hash: H256, full_transactions: bool ) -> BoxFuture<Result<Option<Block<TransactionVariant>>>>
Returns a block by its hash. Currently, only hashes for blocks in memory are supported.
Arguments
hash
- AH256
type representing the hash of the block to retrieve.full_transactions
- A boolean value indicating whether to retrieve full transactions or not.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an Option
of zksync_types::api::Block<zksync_types::api::TransactionVariant>
.
source§fn get_transaction_by_hash(
&self,
hash: H256
) -> BoxFuture<Result<Option<Transaction>>>
fn get_transaction_by_hash( &self, hash: H256 ) -> BoxFuture<Result<Option<Transaction>>>
source§fn get_block_number(&self) -> BoxFuture<Result<U64>>
fn get_block_number(&self) -> BoxFuture<Result<U64>>
Returns the current block number as a U64
wrapped in a BoxFuture
.
source§fn estimate_gas(
&self,
req: CallRequest,
_block: Option<BlockNumber>
) -> BoxFuture<Result<U256>>
fn estimate_gas( &self, req: CallRequest, _block: Option<BlockNumber> ) -> BoxFuture<Result<U256>>
Estimates the gas required for a given call request.
Arguments
req
- ACallRequest
struct representing the call request to estimate gas for._block
- An optionalBlockNumber
struct representing the block number to estimate gas for.
Returns
A BoxFuture
containing a Result
with a U256
representing the estimated gas required.
source§fn new_filter(&self, filter: Filter) -> BoxFuture<Result<U256>>
fn new_filter(&self, filter: Filter) -> BoxFuture<Result<U256>>
Creates a filter object, based on filter options, to notify when the state changes (logs).
To check if the state has changed, call eth_getFilterChanges
.
Arguments
filter
: The filter options - fromBlock: - Integer block number, or the string “latest”, “earliest” or “pending”. toBlock: - Integer block number, or the string “latest”, “earliest” or “pending”. address: - Contract address or a list of addresses from which the logs should originate. topics: - [H256] topics. Topics are order-dependent. Each topic can also be an array with “or” options.
If the from fromBlock
or toBlock
option are equal to “latest” the filter continually appends logs for newly mined blocks.
Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters:
* [] “anything”
* [A] “A in first position (and anything after)”
* [null, B] “anything in first position AND B in second position (and anything after)”
* [A, B] “A in first position AND B in second position (and anything after)”
* [[A, B], [A, B]] “(A OR B) in first position AND (A OR B) in second position (and anything after)”
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an U256
filter id.
source§fn new_block_filter(&self) -> BoxFuture<Result<U256>>
fn new_block_filter(&self) -> BoxFuture<Result<U256>>
Creates a filter in the node, to notify when a new block arrives.
To check if the state has changed, call eth_getFilterChanges
.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an U256
filter id.
source§fn new_pending_transaction_filter(&self) -> BoxFuture<Result<U256>>
fn new_pending_transaction_filter(&self) -> BoxFuture<Result<U256>>
Creates a filter in the node, to notify when new pending transactions arrive.
To check if the state has changed, call eth_getFilterChanges
.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an U256
filter id.
source§fn uninstall_filter(&self, id: U256) -> BoxFuture<Result<bool>>
fn uninstall_filter(&self, id: U256) -> BoxFuture<Result<bool>>
source§fn get_logs(&self, filter: Filter) -> BoxFuture<Result<Vec<Log>>>
fn get_logs(&self, filter: Filter) -> BoxFuture<Result<Vec<Log>>>
Returns an array of all logs matching a given filter.
Arguments
filter
: The filter options - fromBlock - Integer block number, or the string “latest”, “earliest” or “pending”. toBlock - Integer block number, or the string “latest”, “earliest” or “pending”. address - Contract address or a list of addresses from which the logs should originate. topics - [H256] topics. Topics are order-dependent. Each topic can also be an array with “or” options. Seenew_filter
documention for how to specify topics.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an array of logs.
source§fn get_filter_logs(&self, id: U256) -> BoxFuture<Result<FilterChanges>>
fn get_filter_logs(&self, id: U256) -> BoxFuture<Result<FilterChanges>>
source§fn get_filter_changes(&self, id: U256) -> BoxFuture<Result<FilterChanges>>
fn get_filter_changes(&self, id: U256) -> BoxFuture<Result<FilterChanges>>
Polling method for a filter, which returns an array of logs, block hashes, or transaction hashes, depending on the filter type, which occurred since last poll.
Arguments
id
: The filter id
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to an array of logs, block hashes, or transaction hashes,
depending on the filter type, which occurred since last poll.
- Filters created with
eth_newFilter
return [Log] objects. - Filters created with
eth_newBlockFilter
return block hashes. - Filters created with
eth_newPendingTransactionFilter
return transaction hashes.
source§fn get_storage(
&self,
address: Address,
idx: U256,
block: Option<BlockIdVariant>
) -> BoxFuture<Result<H256>>
fn get_storage( &self, address: Address, idx: U256, block: Option<BlockIdVariant> ) -> BoxFuture<Result<H256>>
source§fn get_transaction_by_block_hash_and_index(
&self,
block_hash: H256,
index: Index
) -> BoxFuture<Result<Option<Transaction>>>
fn get_transaction_by_block_hash_and_index( &self, block_hash: H256, index: Index ) -> BoxFuture<Result<Option<Transaction>>>
source§fn get_transaction_by_block_number_and_index(
&self,
block_number: BlockNumber,
index: Index
) -> BoxFuture<Result<Option<Transaction>>>
fn get_transaction_by_block_number_and_index( &self, block_number: BlockNumber, index: Index ) -> BoxFuture<Result<Option<Transaction>>>
Returns information about a transaction by block number and transaction index position.
Arguments
block_number
: A block number, or the string “earliest”, “latest” or “pending”.index
: Integer of the transaction index position
Returns
A BoxFuture
containing a jsonrpc_core::Result
that maybe resolves to a [zksync_types::api::Transaction], if found.
source§fn protocol_version(&self) -> BoxFuture<Result<String>>
fn protocol_version(&self) -> BoxFuture<Result<String>>
Returns the protocol version.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to a hex String
of the version number.
source§fn accounts(&self) -> BoxFuture<Result<Vec<H160>>>
fn accounts(&self) -> BoxFuture<Result<Vec<H160>>>
Returns a list of available accounts.
This function fetches the accounts from the inner state, and returns them as a list of addresses (H160
).
Errors
Returns a jsonrpc_core::Result
error if acquiring a write lock on the inner state fails.
Returns
A BoxFuture
containing a jsonrpc_core::Result
that resolves to a Vec<H160>
of addresses.
source§fn fee_history(
&self,
block_count: U64,
_newest_block: BlockNumber,
reward_percentiles: Vec<f32>
) -> BoxFuture<Result<FeeHistory>>
fn fee_history( &self, block_count: U64, _newest_block: BlockNumber, reward_percentiles: Vec<f32> ) -> BoxFuture<Result<FeeHistory>>
Returns the fee history for a given range of blocks.
Note: This implementation is limited to using the hard-coded value of L2_GAS_PRICE as the history gas price
Arguments
block_count
- The number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query. It will return less than the requested range if not all blocks are available.newest_block
- The highest number block of the requested range. As this implementation is using hard-coded values, this argument is ignored.reward_percentiles
- A list of percentile values with a monotonic increase in value.
Returns
A BoxFuture
containing a Result
with a FeeHistory
representing the fee history of the specified range of blocks.
fn get_block_transaction_count_by_number( &self, block_number: BlockNumber ) -> BoxFuture<Result<Option<U256>>>
fn get_block_transaction_count_by_hash( &self, block_hash: H256 ) -> BoxFuture<Result<Option<U256>>>
fn syncing(&self) -> BoxFuture<Result<SyncState>>
fn coinbase(&self) -> BoxFuture<Result<Address>>
fn compilers(&self) -> BoxFuture<Result<Vec<String>>>
fn hashrate(&self) -> BoxFuture<Result<U256>>
fn get_uncle_count_by_block_hash( &self, _hash: H256 ) -> BoxFuture<Result<Option<U256>>>
fn get_uncle_count_by_block_number( &self, _number: BlockNumber ) -> BoxFuture<Result<Option<U256>>>
fn mining(&self) -> BoxFuture<Result<bool>>
§fn to_delegate<M>(self) -> IoDelegate<Self, M>where
M: Metadata,
fn to_delegate<M>(self) -> IoDelegate<Self, M>where M: Metadata,
IoDelegate
, wiring rpc calls to the trait methods.