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>

source

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

source

pub fn get_inner(&self) -> Arc<RwLock<InMemoryNodeInner<S>>>

source

pub fn apply_txs(&self, txs: Vec<L2Tx>) -> Result<(), String>

Applies multiple transactions - but still one per L1 batch.

source

pub fn set_rich_account(&self, address: H160)

Adds a lot of tokens to a given account.

source

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>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<S: Send + Sync + 'static + ForkSource + Debug> EthNamespaceT for InMemoryNode<S>

source§

fn chain_id(&self) -> BoxFuture<Result<U64>>

Returns the chain ID of the node.

source§

fn call( &self, req: CallRequest, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<Bytes>>

Calls the specified function on the L2 contract with the given arguments.

Arguments
  • req - The call request containing the function name and arguments.
  • _block - The block ID variant (unused).
Returns

A boxed future containing the result of the function call.

source§

fn get_balance( &self, address: Address, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<U256, Error>>

Returns the balance of the specified address.

Arguments
  • address - The address to get the balance of.
  • _block - The block ID variant (optional).
Returns

A BoxFuture that resolves to a Result containing the balance of the specified address as a U256 or a jsonrpc_core::Error if an error occurred.

source§

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 - A BlockNumber 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>>

Returns the code stored at the specified address.

Arguments
  • address - The address to retrieve the code from.
  • _block - An optional block ID variant.
Returns

A BoxFuture containing the result of the operation, which is a jsonrpc_core::Result containing the code as a zksync_basic_types::Bytes object.

source§

fn get_transaction_count( &self, address: Address, _block: Option<BlockIdVariant> ) -> BoxFuture<Result<U256>>

Returns the transaction count for a given address.

Arguments
  • address - The address to get the transaction count for.
  • _block - Optional block ID variant.
Returns

Returns a BoxFuture containing the transaction count as a U256 wrapped in a jsonrpc_core::Result.

source§

fn get_transaction_receipt( &self, hash: H256 ) -> BoxFuture<Result<Option<TransactionReceipt>>>

Retrieves the transaction receipt for a given transaction hash.

Arguments
  • hash - The hash of the transaction to retrieve the receipt for.
Returns

A BoxFuture that resolves to an Option of a TransactionReceipt or an error.

source§

fn send_raw_transaction(&self, tx_bytes: Bytes) -> BoxFuture<Result<H256>>

Sends a raw transaction to the L2 network.

Arguments
  • tx_bytes - The transaction bytes to send.
Returns

A future that resolves to the hash of the transaction if successful, or an error if the transaction is invalid or execution fails.

source§

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 - A H256 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>>>

Returns a future that resolves to an optional transaction with the given hash.

Arguments
  • hash - A 32-byte hash of the transaction.
Returns

A jsonrpc_core::BoxFuture that resolves to a jsonrpc_core::Result containing an optional zksync_types::api::Transaction.

source§

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>>

Estimates the gas required for a given call request.

Arguments
  • req - A CallRequest struct representing the call request to estimate gas for.
  • _block - An optional BlockNumber 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 gas_price(&self) -> BoxFuture<Result<U256>>

Returns the current gas price in U256 format.

source§

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>>

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>>

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>>

Uninstalls a filter with given id. Should always be called when watch is no longer needed.

Arguments
  • id: The filter id
Returns

A BoxFuture containing a jsonrpc_core::Result that resolves to an U256 filter id.

source§

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. See new_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>>

Returns an array of all logs matching filter with given id.

Arguments
  • id: The filter id
Returns

A BoxFuture containing a jsonrpc_core::Result that resolves to an array of logs.

source§

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>>

Returns the value from a storage position at a given address.

Arguments
  • address: Address of the storage
  • idx: Integer of the position in the storage
  • block: The block storage to target
Returns

A BoxFuture containing a jsonrpc_core::Result that resolves to a [H256] value in the storage.

source§

fn get_transaction_by_block_hash_and_index( &self, block_hash: H256, index: Index ) -> BoxFuture<Result<Option<Transaction>>>

Returns information about a transaction by block hash and transaction index position.

Arguments
  • block_hash: Hash of a block
  • 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 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>>

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>>>

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>>

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.

source§

fn get_block_transaction_count_by_number( &self, block_number: BlockNumber ) -> BoxFuture<Result<Option<U256>>>

source§

fn get_block_transaction_count_by_hash( &self, block_hash: H256 ) -> BoxFuture<Result<Option<U256>>>

source§

fn syncing(&self) -> BoxFuture<Result<SyncState>>

source§

fn coinbase(&self) -> BoxFuture<Result<Address>>

source§

fn compilers(&self) -> BoxFuture<Result<Vec<String>>>

source§

fn hashrate(&self) -> BoxFuture<Result<U256>>

source§

fn get_uncle_count_by_block_hash( &self, _hash: H256 ) -> BoxFuture<Result<Option<U256>>>

source§

fn get_uncle_count_by_block_number( &self, _number: BlockNumber ) -> BoxFuture<Result<Option<U256>>>

source§

fn mining(&self) -> BoxFuture<Result<bool>>

§

fn to_delegate<M>(self) -> IoDelegate<Self, M>where M: Metadata,

Create an IoDelegate, wiring rpc calls to the trait methods.

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for InMemoryNode<S>

§

impl<S> Send for InMemoryNode<S>where S: Send + Sync,

§

impl<S> Sync for InMemoryNode<S>where S: Send + Sync,

§

impl<S> Unpin for InMemoryNode<S>

§

impl<S> UnwindSafe for InMemoryNode<S>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for Twhere T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeSend for Twhere T: Send,