From d2aa67e8ee3ddbc5fe9b915e509edd2a883a518a Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 17 Aug 2023 21:55:58 -0700 Subject: [PATCH] test more methods --- web3_proxy/src/test_utils/anvil.rs | 26 ++++++++++++++++++++------ web3_proxy_cli/tests/test_proxy.rs | 24 ++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/web3_proxy/src/test_utils/anvil.rs b/web3_proxy/src/test_utils/anvil.rs index fc012cff..a96b705f 100644 --- a/web3_proxy/src/test_utils/anvil.rs +++ b/web3_proxy/src/test_utils/anvil.rs @@ -15,20 +15,34 @@ pub struct TestAnvil { } impl TestAnvil { - pub async fn spawn(chain_id: u64) -> Self { + pub async fn new(chain_id: Option, fork_rpc: Option<&str>) -> Self { info!(?chain_id); - // TODO: configurable rpc and block - let instance = Anvil::new() - .chain_id(chain_id) - // .fork("https://polygon.llamarpc.com@44300000") - .spawn(); + let mut instance = Anvil::new(); + + if let Some(chain_id) = chain_id { + instance = instance.chain_id(chain_id); + } + + if let Some(fork_rpc) = fork_rpc { + instance = instance.fork(fork_rpc); + } + + let instance = instance.spawn(); let provider = EthersHttpProvider::try_from(instance.endpoint()).unwrap(); Self { instance, provider } } + pub async fn spawn(chain_id: u64) -> Self { + Self::new(Some(chain_id), None).await + } + + pub async fn spawn_fork(fork_rpc: &str) -> Self { + Self::new(None, Some(fork_rpc)).await + } + pub fn wallet(&self, id: usize) -> LocalWallet { self.instance.keys()[id].clone().into() } diff --git a/web3_proxy_cli/tests/test_proxy.rs b/web3_proxy_cli/tests/test_proxy.rs index ec19114e..1dc37ef7 100644 --- a/web3_proxy_cli/tests/test_proxy.rs +++ b/web3_proxy_cli/tests/test_proxy.rs @@ -1,3 +1,4 @@ +use serde_json::Value; use std::{str::FromStr, time::Duration}; use tokio::{ task::yield_now, @@ -111,14 +112,15 @@ async fn it_starts_and_stops() { x.wait_for_stop(); } -/// TODO: have another test that queries mainnet so the state is more interesting? +/// TODO: have another test that queries mainnet so the state is more interesting +/// TODO: have another test that makes sure error codes match #[test_log::test(tokio::test)] async fn it_matches_anvil() { let a = TestAnvil::spawn(31337).await; // TODO: send some test transactions - a.provider.request::<_, ()>("evm_mine", ()).await.unwrap(); + a.provider.request::<_, U64>("evm_mine", ()).await.unwrap(); let x = TestApp::spawn(&a, None, None, None).await; @@ -153,6 +155,24 @@ async fn it_matches_anvil() { .unwrap(); info!(?block_with_tx); + let fee_history: Value = quorum_provider + .request("eth_feeHistory", (4, "latest", [25, 75])) + .await + .unwrap(); + info!(?fee_history); + + let gas_price: U256 = quorum_provider.request("eth_gasPrice", ()).await.unwrap(); + info!(%gas_price); + + let balance: U256 = quorum_provider + .request( + "eth_getBalance", + (block_with_tx.unwrap().author.unwrap(), "latest"), + ) + .await + .unwrap(); + info!(%balance); + // todo!("lots more requests"); // todo!("compare batch requests");