ci: fix nonce manager test (#2014)
* Use Anvil instead of Goerli to test the nonce manager * restore comment * fix: explicitly assign `inner.max_priority_fee_per_gas` Co-authored-by: Andrea Simeoni <>
This commit is contained in:
parent
7e6c3ba983
commit
5917e842d7
|
@ -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<_>>());
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue