Skip to content

Commit

Permalink
fix: some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Apr 25, 2024
1 parent 85f37b3 commit 24eac3c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions crates/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ alloy-pubsub = { workspace = true, optional = true }
alloy-rpc-client = { workspace = true, features = ["pubsub", "ws"] }
alloy-transport-http.workspace = true
alloy-node-bindings.workspace = true
alloy-provider = { workspace = true, features = ["anvil"] }

reqwest.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Expand Down
19 changes: 6 additions & 13 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,19 +513,12 @@ mod tests {
use alloy_network::Ethereum;
use alloy_node_bindings::{Anvil, AnvilInstance};
use alloy_primitives::{address, b256, bytes, hex};
use alloy_provider::{Provider, ReqwestProvider, RootProvider};
use alloy_provider::{Provider, ProviderBuilder, RootProvider, WalletProvider};
use alloy_rpc_client::RpcClient;
use alloy_sol_types::sol;
use alloy_transport_http::Http;
use reqwest::Client;

fn spawn_anvil() -> (ReqwestProvider, AnvilInstance) {
let anvil = Anvil::new().spawn();
let url = anvil.endpoint().parse().unwrap();
let http = Http::<Client>::new(url);
(RootProvider::new(RpcClient::new(http, true)), anvil)
}

#[test]
fn empty_constructor() {
sol! {
Expand All @@ -535,7 +528,7 @@ mod tests {
}
}

let (provider, _anvil) = spawn_anvil();
let provider = ProviderBuilder::new().on_anvil();
let call_builder = EmptyConstructor::deploy_builder(&provider);
assert_eq!(*call_builder.calldata(), bytes!("6942"));
}
Expand All @@ -559,7 +552,7 @@ mod tests {

#[test]
fn call_encoding() {
let (provider, _anvil) = spawn_anvil();
let provider = ProviderBuilder::new().on_anvil();
let contract = MyContract::new(Address::ZERO, &&provider).with_cloned_provider();
let call_builder = contract.doStuff(U256::ZERO, true).with_cloned_provider();
assert_eq!(
Expand All @@ -577,7 +570,7 @@ mod tests {

#[test]
fn deploy_encoding() {
let (provider, _anvil) = spawn_anvil();
let provider = ProviderBuilder::new().on_anvil();
let bytecode = &MyContract::BYTECODE[..];
let call_builder = MyContract::deploy_builder(&provider, false);
assert_eq!(
Expand All @@ -601,10 +594,10 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn deploy_and_call() {
let (provider, anvil) = spawn_anvil();
let provider = ProviderBuilder::new().on_anvil_with_signer();

let expected_address = provider.default_signer_address().create(0);
let my_contract = MyContract::deploy(provider, true).await.unwrap();
let expected_address = anvil.addresses()[0].create(0);
assert_eq!(*my_contract.address(), expected_address);

let my_state_builder = my_contract.myState();
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
/// let provider = ProviderBuilder::new()
/// .with_chain_id(1)
/// .signer(signer)
/// .on_http(url)?;
/// .on_http(url);
///
/// provider.send_transaction(TransactionRequest::default()).await;
/// # Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum GasFillable {
/// let provider = ProviderBuilder::new()
/// .with_gas_estimation()
/// .signer(signer)
/// .on_http(url)?;
/// .on_http(url);
///
/// provider.send_transaction(TransactionRequest::default()).await;
/// # Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use tokio::sync::Mutex;
/// let provider = ProviderBuilder::new()
/// .with_nonce_management()
/// .signer(signer)
/// .on_http(url)?;
/// .on_http(url);
///
/// provider.send_transaction(TransactionRequest::default()).await;
/// # Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::{FillerControlFlow, TxFiller};
/// # async fn test<S: NetworkSigner<Ethereum> + Clone>(url: url::Url, signer: S) -> Result<(), Box<dyn std::error::Error>> {
/// let provider = ProviderBuilder::new()
/// .signer(signer)
/// .on_http(url)?;
/// .on_http(url);
///
/// provider.send_transaction(TransactionRequest::default()).await;
/// # Ok(())
Expand Down

0 comments on commit 24eac3c

Please sign in to comment.