Skip to content

Commit 9bf2b7e

Browse files
committed
ref: reorg provider logic
1 parent dfa2840 commit 9bf2b7e

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

tests/common.rs renamed to tests/common/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub async fn setup_latest_scanner(
182182
}
183183

184184
pub async fn reorg_with_new_count_incr_txs<P>(
185-
provider: RootProvider,
185+
anvil: AnvilInstance,
186186
contract: TestCounter::TestCounterInstance<Arc<P>>,
187187
num_initial_events: u64,
188188
num_new_events: u64,
@@ -192,6 +192,8 @@ pub async fn reorg_with_new_count_incr_txs<P>(
192192
where
193193
P: Provider<Ethereum> + Clone,
194194
{
195+
let wallet = anvil.wallet().expect("anvil should return a default wallet");
196+
let provider = ProviderBuilder::new().wallet(wallet).connect(anvil.endpoint().as_str()).await?;
195197
let mut event_tx_hashes = vec![];
196198

197199
for _ in 0..num_initial_events {

tests/historic_to_live/reorg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn block_confirmations_mitigate_reorgs_historic_to_live() -> anyhow::Resul
3232
let same_block = false;
3333

3434
let all_tx_hashes = reorg_with_new_count_incr_txs(
35-
provider.clone(),
35+
setup.anvil,
3636
contract.clone(),
3737
num_initial_events,
3838
num_new_events,

tests/live_mode/reorg.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use event_scanner::{Message, ScannerStatus};
1010

1111
#[tokio::test]
1212
async fn reorg_rescans_events_within_same_block() -> anyhow::Result<()> {
13-
let LiveScannerSetup { provider, contract, scanner, mut stream, anvil: _anvil } =
13+
let LiveScannerSetup { provider: _provider, contract, scanner, mut stream, anvil } =
1414
setup_live_scanner(Option::Some(0.1), Option::None, 0).await?;
1515

1616
scanner.start().await?;
@@ -21,7 +21,7 @@ async fn reorg_rescans_events_within_same_block() -> anyhow::Result<()> {
2121
let same_block = true;
2222

2323
let expected_event_tx_hashes = reorg_with_new_count_incr_txs(
24-
provider,
24+
anvil,
2525
contract,
2626
num_initial_events,
2727
num_new_events,
@@ -71,7 +71,7 @@ async fn reorg_rescans_events_within_same_block() -> anyhow::Result<()> {
7171

7272
#[tokio::test]
7373
async fn reorg_rescans_events_with_ascending_blocks() -> anyhow::Result<()> {
74-
let LiveScannerSetup { provider, contract, scanner, mut stream, anvil: _anvil } =
74+
let LiveScannerSetup { provider: _provider, contract, scanner, mut stream, anvil } =
7575
setup_live_scanner(Option::Some(0.1), Option::None, 0).await?;
7676

7777
scanner.start().await?;
@@ -84,7 +84,7 @@ async fn reorg_rescans_events_with_ascending_blocks() -> anyhow::Result<()> {
8484
let same_block = false;
8585

8686
let expected_event_tx_hashes = reorg_with_new_count_incr_txs(
87-
provider,
87+
anvil,
8888
contract,
8989
num_initial_events,
9090
num_new_events,
@@ -134,7 +134,7 @@ async fn reorg_rescans_events_with_ascending_blocks() -> anyhow::Result<()> {
134134

135135
#[tokio::test]
136136
async fn reorg_depth_one() -> anyhow::Result<()> {
137-
let LiveScannerSetup { provider, contract, scanner, mut stream, anvil: _anvil } =
137+
let LiveScannerSetup { provider: _provider, contract, scanner, mut stream, anvil } =
138138
setup_live_scanner(Option::Some(0.1), Option::None, 0).await?;
139139

140140
scanner.start().await?;
@@ -146,7 +146,7 @@ async fn reorg_depth_one() -> anyhow::Result<()> {
146146
let same_block = true;
147147

148148
let expected_event_tx_hashes = reorg_with_new_count_incr_txs(
149-
provider,
149+
anvil,
150150
contract,
151151
num_initial_events,
152152
num_new_events,
@@ -196,7 +196,7 @@ async fn reorg_depth_one() -> anyhow::Result<()> {
196196

197197
#[tokio::test]
198198
async fn reorg_depth_two() -> anyhow::Result<()> {
199-
let LiveScannerSetup { provider, contract, scanner, mut stream, anvil: _anvil } =
199+
let LiveScannerSetup { provider: _provider, contract, scanner, mut stream, anvil } =
200200
setup_live_scanner(Option::Some(0.1), Option::None, 0).await?;
201201

202202
scanner.start().await?;
@@ -208,7 +208,7 @@ async fn reorg_depth_two() -> anyhow::Result<()> {
208208

209209
let same_block = true;
210210
let expected_event_tx_hashes = reorg_with_new_count_incr_txs(
211-
provider,
211+
anvil,
212212
contract,
213213
num_initial_events,
214214
num_new_events,
@@ -260,7 +260,7 @@ async fn reorg_depth_two() -> anyhow::Result<()> {
260260
async fn block_confirmations_mitigate_reorgs() -> anyhow::Result<()> {
261261
// any reorg ≤ 5 should be invisible to consumers
262262
let block_confirmations = 5;
263-
let LiveScannerSetup { provider, contract, scanner, mut stream, anvil: _anvil } =
263+
let LiveScannerSetup { provider, contract, scanner, mut stream, anvil } =
264264
setup_live_scanner(Option::Some(1.0), Option::None, block_confirmations).await?;
265265

266266
scanner.start().await?;
@@ -274,7 +274,7 @@ async fn block_confirmations_mitigate_reorgs() -> anyhow::Result<()> {
274274
let same_block = true;
275275

276276
let all_tx_hashes = reorg_with_new_count_incr_txs(
277-
provider.clone(),
277+
anvil,
278278
contract,
279279
num_initial_events,
280280
num_new_events,

0 commit comments

Comments
 (0)