This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Succesfully deploy multicall to anvil in tests
- Loading branch information
Showing
3 changed files
with
33 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::spawn_anvil; | ||
use ethers_core::types::*; | ||
use ethers_middleware::{MiddlewareBuilder, MulticallMiddleware}; | ||
use ethers_providers::Middleware; | ||
|
||
use ethers_contract::multicall::constants::{DEPLOY_MULTICALL_TX, MULTICALL_ADDRESS}; | ||
use ethers_contract::{ | ||
multicall::constants::{DEPLOYER_ADDRESS, MULTICALL_ADDRESS, SIGNED_DEPLOY_MULTICALL_TX}, | ||
multicall::contract::Multicall3, | ||
BaseContract, | ||
}; | ||
use instant::Duration; | ||
|
||
#[tokio::test] | ||
async fn multicall() { | ||
let (provider, anvil) = spawn_anvil(); | ||
|
||
let tx_bytes: Bytes = DEPLOY_MULTICALL_TX.into(); | ||
|
||
provider.send_raw_transaction(tx_bytes).await.unwrap(); | ||
|
||
let contracts = Vec::new(); | ||
provider | ||
.request::<(H160, U256), ()>( | ||
"anvil_setBalance", | ||
(DEPLOYER_ADDRESS, U256::from(1_000_000_000_000_000_000u64)), | ||
) | ||
.await | ||
.unwrap(); | ||
provider | ||
.request::<[serde_json::Value; 1], H256>( | ||
"eth_sendRawTransaction", | ||
[SIGNED_DEPLOY_MULTICALL_TX.into()], | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// TODO: inject some contract ABIs to call | ||
let contracts = vec![]; | ||
let mut multicall_provider = MulticallMiddleware::new( | ||
provider, | ||
contracts, | ||
Duration::from_secs(1), | ||
Some(MULTICALL_ADDRESS), | ||
).unwrap(); | ||
) | ||
.unwrap(); | ||
|
||
// spawn the multicall middleware | ||
tokio::spawn(async move { | ||
multicall_provider.run().await; | ||
}); | ||
|
||
// TODO: make some async calls and verify that only 1 RPC is made | ||
} |