Repository: gakonst/ethers-rs
Pull request #1730 (2022-09-24 07:56:20)

fix(contract, signers): cyclic deps
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md

The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

## Motivation

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.
-->

https://github.com/gakonst/ethers-rs/issues/1713#issuecomment-1250400755

## Solution

<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->

- contract: Remove middleware, not needed since accounts are unlocked on Anvil
- signers: contract import was used only for the derive macros

## PR Checklist

- [ ] Added Tests
- [ ] Added Documentation
- [ ] Updated the changelog



Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 43b7f81d..6b7c6490 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1238,7 +1238,6 @@ dependencies = [
  "ethers-contract-derive",
  "ethers-core",
  "ethers-derive-eip712",
- "ethers-middleware",
  "ethers-providers",
  "ethers-signers",
  "ethers-solc",
@@ -1429,7 +1428,7 @@ dependencies = [
  "coins-ledger",
  "elliptic-curve",
  "eth-keystore",
- "ethers-contract",
+ "ethers-contract-derive",
  "ethers-core",
  "ethers-derive-eip712",
  "futures-executor",
diff --git a/ethers-contract/Cargo.toml b/ethers-contract/Cargo.toml
index d6512ab6..db602458 100644
--- a/ethers-contract/Cargo.toml
+++ b/ethers-contract/Cargo.toml
@@ -26,7 +26,6 @@ futures-util = { version = "^0.3" }
 hex = { version = "0.4.3", default-features = false, features = ["std"] }
 
 [dev-dependencies]
-ethers-middleware = { version = "^0.17.0", path = "../ethers-middleware" }
 ethers-providers = { version = "^0.17.0", path = "../ethers-providers", default-features = false, features = [
     "ws"
 ] }
diff --git a/ethers-contract/src/contract.rs b/ethers-contract/src/contract.rs
index 17443e5a..11ec62a3 100644
--- a/ethers-contract/src/contract.rs
+++ b/ethers-contract/src/contract.rs
@@ -185,9 +185,9 @@ impl<M> Contract<M> {
         &self.base_contract.abi
     }
 
-    /// Returns a reference to the contract's client
-    pub fn client(&self) -> &M {
-        &self.client
+    /// Returns a pointer to the contract's client
+    pub fn client(&self) -> Arc<M> {
+        self.client.clone()
     }
 }
 
diff --git a/ethers-contract/src/factory.rs b/ethers-contract/src/factory.rs
index 7f51e8d3..bffb9045 100644
--- a/ethers-contract/src/factory.rs
+++ b/ethers-contract/src/factory.rs
@@ -147,8 +147,8 @@ impl<M: Middleware, C: From<Contract<M>>> ContractDeployer<M, C> {
         self.deployer.abi()
     }
 
-    /// Returns a reference to the deployer's client
-    pub fn client(&self) -> &M {
+    /// Returns a pointer to the deployer's client
+    pub fn client(&self) -> Arc<M> {
         self.deployer.client()
     }
 }
@@ -261,9 +261,9 @@ impl<M: Middleware> Deployer<M> {
         &self.abi
     }
 
-    /// Returns a reference to the deployer's client
-    pub fn client(&self) -> &M {
-        &self.client
+    /// Returns a pointer to the deployer's client
+    pub fn client(&self) -> Arc<M> {
+        self.client.clone()
     }
 }
 
diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs
index cfe3745a..758eabbf 100644
--- a/ethers-core/src/types/chain.rs
+++ b/ethers-core/src/types/chain.rs
@@ -50,6 +50,7 @@ pub enum Chain {
     OptimismKovan = 69,
     Arbitrum = 42161,
     ArbitrumTestnet = 421611,
+    ArbitrumGoerli = 421613,
     Cronos = 25,
     CronosTestnet = 338,
     #[strum(serialize = "bsc")]
@@ -81,7 +82,7 @@ impl Chain {
     /// <https://polygonscan.com/chart/blocktime>
     pub fn average_blocktime_hint(&self) -> Option<Duration> {
         let ms = match self {
-            Chain::Arbitrum | Chain::ArbitrumTestnet => 1_300,
+            Chain::Arbitrum | Chain::ArbitrumTestnet | Chain::ArbitrumGoerli => 1_300,
             Chain::Mainnet | Chain::Optimism => 13_000,
             Chain::Polygon | Chain::PolygonMumbai => 2_100,
             Chain::Moonbeam | Chain::Moonriver => 12_500,
@@ -164,6 +165,10 @@ impl Chain {
             Chain::ArbitrumTestnet => {
                 ("https://api-testnet.arbiscan.io/api", "https://testnet.arbiscan.io")
             }
+            Chain::ArbitrumGoerli => (
+                "https://goerli-rollup-explorer.arbitrum.io/api",
+                "https://goerli-rollup-explorer.arbitrum.io",
+            ),
             Chain::Cronos => ("https://api.cronoscan.com/api", "https://cronoscan.com"),
             Chain::CronosTestnet => {
                 ("https://api-testnet.cronoscan.com/api", "https://testnet.cronoscan.com")
@@ -244,6 +249,7 @@ impl fmt::Display for Chain {
             Chain::BinanceSmartChainTestnet => "bsc-testnet",
             Chain::Arbitrum => "arbitrum",
             Chain::ArbitrumTestnet => "arbitrum-testnet",
+            Chain::ArbitrumGoerli => "arbitrum-goerli",
             Chain::Cronos => "cronos",
             Chain::CronosTestnet => "cronos-testnet",
             Chain::Poa => "poa",
@@ -313,6 +319,7 @@ impl TryFrom<u64> for Chain {
             97 => Chain::BinanceSmartChainTestnet,
             42161 => Chain::Arbitrum,
             421611 => Chain::ArbitrumTestnet,
+            421613 => Chain::ArbitrumGoerli,
             25 => Chain::Cronos,
             338 => Chain::CronosTestnet,
             99 => Chain::Poa,
@@ -372,6 +379,7 @@ impl FromStr for Chain {
             "bsc-testnet" => Chain::BinanceSmartChainTestnet,
             "arbitrum" => Chain::Arbitrum,
             "arbitrum-testnet" => Chain::ArbitrumTestnet,
+            "arbitrum-goerli" => Chain::ArbitrumGoerli,
             "cronos" => Chain::Cronos,
             "cronos-testnet" => Chain::CronosTestnet,
             "poa" => Chain::Poa,
@@ -403,6 +411,7 @@ impl Chain {
                 Chain::BinanceSmartChainTestnet |
                 Chain::Arbitrum |
                 Chain::ArbitrumTestnet |
+                Chain::ArbitrumGoerli |
                 Chain::Rsk |
                 Chain::Oasis |
                 Chain::Emerald |
diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs
index 33fd37cf..dcab1fc0 100644
--- a/ethers-etherscan/src/lib.rs
+++ b/ethers-etherscan/src/lib.rs
@@ -93,6 +93,7 @@ impl Client {
             Chain::BinanceSmartChainTestnet |
             Chain::Arbitrum |
             Chain::ArbitrumTestnet |
+            Chain::ArbitrumGoerli |
             Chain::Cronos |
             Chain::CronosTestnet |
             Chain::Aurora |
diff --git a/ethers-signers/Cargo.toml b/ethers-signers/Cargo.toml
index 84ab59a9..66dffd69 100644
--- a/ethers-signers/Cargo.toml
+++ b/ethers-signers/Cargo.toml
@@ -44,10 +44,7 @@ eth-keystore = { version = "0.5.0" }
 home = { version = "0.5.3", optional = true }
 
 [dev-dependencies]
-ethers-contract = { version = "^0.17.0", path = "../ethers-contract", features = [
-    "eip712",
-    "abigen"
-] }
+ethers-contract-derive = { version = "^0.17.0", path = "../ethers-contract/ethers-contract-derive" }
 ethers-derive-eip712 = { version = "^0.17.0", path = "../ethers-core/ethers-derive-eip712" }
 serde_json = { version = "1.0.64" }
 tracing-subscriber = "0.3.15"
diff --git a/ethers-signers/src/ledger/app.rs b/ethers-signers/src/ledger/app.rs
index fc9e4fe2..5932f0b8 100644
--- a/ethers-signers/src/ledger/app.rs
+++ b/ethers-signers/src/ledger/app.rs
@@ -250,7 +250,7 @@ impl LedgerEthereum {
 mod tests {
     use super::*;
     use crate::Signer;
-    use ethers_contract::EthAbiType;
+    use ethers_contract_derive::EthAbiType;
     use ethers_core::types::{
         transaction::eip712::Eip712, Address, TransactionRequest, I256, U256,
     };
diff --git a/ethers-signers/src/trezor/app.rs b/ethers-signers/src/trezor/app.rs
index 5994c79a..a9e7b555 100644
--- a/ethers-signers/src/trezor/app.rs
+++ b/ethers-signers/src/trezor/app.rs
@@ -233,7 +233,7 @@ impl TrezorEthereum {
 mod tests {
     use super::*;
     use crate::Signer;
-    use ethers_contract::EthAbiType;
+    use ethers_contract_derive::EthAbiType;
     use ethers_core::types::{
         transaction::{
             eip2930::{AccessList, AccessListItem},


Test patch:
diff --git a/ethers-contract/tests/it/abigen.rs b/ethers-contract/tests/it/abigen.rs
index d09c2b96..dbcaa1df 100644
--- a/ethers-contract/tests/it/abigen.rs
+++ b/ethers-contract/tests/it/abigen.rs
@@ -7,9 +7,7 @@ use ethers_core::{
     types::{transaction::eip2718::TypedTransaction, Chain, Eip1559TransactionRequest, U256},
     utils::Anvil,
 };
-use ethers_middleware::SignerMiddleware;
 use ethers_providers::{MockProvider, Provider};
-use ethers_signers::{LocalWallet, Signer};
 use ethers_solc::Solc;
 use std::{
     convert::{TryFrom, TryInto},
@@ -617,11 +615,14 @@ fn can_handle_overloaded_events() {
 async fn can_send_struct_param() {
     abigen!(StructContract, "./tests/solidity-contracts/StructContract.json");
 
-    let server = Anvil::new().spawn();
-    let wallet: LocalWallet = server.keys()[0].clone().into();
-    let provider = Provider::try_from(server.endpoint()).unwrap();
-    let client =
-        Arc::new(SignerMiddleware::new(provider, wallet.with_chain_id(Chain::AnvilHardhat)));
+    // launch the network & connect to it
+    let anvil = Anvil::new().spawn();
+    let from = anvil.addresses()[0];
+    let provider = Provider::try_from(anvil.endpoint())
+        .unwrap()
+        .with_sender(from)
+        .interval(std::time::Duration::from_millis(10));
+    let client = Arc::new(provider);
 
     let contract = StructContract::deploy(client, ()).unwrap().legacy().send().await.unwrap();
 
diff --git a/ethers-contract/tests/it/contract.rs b/ethers-contract/tests/it/contract.rs
index 756210b2..5968b19d 100644
--- a/ethers-contract/tests/it/contract.rs
+++ b/ethers-contract/tests/it/contract.rs
@@ -13,7 +13,6 @@ mod eth_tests {
         utils::{keccak256, Anvil},
     };
     use ethers_derive_eip712::*;
-    use ethers_middleware::signer::SignerMiddleware;
     use ethers_providers::{Http, Middleware, PendingTransaction, Provider, StreamExt};
     use ethers_signers::{LocalWallet, Signer};
     use std::{convert::TryFrom, sync::Arc, time::Duration};
@@ -747,19 +746,17 @@ mod eth_tests {
         // get ABI and bytecode for the DeriveEip712Test contract
         let (abi, bytecode) = compile_contract("DeriveEip712Test", "DeriveEip712Test.sol");
 
-        // launch anvil
+        // launch the network & connect to it
         let anvil = Anvil::new().spawn();
+        let from = anvil.addresses()[0];
+        let provider = Provider::try_from(anvil.endpoint())
+            .unwrap()
+            .with_sender(from)
+            .interval(std::time::Duration::from_millis(10));
+        let client = Arc::new(provider);
 
         let wallet: LocalWallet = anvil.keys()[0].clone().into();
 
-        let provider = Provider::<Http>::try_from(anvil.endpoint())
-            .expect("failed to instantiate provider from anvil endpoint")
-            .interval(Duration::from_millis(10u64));
-
-        let client =
-            SignerMiddleware::new_with_provider_chain(provider, wallet.clone()).await.unwrap();
-        let client = Arc::new(client);
-
         let factory = ContractFactory::new(abi.clone(), bytecode.clone(), client.clone());
 
         let contract = factory