test more methods
This commit is contained in:
parent
e86bb6ee07
commit
d2aa67e8ee
@ -15,20 +15,34 @@ pub struct TestAnvil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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);
|
info!(?chain_id);
|
||||||
|
|
||||||
// TODO: configurable rpc and block
|
let mut instance = Anvil::new();
|
||||||
let instance = Anvil::new()
|
|
||||||
.chain_id(chain_id)
|
if let Some(chain_id) = chain_id {
|
||||||
// .fork("https://polygon.llamarpc.com@44300000")
|
instance = instance.chain_id(chain_id);
|
||||||
.spawn();
|
}
|
||||||
|
|
||||||
|
if let Some(fork_rpc) = fork_rpc {
|
||||||
|
instance = instance.fork(fork_rpc);
|
||||||
|
}
|
||||||
|
|
||||||
|
let instance = instance.spawn();
|
||||||
|
|
||||||
let provider = EthersHttpProvider::try_from(instance.endpoint()).unwrap();
|
let provider = EthersHttpProvider::try_from(instance.endpoint()).unwrap();
|
||||||
|
|
||||||
Self { instance, provider }
|
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 {
|
pub fn wallet(&self, id: usize) -> LocalWallet {
|
||||||
self.instance.keys()[id].clone().into()
|
self.instance.keys()[id].clone().into()
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use serde_json::Value;
|
||||||
use std::{str::FromStr, time::Duration};
|
use std::{str::FromStr, time::Duration};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
task::yield_now,
|
task::yield_now,
|
||||||
@ -111,14 +112,15 @@ async fn it_starts_and_stops() {
|
|||||||
x.wait_for_stop();
|
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)]
|
#[test_log::test(tokio::test)]
|
||||||
async fn it_matches_anvil() {
|
async fn it_matches_anvil() {
|
||||||
let a = TestAnvil::spawn(31337).await;
|
let a = TestAnvil::spawn(31337).await;
|
||||||
|
|
||||||
// TODO: send some test transactions
|
// 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;
|
let x = TestApp::spawn(&a, None, None, None).await;
|
||||||
|
|
||||||
@ -153,6 +155,24 @@ async fn it_matches_anvil() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
info!(?block_with_tx);
|
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!("lots more requests");
|
||||||
|
|
||||||
// todo!("compare batch requests");
|
// todo!("compare batch requests");
|
||||||
|
Loading…
Reference in New Issue
Block a user