test more methods

This commit is contained in:
Bryan Stitt 2023-08-17 21:55:58 -07:00
parent e86bb6ee07
commit d2aa67e8ee
2 changed files with 42 additions and 8 deletions

@ -15,20 +15,34 @@ pub struct TestAnvil {
}
impl TestAnvil {
pub async fn spawn(chain_id: u64) -> Self {
pub async fn new(chain_id: Option<u64>, 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()
}

@ -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");