use crate::{eth::subscription::SubscriptionId, types::ReorgOptions};
use alloy_primitives::{Address, Bytes, TxHash, B256, B64, U256};
use alloy_rpc_types::{
anvil::{Forking, MineOptions},
pubsub::{Params as SubscriptionParams, SubscriptionKind},
request::TransactionRequest,
state::StateOverride,
trace::{
filter::TraceFilter,
geth::{GethDebugTracingCallOptions, GethDebugTracingOptions},
},
BlockId, BlockNumberOrTag as BlockNumber, Filter, Index,
};
use alloy_serde::WithOtherFields;
pub mod block;
pub mod proof;
pub mod subscription;
pub mod transaction;
pub mod trie;
pub mod wallet;
#[cfg(feature = "serde")]
pub mod serde_helpers;
#[cfg(feature = "serde")]
use self::serde_helpers::*;
#[cfg(feature = "serde")]
use foundry_common::serde_helpers::{
deserialize_number, deserialize_number_opt, deserialize_number_seq,
};
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct Params<T: Default> {
#[cfg_attr(feature = "serde", serde(default))]
pub params: T,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "method", content = "params"))]
pub enum EthRequest {
#[cfg_attr(feature = "serde", serde(rename = "web3_clientVersion", with = "empty_params"))]
Web3ClientVersion(()),
#[cfg_attr(feature = "serde", serde(rename = "web3_sha3", with = "sequence"))]
Web3Sha3(Bytes),
#[cfg_attr(feature = "serde", serde(rename = "eth_chainId", with = "empty_params"))]
EthChainId(()),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_networkId", alias = "net_version", with = "empty_params")
)]
EthNetworkId(()),
#[cfg_attr(feature = "serde", serde(rename = "net_listening", with = "empty_params"))]
NetListening(()),
#[cfg_attr(feature = "serde", serde(rename = "eth_gasPrice", with = "empty_params"))]
EthGasPrice(()),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_maxPriorityFeePerGas", with = "empty_params")
)]
EthMaxPriorityFeePerGas(()),
#[cfg_attr(feature = "serde", serde(rename = "eth_blobBaseFee", with = "empty_params"))]
EthBlobBaseFee(()),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_accounts", alias = "eth_requestAccounts", with = "empty_params")
)]
EthAccounts(()),
#[cfg_attr(feature = "serde", serde(rename = "eth_blockNumber", with = "empty_params"))]
EthBlockNumber(()),
#[cfg_attr(feature = "serde", serde(rename = "eth_getBalance"))]
EthGetBalance(Address, Option<BlockId>),
#[cfg_attr(feature = "serde", serde(rename = "eth_getAccount"))]
EthGetAccount(Address, Option<BlockId>),
#[cfg_attr(feature = "serde", serde(rename = "eth_getStorageAt"))]
EthGetStorageAt(Address, U256, Option<BlockId>),
#[cfg_attr(feature = "serde", serde(rename = "eth_getBlockByHash"))]
EthGetBlockByHash(B256, bool),
#[cfg_attr(feature = "serde", serde(rename = "eth_getBlockByNumber"))]
EthGetBlockByNumber(
#[cfg_attr(
feature = "serde",
serde(deserialize_with = "lenient_block_number::lenient_block_number")
)]
BlockNumber,
bool,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionCount"))]
EthGetTransactionCount(Address, Option<BlockId>),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_getBlockTransactionCountByHash", with = "sequence")
)]
EthGetTransactionCountByHash(B256),
#[cfg_attr(
feature = "serde",
serde(
rename = "eth_getBlockTransactionCountByNumber",
deserialize_with = "lenient_block_number::lenient_block_number_seq"
)
)]
EthGetTransactionCountByNumber(BlockNumber),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_getUncleCountByBlockHash", with = "sequence")
)]
EthGetUnclesCountByHash(B256),
#[cfg_attr(
feature = "serde",
serde(
rename = "eth_getUncleCountByBlockNumber",
deserialize_with = "lenient_block_number::lenient_block_number_seq"
)
)]
EthGetUnclesCountByNumber(BlockNumber),
#[cfg_attr(feature = "serde", serde(rename = "eth_getCode"))]
EthGetCodeAt(Address, Option<BlockId>),
#[cfg_attr(feature = "serde", serde(rename = "eth_getProof"))]
EthGetProof(Address, Vec<B256>, Option<BlockId>),
#[cfg_attr(feature = "serde", serde(rename = "eth_sign"))]
EthSign(Address, Bytes),
#[cfg_attr(feature = "serde", serde(rename = "personal_sign"))]
PersonalSign(Bytes, Address),
#[cfg_attr(feature = "serde", serde(rename = "eth_signTransaction", with = "sequence"))]
EthSignTransaction(Box<WithOtherFields<TransactionRequest>>),
#[cfg_attr(feature = "serde", serde(rename = "eth_signTypedData"))]
EthSignTypedData(Address, serde_json::Value),
#[cfg_attr(feature = "serde", serde(rename = "eth_signTypedData_v3"))]
EthSignTypedDataV3(Address, serde_json::Value),
#[cfg_attr(feature = "serde", serde(rename = "eth_signTypedData_v4"))]
EthSignTypedDataV4(Address, alloy_dyn_abi::TypedData),
#[cfg_attr(feature = "serde", serde(rename = "eth_sendTransaction", with = "sequence"))]
EthSendTransaction(Box<WithOtherFields<TransactionRequest>>),
#[cfg_attr(feature = "serde", serde(rename = "eth_sendRawTransaction", with = "sequence"))]
EthSendRawTransaction(Bytes),
#[cfg_attr(feature = "serde", serde(rename = "eth_call"))]
EthCall(
WithOtherFields<TransactionRequest>,
#[cfg_attr(feature = "serde", serde(default))] Option<BlockId>,
#[cfg_attr(feature = "serde", serde(default))] Option<StateOverride>,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_createAccessList"))]
EthCreateAccessList(
WithOtherFields<TransactionRequest>,
#[cfg_attr(feature = "serde", serde(default))] Option<BlockId>,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_estimateGas"))]
EthEstimateGas(
WithOtherFields<TransactionRequest>,
#[cfg_attr(feature = "serde", serde(default))] Option<BlockId>,
#[cfg_attr(feature = "serde", serde(default))] Option<StateOverride>,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionByHash", with = "sequence"))]
EthGetTransactionByHash(TxHash),
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionByBlockHashAndIndex"))]
EthGetTransactionByBlockHashAndIndex(TxHash, Index),
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionByBlockNumberAndIndex"))]
EthGetTransactionByBlockNumberAndIndex(BlockNumber, Index),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_getRawTransactionByHash", with = "sequence")
)]
EthGetRawTransactionByHash(TxHash),
#[cfg_attr(feature = "serde", serde(rename = "eth_getRawTransactionByBlockHashAndIndex"))]
EthGetRawTransactionByBlockHashAndIndex(TxHash, Index),
#[cfg_attr(feature = "serde", serde(rename = "eth_getRawTransactionByBlockNumberAndIndex"))]
EthGetRawTransactionByBlockNumberAndIndex(BlockNumber, Index),
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionReceipt", with = "sequence"))]
EthGetTransactionReceipt(B256),
#[cfg_attr(feature = "serde", serde(rename = "eth_getBlockReceipts", with = "sequence"))]
EthGetBlockReceipts(BlockId),
#[cfg_attr(feature = "serde", serde(rename = "eth_getUncleByBlockHashAndIndex"))]
EthGetUncleByBlockHashAndIndex(B256, Index),
#[cfg_attr(feature = "serde", serde(rename = "eth_getUncleByBlockNumberAndIndex"))]
EthGetUncleByBlockNumberAndIndex(
#[cfg_attr(
feature = "serde",
serde(deserialize_with = "lenient_block_number::lenient_block_number")
)]
BlockNumber,
Index,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_getLogs", with = "sequence"))]
EthGetLogs(Filter),
#[cfg_attr(feature = "serde", serde(rename = "eth_newFilter", with = "sequence"))]
EthNewFilter(Filter),
#[cfg_attr(feature = "serde", serde(rename = "eth_getFilterChanges", with = "sequence"))]
EthGetFilterChanges(String),
#[cfg_attr(feature = "serde", serde(rename = "eth_newBlockFilter", with = "empty_params"))]
EthNewBlockFilter(()),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_newPendingTransactionFilter", with = "empty_params")
)]
EthNewPendingTransactionFilter(()),
#[cfg_attr(feature = "serde", serde(rename = "eth_getFilterLogs", with = "sequence"))]
EthGetFilterLogs(String),
#[cfg_attr(feature = "serde", serde(rename = "eth_uninstallFilter", with = "sequence"))]
EthUninstallFilter(String),
#[cfg_attr(feature = "serde", serde(rename = "eth_getWork", with = "empty_params"))]
EthGetWork(()),
#[cfg_attr(feature = "serde", serde(rename = "eth_submitWork"))]
EthSubmitWork(B64, B256, B256),
#[cfg_attr(feature = "serde", serde(rename = "eth_submitHashrate"))]
EthSubmitHashRate(U256, B256),
#[cfg_attr(feature = "serde", serde(rename = "eth_feeHistory"))]
EthFeeHistory(
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_number"))] U256,
BlockNumber,
#[cfg_attr(feature = "serde", serde(default))] Vec<f64>,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_syncing", with = "empty_params"))]
EthSyncing(()),
#[cfg_attr(feature = "serde", serde(rename = "debug_getRawTransaction", with = "sequence"))]
DebugGetRawTransaction(TxHash),
#[cfg_attr(feature = "serde", serde(rename = "debug_traceTransaction"))]
DebugTraceTransaction(
B256,
#[cfg_attr(feature = "serde", serde(default))] GethDebugTracingOptions,
),
#[cfg_attr(feature = "serde", serde(rename = "debug_traceCall"))]
DebugTraceCall(
WithOtherFields<TransactionRequest>,
#[cfg_attr(feature = "serde", serde(default))] Option<BlockId>,
#[cfg_attr(feature = "serde", serde(default))] GethDebugTracingCallOptions,
),
#[cfg_attr(feature = "serde", serde(rename = "trace_transaction", with = "sequence"))]
TraceTransaction(B256),
#[cfg_attr(
feature = "serde",
serde(
rename = "trace_block",
deserialize_with = "lenient_block_number::lenient_block_number_seq"
)
)]
TraceBlock(BlockNumber),
#[cfg_attr(feature = "serde", serde(rename = "trace_filter",))]
TraceFilter(TraceFilter),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_impersonateAccount",
alias = "hardhat_impersonateAccount",
with = "sequence"
)
)]
ImpersonateAccount(Address),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_stopImpersonatingAccount",
alias = "hardhat_stopImpersonatingAccount",
with = "sequence"
)
)]
StopImpersonatingAccount(Address),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_autoImpersonateAccount",
alias = "hardhat_autoImpersonateAccount",
with = "sequence"
)
)]
AutoImpersonateAccount(bool),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_getAutomine", alias = "hardhat_getAutomine", with = "empty_params")
)]
GetAutoMine(()),
#[cfg_attr(feature = "serde", serde(rename = "anvil_mine", alias = "hardhat_mine"))]
Mine(
#[cfg_attr(feature = "serde", serde(default, deserialize_with = "deserialize_number_opt"))]
Option<U256>,
#[cfg_attr(feature = "serde", serde(default, deserialize_with = "deserialize_number_opt"))]
Option<U256>,
),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_setAutomine", alias = "evm_setAutomine", with = "sequence")
)]
SetAutomine(bool),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setIntervalMining",
alias = "evm_setIntervalMining",
with = "sequence"
)
)]
SetIntervalMining(u64),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_getIntervalMining", with = "empty_params")
)]
GetIntervalMining(()),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_dropTransaction",
alias = "hardhat_dropTransaction",
with = "sequence"
)
)]
DropTransaction(B256),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_dropAllTransactions",
alias = "hardhat_dropAllTransactions",
with = "empty_params"
)
)]
DropAllTransactions(),
#[cfg_attr(feature = "serde", serde(rename = "anvil_reset", alias = "hardhat_reset"))]
Reset(#[cfg_attr(feature = "serde", serde(default))] Option<Params<Option<Forking>>>),
#[cfg_attr(feature = "serde", serde(rename = "anvil_setRpcUrl", with = "sequence"))]
SetRpcUrl(String),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_setBalance", alias = "hardhat_setBalance")
)]
SetBalance(
Address,
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_number"))] U256,
),
#[cfg_attr(feature = "serde", serde(rename = "anvil_setCode", alias = "hardhat_setCode"))]
SetCode(Address, Bytes),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setNonce",
alias = "hardhat_setNonce",
alias = "evm_setAccountNonce"
)
)]
SetNonce(
Address,
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_number"))] U256,
),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_setStorageAt", alias = "hardhat_setStorageAt")
)]
SetStorageAt(
Address,
U256,
B256,
),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_setCoinbase", alias = "hardhat_setCoinbase", with = "sequence")
)]
SetCoinbase(Address),
#[cfg_attr(feature = "serde", serde(rename = "anvil_setChainId", with = "sequence"))]
SetChainId(u64),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setLoggingEnabled",
alias = "hardhat_setLoggingEnabled",
with = "sequence"
)
)]
SetLogging(bool),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setMinGasPrice",
alias = "hardhat_setMinGasPrice",
deserialize_with = "deserialize_number_seq"
)
)]
SetMinGasPrice(U256),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setNextBlockBaseFeePerGas",
alias = "hardhat_setNextBlockBaseFeePerGas",
deserialize_with = "deserialize_number_seq"
)
)]
SetNextBlockBaseFeePerGas(U256),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setTime",
alias = "evm_setTime",
deserialize_with = "deserialize_number_seq"
)
)]
EvmSetTime(U256),
#[cfg_attr(feature = "serde", serde(rename = "anvil_dumpState", alias = "hardhat_dumpState"))]
DumpState(#[cfg_attr(feature = "serde", serde(default))] Option<Params<Option<bool>>>),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_loadState", alias = "hardhat_loadState", with = "sequence")
)]
LoadState(Bytes),
#[cfg_attr(feature = "serde", serde(rename = "anvil_nodeInfo", with = "empty_params"))]
NodeInfo(()),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_metadata", alias = "hardhat_metadata", with = "empty_params")
)]
AnvilMetadata(()),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_snapshot", alias = "evm_snapshot", with = "empty_params")
)]
EvmSnapshot(()),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_revert",
alias = "evm_revert",
deserialize_with = "deserialize_number_seq"
)
)]
EvmRevert(U256),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_increaseTime",
alias = "evm_increaseTime",
deserialize_with = "deserialize_number_seq"
)
)]
EvmIncreaseTime(U256),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setNextBlockTimestamp",
alias = "evm_setNextBlockTimestamp",
deserialize_with = "deserialize_number_seq"
)
)]
EvmSetNextBlockTimeStamp(U256),
#[cfg_attr(
feature = "serde",
serde(
rename = "anvil_setBlockGasLimit",
alias = "evm_setBlockGasLimit",
deserialize_with = "deserialize_number_seq"
)
)]
EvmSetBlockGasLimit(U256),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_setBlockTimestampInterval", with = "sequence")
)]
EvmSetBlockTimeStampInterval(u64),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_removeBlockTimestampInterval", with = "empty_params")
)]
EvmRemoveBlockTimeStampInterval(()),
#[cfg_attr(feature = "serde", serde(rename = "evm_mine"))]
EvmMine(#[cfg_attr(feature = "serde", serde(default))] Option<Params<Option<MineOptions>>>),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_mine_detailed", alias = "evm_mine_detailed",)
)]
EvmMineDetailed(
#[cfg_attr(feature = "serde", serde(default))] Option<Params<Option<MineOptions>>>,
),
#[cfg_attr(
feature = "serde",
serde(rename = "eth_sendUnsignedTransaction", with = "sequence")
)]
EthSendUnsignedTransaction(Box<WithOtherFields<TransactionRequest>>),
#[cfg_attr(feature = "serde", serde(rename = "anvil_enableTraces", with = "empty_params"))]
EnableTraces(()),
#[cfg_attr(feature = "serde", serde(rename = "txpool_status", with = "empty_params"))]
TxPoolStatus(()),
#[cfg_attr(feature = "serde", serde(rename = "txpool_inspect", with = "empty_params"))]
TxPoolInspect(()),
#[cfg_attr(feature = "serde", serde(rename = "txpool_content", with = "empty_params"))]
TxPoolContent(()),
#[cfg_attr(feature = "serde", serde(rename = "erigon_getHeaderByNumber"))]
ErigonGetHeaderByNumber(
#[cfg_attr(
feature = "serde",
serde(deserialize_with = "lenient_block_number::lenient_block_number_seq")
)]
BlockNumber,
),
#[cfg_attr(feature = "serde", serde(rename = "ots_getApiLevel", with = "empty_params"))]
OtsGetApiLevel(()),
#[cfg_attr(feature = "serde", serde(rename = "ots_getInternalOperations", with = "sequence"))]
OtsGetInternalOperations(B256),
#[cfg_attr(feature = "serde", serde(rename = "ots_hasCode"))]
OtsHasCode(
Address,
#[cfg_attr(
feature = "serde",
serde(deserialize_with = "lenient_block_number::lenient_block_number", default)
)]
BlockNumber,
),
#[cfg_attr(feature = "serde", serde(rename = "ots_traceTransaction", with = "sequence"))]
OtsTraceTransaction(B256),
#[cfg_attr(feature = "serde", serde(rename = "ots_getTransactionError", with = "sequence"))]
OtsGetTransactionError(B256),
#[cfg_attr(feature = "serde", serde(rename = "ots_getBlockDetails"))]
OtsGetBlockDetails(
#[cfg_attr(
feature = "serde",
serde(deserialize_with = "lenient_block_number::lenient_block_number_seq", default)
)]
BlockNumber,
),
#[cfg_attr(feature = "serde", serde(rename = "ots_getBlockDetailsByHash", with = "sequence"))]
OtsGetBlockDetailsByHash(B256),
#[cfg_attr(feature = "serde", serde(rename = "ots_getBlockTransactions"))]
OtsGetBlockTransactions(u64, usize, usize),
#[cfg_attr(feature = "serde", serde(rename = "ots_searchTransactionsBefore"))]
OtsSearchTransactionsBefore(Address, u64, usize),
#[cfg_attr(feature = "serde", serde(rename = "ots_searchTransactionsAfter"))]
OtsSearchTransactionsAfter(Address, u64, usize),
#[cfg_attr(feature = "serde", serde(rename = "ots_getTransactionBySenderAndNonce",))]
OtsGetTransactionBySenderAndNonce(
Address,
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_number"))] U256,
),
#[cfg_attr(feature = "serde", serde(rename = "ots_getContractCreator", with = "sequence"))]
OtsGetContractCreator(Address),
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_removePoolTransactions", with = "sequence")
)]
RemovePoolTransactions(Address),
#[cfg_attr(feature = "serde", serde(rename = "anvil_reorg",))]
Reorg(ReorgOptions),
#[cfg_attr(feature = "serde", serde(rename = "wallet_getCapabilities", with = "empty_params"))]
WalletGetCapabilities(()),
#[cfg_attr(
feature = "serde",
serde(
rename = "wallet_sendTransaction",
alias = "odyssey_sendTransaction",
with = "sequence"
)
)]
WalletSendTransaction(Box<WithOtherFields<TransactionRequest>>),
#[cfg_attr(feature = "serde", serde(rename = "anvil_addCapability", with = "sequence"))]
AnvilAddCapability(Address),
#[cfg_attr(feature = "serde", serde(rename = "anvil_setExecutor", with = "sequence"))]
AnvilSetExecutor(String),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "method", content = "params"))]
pub enum EthPubSub {
#[cfg_attr(feature = "serde", serde(rename = "eth_subscribe"))]
EthSubscribe(
SubscriptionKind,
#[cfg_attr(feature = "serde", serde(default))] Box<SubscriptionParams>,
),
#[cfg_attr(feature = "serde", serde(rename = "eth_unsubscribe", with = "sequence"))]
EthUnSubscribe(SubscriptionId),
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
pub enum EthRpcCall {
Request(Box<EthRequest>),
PubSub(EthPubSub),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_web3_client_version() {
let s = r#"{"method": "web3_clientVersion", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_web3_sha3() {
let s = r#"{"method": "web3_sha3", "params":["0x68656c6c6f20776f726c64"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_accounts() {
let s = r#"{"method": "eth_accounts", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_network_id() {
let s = r#"{"method": "eth_networkId", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_get_proof() {
let s = r#"{"method":"eth_getProof","params":["0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842",["0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"],"latest"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_chain_id() {
let s = r#"{"method": "eth_chainId", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_net_listening() {
let s = r#"{"method": "net_listening", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_block_number() {
let s = r#"{"method": "eth_blockNumber", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_max_priority_fee() {
let s = r#"{"method": "eth_maxPriorityFeePerGas", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_syncing() {
let s = r#"{"method": "eth_syncing", "params":[]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_impersonate_account() {
let s = r#"{"method": "anvil_impersonateAccount", "params":
["0xd84de507f3fada7df80908082d3239466db55a71"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_stop_impersonate_account() {
let s = r#"{"method": "anvil_stopImpersonatingAccount", "params":
["0x364d6D0333432C3Ac016Ca832fb8594A8cE43Ca6"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_auto_impersonate_account() {
let s = r#"{"method": "anvil_autoImpersonateAccount", "params": [true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_get_automine() {
let s = r#"{"method": "anvil_getAutomine", "params": []}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_mine() {
let s = r#"{"method": "anvil_mine", "params": []}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Mine(num, time) => {
assert!(num.is_none());
assert!(time.is_none());
}
_ => unreachable!(),
}
let s = r#"{"method": "anvil_mine", "params":
["0xd84de507f3fada7df80908082d3239466db55a71"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Mine(num, time) => {
assert!(num.is_some());
assert!(time.is_none());
}
_ => unreachable!(),
}
let s = r#"{"method": "anvil_mine", "params": ["0xd84de507f3fada7df80908082d3239466db55a71", "0xd84de507f3fada7df80908082d3239466db55a71"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Mine(num, time) => {
assert!(num.is_some());
assert!(time.is_some());
}
_ => unreachable!(),
}
}
#[test]
fn test_custom_auto_mine() {
let s = r#"{"method": "anvil_setAutomine", "params": [false]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_setAutomine", "params": [false]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_interval_mining() {
let s = r#"{"method": "anvil_setIntervalMining", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_setIntervalMining", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_drop_tx() {
let s = r#"{"method": "anvil_dropTransaction", "params":
["0x4a3b0fce2cb9707b0baa68640cf2fe858c8bb4121b2a8cb904ff369d38a560ff"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_reset() {
let s = r#"{"method": "anvil_reset", "params": [{"forking": {"jsonRpcUrl": "https://ethereumpublicnode.com",
"blockNumber": "18441649"
}
}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking {
json_rpc_url: Some("https://ethereumpublicnode.com".into()),
block_number: Some(18441649)
})
)
}
_ => unreachable!(),
}
let s = r#"{"method": "anvil_reset", "params": [ { "forking": {
"jsonRpcUrl": "https://eth-mainnet.alchemyapi.io/v2/<key>",
"blockNumber": 11095000
}}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking {
json_rpc_url: Some(
"https://eth-mainnet.alchemyapi.io/v2/<key>".to_string()
),
block_number: Some(11095000)
})
)
}
_ => unreachable!(),
}
let s = r#"{"method": "anvil_reset", "params": [ { "forking": {
"jsonRpcUrl": "https://eth-mainnet.alchemyapi.io/v2/<key>"
}}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking {
json_rpc_url: Some(
"https://eth-mainnet.alchemyapi.io/v2/<key>".to_string()
),
block_number: None
})
)
}
_ => unreachable!(),
}
let s = r#"{"method":"anvil_reset","params":[{"jsonRpcUrl": "http://localhost:8545", "blockNumber": 14000000}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking {
json_rpc_url: Some("http://localhost:8545".to_string()),
block_number: Some(14000000)
})
)
}
_ => unreachable!(),
}
let s = r#"{"method":"anvil_reset","params":[{ "blockNumber": 14000000}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking { json_rpc_url: None, block_number: Some(14000000) })
)
}
_ => unreachable!(),
}
let s = r#"{"method":"anvil_reset","params":[{ "blockNumber": "14000000"}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking { json_rpc_url: None, block_number: Some(14000000) })
)
}
_ => unreachable!(),
}
let s = r#"{"method":"anvil_reset","params":[{"jsonRpcUrl": "http://localhost:8545"}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
let forking = forking.and_then(|f| f.params);
assert_eq!(
forking,
Some(Forking {
json_rpc_url: Some("http://localhost:8545".to_string()),
block_number: None
})
)
}
_ => unreachable!(),
}
let s = r#"{"method": "anvil_reset"}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::Reset(forking) => {
assert!(forking.is_none())
}
_ => unreachable!(),
}
}
#[test]
fn test_custom_set_balance() {
let s = r#"{"method": "anvil_setBalance", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", "0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_setBalance", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", 1337]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_set_code() {
let s = r#"{"method": "anvil_setCode", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", "0x0123456789abcdef"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_setCode", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", "0x"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_setCode", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", ""]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_custom_set_nonce() {
let s = r#"{"method": "anvil_setNonce", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", "0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method":
"hardhat_setNonce", "params": ["0xd84de507f3fada7df80908082d3239466db55a71", "0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_setAccountNonce", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", "0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_set_storage_at() {
let s = r#"{"method": "anvil_setStorageAt", "params":
["0x295a70b2de5e3953354a6a8344e616ed314d7251", "0x0",
"0x0000000000000000000000000000000000000000000000000000000000003039"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "hardhat_setStorageAt", "params":
["0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
"0xa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb49",
"0x0000000000000000000000000000000000000000000000000000000000003039"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_coinbase() {
let s = r#"{"method": "anvil_setCoinbase", "params":
["0x295a70b2de5e3953354a6a8344e616ed314d7251"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_logging() {
let s = r#"{"method": "anvil_setLoggingEnabled", "params": [false]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_min_gas_price() {
let s = r#"{"method": "anvil_setMinGasPrice", "params": ["0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_next_block_base_fee() {
let s = r#"{"method": "anvil_setNextBlockBaseFeePerGas", "params": ["0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_set_time() {
let s = r#"{"method": "anvil_setTime", "params": ["0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_increaseTime", "params": 1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_dump_state() {
let s = r#"{"method": "anvil_dumpState", "params": [true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_dumpState"}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::DumpState(param) => {
assert!(param.is_none());
}
_ => unreachable!(),
}
}
#[test]
fn test_serde_custom_load_state() {
let s = r#"{"method": "anvil_loadState", "params": ["0x0001"] }"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_snapshot() {
let s = r#"{"method": "anvil_snapshot", "params": [] }"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_snapshot", "params": [] }"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_revert() {
let s = r#"{"method": "anvil_revert", "params": ["0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_increase_time() {
let s = r#"{"method": "anvil_increaseTime", "params": ["0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_increaseTime", "params": [1]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_increaseTime", "params": 1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_increaseTime", "params": ["0x0"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_increaseTime", "params": [1]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_increaseTime", "params": 1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_next_timestamp() {
let s = r#"{"method": "anvil_setNextBlockTimestamp", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_setNextBlockTimestamp", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_setNextBlockTimestamp", "params": ["0x64e0f308"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_timestamp_interval() {
let s = r#"{"method": "anvil_setBlockTimestampInterval", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_remove_timestamp_interval() {
let s = r#"{"method": "anvil_removeBlockTimestampInterval", "params": []}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_evm_mine() {
let s = r#"{"method": "evm_mine", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "evm_mine", "params": [{
"timestamp": 100,
"blocks": 100
}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::EvmMine(params) => {
assert_eq!(
params.unwrap().params.unwrap_or_default(),
MineOptions::Options { timestamp: Some(100), blocks: Some(100) }
)
}
_ => unreachable!(),
}
let s = r#"{"method": "evm_mine"}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::EvmMine(params) => {
assert!(params.is_none())
}
_ => unreachable!(),
}
let s = r#"{"method": "evm_mine", "params": []}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_evm_mine_detailed() {
let s = r#"{"method": "anvil_mine_detailed", "params": [100]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "anvil_mine_detailed", "params": [{
"timestamp": 100,
"blocks": 100
}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::EvmMineDetailed(params) => {
assert_eq!(
params.unwrap().params.unwrap_or_default(),
MineOptions::Options { timestamp: Some(100), blocks: Some(100) }
)
}
_ => unreachable!(),
}
let s = r#"{"method": "evm_mine_detailed"}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::EvmMineDetailed(params) => {
assert!(params.is_none())
}
_ => unreachable!(),
}
let s = r#"{"method": "anvil_mine_detailed", "params": []}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_custom_evm_mine_hex() {
let s = r#"{"method": "evm_mine", "params": ["0x63b6ff08"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::EvmMine(params) => {
assert_eq!(
params.unwrap().params.unwrap_or_default(),
MineOptions::Timestamp(Some(1672937224))
)
}
_ => unreachable!(),
}
let s = r#"{"method": "evm_mine", "params": [{"timestamp": "0x63b6ff08"}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let req = serde_json::from_value::<EthRequest>(value).unwrap();
match req {
EthRequest::EvmMine(params) => {
assert_eq!(
params.unwrap().params.unwrap_or_default(),
MineOptions::Options { timestamp: Some(1672937224), blocks: None }
)
}
_ => unreachable!(),
}
}
#[test]
fn test_eth_uncle_count_by_block_hash() {
let s = r#"{"jsonrpc":"2.0","method":"eth_getUncleCountByBlockHash","params":["0x4a3b0fce2cb9707b0baa68640cf2fe858c8bb4121b2a8cb904ff369d38a560ff"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_block_tx_count_by_block_hash() {
let s = r#"{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByHash","params":["0x4a3b0fce2cb9707b0baa68640cf2fe858c8bb4121b2a8cb904ff369d38a560ff"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_get_logs() {
let s = r#"{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}],"id":74}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_new_filter() {
let s = r#"{"method": "eth_newFilter", "params": [{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}],"id":73}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_eth_unsubscribe() {
let s = r#"{"id": 1, "method": "eth_unsubscribe", "params":
["0x9cef478923ff08bf67fde6c64013158d"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthPubSub>(value).unwrap();
}
#[test]
fn test_serde_eth_subscribe() {
let s = r#"{"id": 1, "method": "eth_subscribe", "params": ["newHeads"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthPubSub>(value).unwrap();
let s = r#"{"id": 1, "method": "eth_subscribe", "params": ["logs", {"address":
"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd", "topics":
["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"]}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthPubSub>(value).unwrap();
let s = r#"{"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthPubSub>(value).unwrap();
let s = r#"{"id": 1, "method": "eth_subscribe", "params": ["syncing"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthPubSub>(value).unwrap();
}
#[test]
fn test_serde_debug_raw_transaction() {
let s = r#"{"jsonrpc":"2.0","method":"debug_getRawTransaction","params":["0x3ed3a89bc10115a321aee238c02de214009f8532a65368e5df5eaf732ee7167c"],"id":1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["0x3ed3a89bc10115a321aee238c02de214009f8532a65368e5df5eaf732ee7167c"],"id":1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"jsonrpc":"2.0","method":"eth_getRawTransactionByBlockHashAndIndex","params":["0x3ed3a89bc10115a321aee238c02de214009f8532a65368e5df5eaf732ee7167c",1],"id":1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"jsonrpc":"2.0","method":"eth_getRawTransactionByBlockNumberAndIndex","params":["0x3ed3a89b",0],"id":1}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_debug_trace_transaction() {
let s = r#"{"method": "debug_traceTransaction", "params":
["0x4a3b0fce2cb9707b0baa68640cf2fe858c8bb4121b2a8cb904ff369d38a560ff"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "debug_traceTransaction", "params":
["0x4a3b0fce2cb9707b0baa68640cf2fe858c8bb4121b2a8cb904ff369d38a560ff", {}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "debug_traceTransaction", "params":
["0x4a3b0fce2cb9707b0baa68640cf2fe858c8bb4121b2a8cb904ff369d38a560ff", {"disableStorage":
true}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_debug_trace_call() {
let s = r#"{"method": "debug_traceCall", "params": [{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "debug_traceCall", "params": [{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockNumber": "latest" }]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "debug_traceCall", "params": [{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockNumber": "0x0" }]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "debug_traceCall", "params": [{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" }]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "debug_traceCall", "params": [{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockNumber": "0x0" }, {"disableStorage": true}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_eth_storage() {
let s = r#"{"method": "eth_getStorageAt", "params":
["0x295a70b2de5e3953354a6a8344e616ed314d7251", "0x0", "latest"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_call() {
let req = r#"{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}"#;
let _req = serde_json::from_str::<TransactionRequest>(req).unwrap();
let s = r#"{"method": "eth_call", "params":[{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"},"latest"]}"#;
let _req = serde_json::from_str::<EthRequest>(s).unwrap();
let s = r#"{"method": "eth_call", "params":[{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}]}"#;
let _req = serde_json::from_str::<EthRequest>(s).unwrap();
let s = r#"{"method": "eth_call", "params":[{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockNumber": "latest" }]}"#;
let _req = serde_json::from_str::<EthRequest>(s).unwrap();
let s = r#"{"method": "eth_call", "params":[{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockNumber": "0x0" }]}"#;
let _req = serde_json::from_str::<EthRequest>(s).unwrap();
let s = r#"{"method": "eth_call", "params":[{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}, { "blockHash":"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" }]}"#;
let _req = serde_json::from_str::<EthRequest>(s).unwrap();
}
#[test]
fn test_serde_eth_balance() {
let s = r#"{"method": "eth_getBalance", "params":
["0x295a70b2de5e3953354a6a8344e616ed314d7251", "latest"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_eth_block_by_number() {
let s = r#"{"method": "eth_getBlockByNumber", "params": ["0x0", true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "eth_getBlockByNumber", "params": ["latest", true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "eth_getBlockByNumber", "params": ["earliest", true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "eth_getBlockByNumber", "params": ["pending", true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "eth_getBlockByNumber", "params": [0, true]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_sign() {
let s = r#"{"method": "eth_sign", "params":
["0xd84de507f3fada7df80908082d3239466db55a71", "0x00"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"{"method": "personal_sign", "params":
["0x00", "0xd84de507f3fada7df80908082d3239466db55a71"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_eth_sign_typed_data() {
let s = r#"{"method":"eth_signTypedData_v4","params":["0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", {"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":1,"verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_remove_pool_transactions() {
let s = r#"{"method": "anvil_removePoolTransactions", "params":["0x364d6D0333432C3Ac016Ca832fb8594A8cE43Ca6"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
#[test]
fn test_serde_anvil_reorg() {
let s = r#"
{
"method": "anvil_reorg",
"params": [
5,
[
[
{
"from": "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
"to": "0x1199bc69f16FDD6690DC40339EC445FaE1b6DD11",
"value": 100
},
1
],
[
{
"from": "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
"to": "0x1199bc69f16FDD6690DC40339EC445FaE1b6DD11",
"value": 200
},
2
]
]
]
}
"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"
{
"method": "anvil_reorg",
"params": [
5,
[
[
"0x19d55c67e1ba8f1bbdfed75f8ad524ebf087e4ecb848a2d19881d7a5e3d2c54e1732cb1b462da3b3fdb05bdf4c4d3c8e3c9fcebdc2ab5fa5d59a3f752888f27e1b",
1
]
]
]
}
"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
let s = r#"
{
"method": "anvil_reorg",
"params": [
5,
[
[
"0x19d55c67e1ba8f1bbdfed75f8ad524ebf087e4ecb848a2d19881d7a5e3d2c54e1732cb1b462da3b3fdb05bdf4c4d3c8e3c9fcebdc2ab5fa5d59a3f752888f27e1b",
1
],
[
{
"from": "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
"to": "0x1199bc69f16FDD6690DC40339EC445FaE1b6DD11",
"value": 200
},
2
]
]
]
}
"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
}