-
Notifications
You must be signed in to change notification settings - Fork 4
Migrate event scanner tests #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
5f40c94
define block scanner types
0xNeshi 2324ccd
setup basic interface
0xNeshi bb6de81
rename module to block_scanner
0xNeshi 02de8d0
implement event scanner
0xNeshi 4d3c4c2
enable websocket and ipc connections
0xNeshi a6d16aa
remove http, cleanup
LeoPatOZ c058ad9
Merge branch 'main' into channels
LeoPatOZ 3961e75
event channeling
LeoPatOZ 4efba82
Merge branch 'main' into event-channeling
LeoPatOZ 335d4a7
make end height optional
0xNeshi eda1385
Merge branch 'main' into event-channeling
LeoPatOZ e36803a
merge
0xNeshi 5d7f48c
update to use stream
LeoPatOZ 1c67dbb
Merge branch 'main' into event-channeling
LeoPatOZ 40c4cef
lint
LeoPatOZ 4bca02c
assume errors when building block scanner
0xNeshi 238d9c6
implement reorg logic
0xNeshi eb73b49
Merge branch 'main' into event-channeling
LeoPatOZ c54671c
remove comment about placeholder
LeoPatOZ 597d87b
test migration
LeoPatOZ 9f3d72d
add more int tests
LeoPatOZ 19c3c7f
renameing and crate issues
LeoPatOZ 3a51905
update order test
LeoPatOZ e48e119
udpate tests and add block ordering
LeoPatOZ e2f7828
clippy
LeoPatOZ 0fb8d7b
format
LeoPatOZ cafdfb2
Merge branch 'main' into migrate-event-scanner-tests
LeoPatOZ 4e6e580
merge main
0xNeshi 8cd6f30
Block scanner refactor (#21)
0xNeshi 499b683
Merge branch 'block-scanner' into migrate-event-scanner-tests
LeoPatOZ 159c33f
fix test and bug
LeoPatOZ 5e5e8f3
historic test
LeoPatOZ 95109a2
historic to live test
LeoPatOZ eabf88b
remove legacy scanner
LeoPatOZ da70991
fix examples
LeoPatOZ 4dfc202
Merge branch 'block-scanner' into migrate-event-scanner-tests
LeoPatOZ e90556a
fix doc test
LeoPatOZ 1edc9b4
Merge branch 'block-scanner' into migrate-event-scanner-tests
LeoPatOZ 0bc695d
merge
0xNeshi 4a2e569
set timeout on processes_events_within_specified_historical_range test
0xNeshi 7930ab2
set timeout on processes_events_within_specified_historical_range test
0xNeshi 602d78e
make spawn_anvil accept f64
0xNeshi bbf641b
speed up block time in processes_events_within_specified_historical_r…
0xNeshi ee77985
fail_times -> max_fail_times
0xNeshi bd86c5c
fail_times -> max_fail_times
0xNeshi ed22861
change anvil block time to 0.1
0xNeshi 1256f15
optimize high_event_volume_no_loss
0xNeshi f0baad8
make event scanner builder return consume self
0xNeshi b3b5421
make block scanner builder pattern consume self
0xNeshi 39bcf9e
use arc clone convention
0xNeshi 64b122d
use timeout approach to asserting
0xNeshi d117164
use last-attempt assertions with clear msgs on timeouts
0xNeshi 203ddcd
fmt
0xNeshi 552cb13
clippy
0xNeshi 10f5a4a
assert event ordering in replays_historical_then_switches_to_live
0xNeshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| use std::{ | ||
| sync::{ | ||
| Arc, | ||
| atomic::{AtomicU64, AtomicUsize, Ordering}, | ||
| }, | ||
| time::Duration, | ||
| }; | ||
|
|
||
| use alloy::{rpc::types::Log, sol_types::SolEvent}; | ||
| use async_trait::async_trait; | ||
| use event_scanner::EventCallback; | ||
| use tokio::{sync::Mutex, time::sleep}; | ||
|
|
||
| use crate::common::TestCounter; | ||
|
|
||
| pub struct BasicCounterCallback { | ||
| pub count: Arc<AtomicUsize>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventCallback for BasicCounterCallback { | ||
| async fn on_event(&self, _log: &Log) -> anyhow::Result<()> { | ||
| self.count.fetch_add(1, Ordering::SeqCst); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| pub struct SlowProcessorCallback { | ||
| pub delay_ms: u64, | ||
| pub processed: Arc<AtomicUsize>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventCallback for SlowProcessorCallback { | ||
| async fn on_event(&self, _log: &Log) -> anyhow::Result<()> { | ||
| sleep(Duration::from_millis(self.delay_ms)).await; | ||
| self.processed.fetch_add(1, Ordering::SeqCst); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// A callback that fails `max_fail_times` attempts before succeeding once. | ||
| pub struct FlakyCallback { | ||
| pub attempts: Arc<AtomicUsize>, | ||
| pub successes: Arc<AtomicUsize>, | ||
| pub max_fail_times: usize, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventCallback for FlakyCallback { | ||
| async fn on_event(&self, _log: &Log) -> anyhow::Result<()> { | ||
| let attempt = self.attempts.fetch_add(1, Ordering::SeqCst) + 1; | ||
| if attempt <= self.max_fail_times { | ||
| anyhow::bail!("intentional failure on attempt {attempt}"); | ||
| } | ||
| self.successes.fetch_add(1, Ordering::SeqCst); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| // A callback that always fails and records attempts. | ||
| pub struct AlwaysFailingCallback { | ||
| pub attempts: Arc<AtomicU64>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventCallback for AlwaysFailingCallback { | ||
| async fn on_event(&self, _log: &Log) -> anyhow::Result<()> { | ||
| self.attempts.fetch_add(1, Ordering::SeqCst); | ||
| anyhow::bail!("always failing callback") | ||
| } | ||
| } | ||
|
|
||
| // Captures block numbers in the order they are processed. | ||
| pub struct BlockOrderingCallback { | ||
| pub blocks: Arc<Mutex<Vec<u64>>>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventCallback for BlockOrderingCallback { | ||
| async fn on_event(&self, log: &Log) -> anyhow::Result<()> { | ||
| let mut guard = self.blocks.lock().await; | ||
| if let Some(n) = log.block_number { | ||
| guard.push(n); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| // Captures decoded CountIncreased `newCount` values to verify callback/event ordering. | ||
| pub struct EventOrderingCallback { | ||
| pub counts: Arc<Mutex<Vec<u64>>>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventCallback for EventOrderingCallback { | ||
| async fn on_event(&self, log: &Log) -> anyhow::Result<()> { | ||
| if let Some(&TestCounter::CountIncreased::SIGNATURE_HASH) = log.topic0() { | ||
| let TestCounter::CountIncreased { newCount } = log.log_decode()?.inner.data; | ||
| let mut guard = self.counts.lock().await; | ||
| guard.push(newCount.try_into().unwrap()); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loving the event callback approach so far, seems super convenient for testing