Repository: gakonst/ethers-rs
Pull request #2020 (2023-01-05 20:24:31)

feat: Add arbitrum nova api and chain id 42170
## Motivation

This adds support for Arbitrum Nova chain.

## Solution

Add ArbitrumNova to Chain enum with chain id: 42170

## PR Checklist

-   [ ] Added Tests
-   [ ] Added Documentation
-   [ ] Updated the changelog
-   [ ] Breaking changes



Patch:
diff --git a/ethers-contract/ethers-contract-abigen/src/contract/events.rs b/ethers-contract/ethers-contract-abigen/src/contract/events.rs
index 90727439..bae8ca66 100644
--- a/ethers-contract/ethers-contract-abigen/src/contract/events.rs
+++ b/ethers-contract/ethers-contract-abigen/src/contract/events.rs
@@ -405,7 +405,7 @@ mod tests {
             #[doc = "Gets the contract's `Transfer` event"]
             pub fn transfer_event_filter(
                 &self
-            ) -> ethers_contract::builders::Event<M, TransferEventFilter> {
+            ) -> ::ethers_contract::builders::Event<M, TransferEventFilter> {
                 self.0.event()
             }
         });
@@ -424,7 +424,7 @@ mod tests {
         let cx = test_context();
         assert_quote!(cx.expand_filter(&event), {
             #[doc = "Gets the contract's `Transfer` event"]
-            pub fn transfer_filter(&self) -> ethers_contract::builders::Event<M, TransferFilter> {
+            pub fn transfer_filter(&self) -> ::ethers_contract::builders::Event<M, TransferFilter> {
                 self.0.event()
             }
         });
@@ -449,7 +449,7 @@ mod tests {
         assert_quote!(definition, {
             struct FooFilter {
                 pub a: bool,
-                pub p1: ethers_core::types::Address,
+                pub p1: ::ethers_core::types::Address,
             }
         });
     }
@@ -474,7 +474,7 @@ mod tests {
         assert_quote!(definition, {
             struct FooAliasedFilter {
                 pub a: bool,
-                pub p1: ethers_core::types::Address,
+                pub p1: ::ethers_core::types::Address,
             }
         });
     }
@@ -496,7 +496,7 @@ mod tests {
         let definition = expand_data_tuple(&name, &params);
 
         assert_quote!(definition, {
-            struct FooFilter(pub bool, pub ethers_core::types::Address);
+            struct FooFilter(pub bool, pub ::ethers_core::types::Address);
         });
     }
 
@@ -518,7 +518,7 @@ mod tests {
         let definition = expand_data_tuple(&name, &params);
 
         assert_quote!(definition, {
-            struct FooAliasedFilter(pub bool, pub ethers_core::types::Address);
+            struct FooAliasedFilter(pub bool, pub ::ethers_core::types::Address);
         });
     }
 
@@ -530,7 +530,7 @@ mod tests {
                 "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f".parse().unwrap()
             ),
             {
-                ethers_core::types::H256([
+                ::ethers_core::types::H256([
                     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
                 ])
diff --git a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs
index 6fc6bb56..e2d048ad 100644
--- a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs
+++ b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs
@@ -846,31 +846,28 @@ mod tests {
     }
 
     #[test]
-    fn expand_inputs_() {
+    fn test_expand_inputs() {
         assert_quote!(
-            expand_inputs(
-
-                &[
-                    Param {
-                        name: "a".to_string(),
-                        kind: ParamType::Bool,
-                        internal_type: None,
-                    },
-                    Param {
-                        name: "b".to_string(),
-                        kind: ParamType::Address,
-                        internal_type: None,
-                    },
-                ],
-            )
+            expand_inputs(&[
+                Param {
+                    name: "a".to_string(),
+                    kind: ParamType::Bool,
+                    internal_type: None,
+                },
+                Param {
+                    name: "b".to_string(),
+                    kind: ParamType::Address,
+                    internal_type: None,
+                },
+            ])
             .unwrap(),
-            { , a: bool, b: ethers_core::types::Address },
+            { , a: bool, b: ::ethers_core::types::Address },
         );
     }
 
     #[test]
     fn expand_fn_outputs_empty() {
-        assert_quote!(expand_fn_outputs(&[],).unwrap(), { () });
+        assert_quote!(expand_fn_outputs(&[]).unwrap(), { () });
     }
 
     #[test]
@@ -892,9 +889,9 @@ mod tests {
             expand_fn_outputs(&[
                 Param { name: "a".to_string(), kind: ParamType::Bool, internal_type: None },
                 Param { name: "b".to_string(), kind: ParamType::Address, internal_type: None },
-            ],)
+            ])
             .unwrap(),
-            { (bool, ethers_core::types::Address) },
+            { (bool, ::ethers_core::types::Address) },
         );
     }
 }
diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs
index 11417376..8069370c 100644
--- a/ethers-core/src/types/chain.rs
+++ b/ethers-core/src/types/chain.rs
@@ -50,6 +50,7 @@ pub enum Chain {
     Arbitrum = 42161,
     ArbitrumTestnet = 421611,
     ArbitrumGoerli = 421613,
+    ArbitrumNova = 42170,
 
     Cronos = 25,
     CronosTestnet = 338,
@@ -205,7 +206,7 @@ impl Chain {
         use Chain::*;
 
         let ms = match self {
-            Arbitrum | ArbitrumTestnet | ArbitrumGoerli => 1_300,
+            Arbitrum | ArbitrumTestnet | ArbitrumGoerli | ArbitrumNova => 1_300,
             Mainnet | Optimism => 13_000,
             Polygon | PolygonMumbai => 2_100,
             Moonbeam | Moonriver => 12_500,
@@ -276,6 +277,7 @@ impl Chain {
                 "https://goerli-rollup-explorer.arbitrum.io/api",
                 "https://goerli-rollup-explorer.arbitrum.io",
             ),
+            ArbitrumNova => ("https://api-nova.arbiscan.io/api", "https://nova.arbiscan.io/"),
             Cronos => ("https://api.cronoscan.com/api", "https://cronoscan.com"),
             CronosTestnet => {
                 ("https://api-testnet.cronoscan.com/api", "https://testnet.cronoscan.com")
@@ -340,6 +342,7 @@ impl Chain {
             Arbitrum |
             ArbitrumTestnet |
             ArbitrumGoerli |
+            ArbitrumNova |
             Rsk |
             Oasis |
             Emerald |
diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs
index 9c9930db..f8340d41 100644
--- a/ethers-etherscan/src/lib.rs
+++ b/ethers-etherscan/src/lib.rs
@@ -95,6 +95,7 @@ impl Client {
             Chain::Arbitrum |
             Chain::ArbitrumTestnet |
             Chain::ArbitrumGoerli |
+            Chain::ArbitrumNova |
             Chain::Cronos |
             Chain::CronosTestnet |
             Chain::Aurora |
diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs
index 11083891..54fd646e 100644
--- a/ethers-providers/src/provider.rs
+++ b/ethers-providers/src/provider.rs
@@ -359,10 +359,10 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
                     //   - first: if set, set to the min(current value, MFPG)
                     //   - second, if still unset, use the RPC estimated amount
                     let mfpg = inner.max_fee_per_gas.get_or_insert(max_fee_per_gas);
-                    inner
+                    inner.max_priority_fee_per_gas = inner
                         .max_priority_fee_per_gas
                         .map(|tip| std::cmp::min(tip, *mfpg))
-                        .get_or_insert(max_priority_fee_per_gas);
+                        .or(Some(max_priority_fee_per_gas));
                 };
             }
         }


Test patch:
diff --git a/ethers-middleware/tests/nonce_manager.rs b/ethers-middleware/tests/nonce_manager.rs
index 1be27fec..85368aa2 100644
--- a/ethers-middleware/tests/nonce_manager.rs
+++ b/ethers-middleware/tests/nonce_manager.rs
@@ -1,28 +1,22 @@
 #![cfg(all(not(target_arch = "wasm32"), not(feature = "celo")))]
 
-use ethers_core::types::*;
-use ethers_middleware::{nonce_manager::NonceManagerMiddleware, signer::SignerMiddleware};
-use ethers_providers::Middleware;
-use ethers_signers::{LocalWallet, Signer};
-use std::time::Duration;
+use ethers_core::{types::*, utils::Anvil};
+use ethers_middleware::MiddlewareBuilder;
+use ethers_providers::{Http, Middleware, Provider};
 
 #[tokio::test]
 async fn nonce_manager() {
-    let provider = ethers_providers::GOERLI.provider().interval(Duration::from_millis(2000));
-    let chain_id = provider.get_chainid().await.unwrap().as_u64();
+    let anvil = Anvil::new().spawn();
+    let endpoint = anvil.endpoint();
 
-    let wallet = std::env::var("GOERLI_PRIVATE_KEY")
-        .expect("GOERLI_PRIVATE_KEY is not defined")
-        .parse::<LocalWallet>()
-        .unwrap()
-        .with_chain_id(chain_id);
-    let address = wallet.address();
-
-    let provider = SignerMiddleware::new(provider, wallet);
+    let provider = Provider::<Http>::try_from(endpoint).unwrap();
+    let accounts = provider.get_accounts().await.unwrap();
+    let address = accounts[0];
+    let to = accounts[1];
 
     // the nonce manager must be over the Client so that it overrides the nonce
     // before the client gets it
-    let provider = NonceManagerMiddleware::new(provider, address);
+    let provider = provider.nonce_manager(address);
 
     let nonce = provider
         .get_transaction_count(address, Some(BlockNumber::Pending.into()))
@@ -34,22 +28,16 @@ async fn nonce_manager() {
     let mut tx_hashes = Vec::with_capacity(num_tx);
     for _ in 0..num_tx {
         let tx = provider
-            .send_transaction(
-                Eip1559TransactionRequest::new().to(address).value(100u64).chain_id(chain_id),
-                None,
-            )
+            .send_transaction(TransactionRequest::new().from(address).to(to).value(100u64), None)
             .await
             .unwrap();
         tx_hashes.push(*tx);
     }
 
-    // sleep a bit to ensure there's no flakiness in the test
-    tokio::time::sleep(Duration::from_secs(10)).await;
-
     let mut nonces = Vec::with_capacity(num_tx);
     for tx_hash in tx_hashes {
         nonces.push(provider.get_transaction(tx_hash).await.unwrap().unwrap().nonce.as_u64());
     }
 
-    assert_eq!(nonces, (nonce..nonce + num_tx as u64).collect::<Vec<_>>())
+    assert_eq!(nonces, (nonce..nonce + num_tx as u64).collect::<Vec<_>>());
 }