ethers-rs/ethers-middleware/tests/it/gas_escalator.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.6 KiB
Rust
Raw Normal View History

ci/test: improve CI jobs and tests (#2189) * ci: move to scripts directory * nits * ci: improve main CI jobs * fix: install script * fix * fix: use curl for windows installation * fix: wasm typo * tests: move to single binary * chore: clippy * chore: clippy * chore: clippy * fix: test command * fix: quote tests * update script * fix: action exclude * fix: dev deps * fix: only run wasm in own job * ci: add aarch64 targets * test: rm useless test * ci: update security audit * ci: add deny CI * chore: rm unused audit.toml * chore: update geth.rs * ci: remove unusable targets * fix: install script path * fix: wasm * improve script * fix: failing ci * fix: contract tests * ci: improve install script * update middleware tests * move integration etherscan tests to tests/ dir * fix: eip2930 access_list field name * add pendingtransaction must_use * add random anvil comment * ci: add miri job * ci: simplify * fixci * Revert "add pendingtransaction must_use" This reverts commit 770b21b4a3c6ef8900a6aa1cd46aa9638317a60d. * fix: macos script * fix: use curl in script * unused ci * update script * fix wasm * rm_miri * fix: signer test * fix: wasm ci * fix: ipc test * fix: live celo tests * fix: abi online source test * fix: windows paths in test * chore: update serial_test * ci: run live tests separately * fix: provider tests * fix: unused var * fix: feature * fix merge * fix: etherscan key tests * ci: rm duplicate audit * fix: split etherscan test ci * fix: etherscan test * fix: generate multiple unused ports * fix: source test * fix: udeps * rm unused
2023-03-01 00:26:27 +00:00
use ethers_core::{types::*, utils::Anvil};
use ethers_middleware::{
gas_escalator::{Frequency, GasEscalatorMiddleware, GeometricGasPrice},
MiddlewareBuilder,
};
use ethers_providers::{Http, Middleware, Provider};
use ethers_signers::{LocalWallet, Signer};
#[tokio::test]
#[ignore]
async fn gas_escalator() {
let anvil = Anvil::new().block_time(2u64).spawn();
let chain_id = anvil.chain_id();
let provider = Provider::<Http>::try_from(anvil.endpoint()).unwrap();
// wrap with signer
let wallet: LocalWallet = anvil.keys().first().unwrap().clone().into();
let wallet = wallet.with_chain_id(chain_id);
let address = wallet.address();
let provider = provider.with_signer(wallet);
// wrap with escalator
let escalator = GeometricGasPrice::new(5.0, 10u64, Some(2_000_000_000_000u64));
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::Duration(300));
let nonce = provider.get_transaction_count(address, None).await.unwrap();
// 1 gwei default base fee
let gas_price = U256::from(1_000_000_000_u64);
let tx = TransactionRequest::pay(Address::zero(), 1u64)
.gas_price(gas_price)
.nonce(nonce)
.chain_id(chain_id);
eprintln!("sending");
let pending = provider.send_transaction(tx, None).await.expect("could not send");
eprintln!("waiting");
let receipt = pending.await.expect("reverted").expect("dropped");
assert_eq!(receipt.from, address);
assert_eq!(receipt.to, Some(Address::zero()));
assert!(receipt.effective_gas_price.unwrap() > gas_price * 2, "{receipt:?}");
}