-
Notifications
You must be signed in to change notification settings - Fork 176
tests(solana-indexer) PR 5.2: Add unit tests for solana-indexer ingester component
#4550
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
Open
tilacog
wants to merge
7
commits into
solana-indexer/PR5.1-bootstrap
Choose a base branch
from
solana-indexer-PR5.2-bootstrap
base: solana-indexer/PR5.1-bootstrap
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+223
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75a0c75
Add simple unit tests for solana-indexer ingester
tilacog b107847
fix: bump quinn-proto to 0.11.15 (RUSTSEC-2026-0185)
tilacog 083dded
Merge remote-tracking branch 'origin/solana-indexer/PR5.1-bootstrap' …
squadgazzz 852275f
test(solana-indexer): pass arrays to stream::iter instead of vec!
squadgazzz fef46d6
Merge branch 'solana-indexer/PR5.1-bootstrap' into solana-indexer-PR5…
squadgazzz c035b32
Merge branch 'solana-indexer/PR5.1-bootstrap' into solana-indexer-PR5…
squadgazzz 04d5de8
Merge branch 'solana-indexer/PR5.1-bootstrap' into solana-indexer-PR5…
squadgazzz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -401,3 +401,6 @@ fn subscribe_request( | |
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; | ||
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,215 @@ | ||
| use { | ||
| super::{Error, INGEST_TO_DECODER_CAPACITY, Ingester}, | ||
| crate::types::{ | ||
| Signature, | ||
| shared::StreamUpdate, | ||
| slot::Slot, | ||
| wire::{ | ||
| SubscribeUpdate, | ||
| SubscribeUpdateAccount, | ||
| SubscribeUpdateAccountInfo, | ||
| SubscribeUpdateBlock, | ||
| SubscribeUpdateBlockMeta, | ||
| SubscribeUpdateEntry, | ||
| SubscribeUpdatePing, | ||
| SubscribeUpdatePong, | ||
| SubscribeUpdateSlot, | ||
| SubscribeUpdateTransaction, | ||
| SubscribeUpdateTransactionInfo, | ||
| SubscribeUpdateTransactionStatus, | ||
| UpdateOneof, | ||
| }, | ||
| }, | ||
| futures::stream, | ||
| std::sync::{ | ||
| Arc, | ||
| atomic::{AtomicU64, Ordering}, | ||
| }, | ||
| tokio::sync::mpsc::channel, | ||
| yellowstone_grpc_proto::tonic::Status, | ||
| }; | ||
|
|
||
| fn signature(n: u8) -> Signature { | ||
| Signature::from([n; 64]) | ||
| } | ||
|
|
||
| fn signature_bytes(n: u8) -> Vec<u8> { | ||
| signature(n).as_ref().to_vec() | ||
| } | ||
|
|
||
| fn tx_update(slot: u64, sig: u8) -> Result<SubscribeUpdate, Status> { | ||
| Ok(SubscribeUpdate { | ||
| update_oneof: Some(UpdateOneof::Transaction(SubscribeUpdateTransaction { | ||
| slot, | ||
| transaction: Some(SubscribeUpdateTransactionInfo { | ||
| signature: signature_bytes(sig), | ||
| ..Default::default() | ||
| }), | ||
| })), | ||
| ..Default::default() | ||
| }) | ||
| } | ||
|
|
||
| fn account_update(slot: u64, sig: u8) -> Result<SubscribeUpdate, Status> { | ||
| Ok(SubscribeUpdate { | ||
| update_oneof: Some(UpdateOneof::Account(SubscribeUpdateAccount { | ||
| slot, | ||
| account: Some(SubscribeUpdateAccountInfo { | ||
| txn_signature: Some(signature_bytes(sig)), | ||
| ..Default::default() | ||
| }), | ||
| ..Default::default() | ||
| })), | ||
| ..Default::default() | ||
| }) | ||
| } | ||
|
|
||
| fn slot_update(slot: u64) -> Result<SubscribeUpdate, Status> { | ||
| Ok(SubscribeUpdate { | ||
| update_oneof: Some(UpdateOneof::Slot(SubscribeUpdateSlot { | ||
| slot, | ||
| ..Default::default() | ||
| })), | ||
| ..Default::default() | ||
| }) | ||
| } | ||
|
|
||
| fn update_of(update: UpdateOneof) -> Result<SubscribeUpdate, Status> { | ||
| Ok(SubscribeUpdate { | ||
| update_oneof: Some(update), | ||
| ..Default::default() | ||
| }) | ||
| } | ||
|
|
||
| fn ingester( | ||
| stream: impl stream::Stream<Item = Result<SubscribeUpdate, Status>> + Unpin + Send, | ||
| ) -> ( | ||
| Ingester<impl stream::Stream<Item = Result<SubscribeUpdate, Status>> + Unpin + Send>, | ||
| tokio::sync::mpsc::Receiver<StreamUpdate>, | ||
| Arc<AtomicU64>, | ||
| ) { | ||
| let (tx, rx) = channel(INGEST_TO_DECODER_CAPACITY); | ||
| let latest_chain_slot = Arc::new(AtomicU64::new(0)); | ||
| ( | ||
| Ingester::new(stream, tx, latest_chain_slot.clone()), | ||
| rx, | ||
| latest_chain_slot, | ||
| ) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn transaction_update_with_valid_signature_is_forwarded() { | ||
| let signature = signature(1); | ||
| let (mut ingester, mut rx, _) = ingester(stream::iter([tx_update(42, 1)])); | ||
|
|
||
| assert!(matches!(ingester.run().await, Err(Error::StreamEnded))); | ||
| let update = rx.recv().await.unwrap(); | ||
| assert!( | ||
| matches!(update, StreamUpdate::Tx { slot: Slot(42), signature: s, .. } if s == signature) | ||
| ); | ||
| assert!(rx.is_empty()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn account_update_with_body_is_forwarded() { | ||
| let signature = signature(2); | ||
| let (mut ingester, mut rx, _) = ingester(stream::iter([account_update(100, 2)])); | ||
|
|
||
| assert!(matches!(ingester.run().await, Err(Error::StreamEnded))); | ||
| let update = rx.recv().await.unwrap(); | ||
| assert!( | ||
| matches!(update, StreamUpdate::Account { slot: Slot(100), txn_signature: Some(s), .. } if s == signature) | ||
| ); | ||
| assert!(rx.is_empty()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn slot_update_advances_latest_chain_slot() { | ||
| let (mut ingester, _rx, slot) = ingester(stream::iter([slot_update(9_001)])); | ||
|
|
||
| assert!(matches!(ingester.run().await, Err(Error::StreamEnded))); | ||
| assert_eq!(slot.load(Ordering::Relaxed), 9_001); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn unrelated_and_empty_updates_are_ignored() { | ||
| let (mut ingester, mut rx, slot) = ingester(stream::iter([ | ||
| Ok(SubscribeUpdate::default()), | ||
| update_of(UpdateOneof::Ping(SubscribeUpdatePing::default())), | ||
| update_of(UpdateOneof::Pong(SubscribeUpdatePong::default())), | ||
| update_of(UpdateOneof::TransactionStatus( | ||
| SubscribeUpdateTransactionStatus::default(), | ||
| )), | ||
| update_of(UpdateOneof::Block(SubscribeUpdateBlock::default())), | ||
| update_of(UpdateOneof::BlockMeta(SubscribeUpdateBlockMeta::default())), | ||
| update_of(UpdateOneof::Entry(SubscribeUpdateEntry::default())), | ||
| tx_update(7, 3), | ||
| ])); | ||
|
|
||
| assert!(matches!(ingester.run().await, Err(Error::StreamEnded))); | ||
| let update = rx.recv().await.unwrap(); | ||
| assert!( | ||
| matches!(update, StreamUpdate::Tx { slot: Slot(7), signature: s, .. } if s == signature(3)) | ||
| ); | ||
| assert!(rx.is_empty()); | ||
| assert_eq!(slot.load(Ordering::Relaxed), 0); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn transaction_without_body_or_malformed_signature_is_skipped() { | ||
| let signature = signature(4); | ||
| let (mut ingester, mut rx, _) = ingester(stream::iter([ | ||
| Ok(SubscribeUpdate { | ||
| update_oneof: Some(UpdateOneof::Transaction(SubscribeUpdateTransaction { | ||
| slot: 1, | ||
| transaction: None, | ||
| })), | ||
| ..Default::default() | ||
| }), | ||
| Ok(SubscribeUpdate { | ||
| update_oneof: Some(UpdateOneof::Transaction(SubscribeUpdateTransaction { | ||
| slot: 2, | ||
| transaction: Some(SubscribeUpdateTransactionInfo { | ||
| signature: vec![1, 2, 3], | ||
| ..Default::default() | ||
| }), | ||
| })), | ||
| ..Default::default() | ||
| }), | ||
| tx_update(3, 4), | ||
| ])); | ||
|
|
||
| assert!(matches!(ingester.run().await, Err(Error::StreamEnded))); | ||
| let update = rx.recv().await.unwrap(); | ||
| assert!( | ||
| matches!(update, StreamUpdate::Tx { slot: Slot(3), signature: s, .. } if s == signature) | ||
| ); | ||
| assert!(rx.is_empty()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn terminal_grpc_status_returns_stream_error() { | ||
| let status = Status::invalid_argument("boom"); | ||
| let (mut ingester, _rx, _) = ingester(stream::iter([Err(status.clone())])); | ||
|
|
||
| let result = ingester.run().await; | ||
| assert!( | ||
| matches!(result, Err(Error::Stream(s)) if s.code() == status.code() && s.message() == status.message()) | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn clean_stream_end_returns_stream_ended() { | ||
| let (mut ingester, _rx, _) = | ||
| ingester(stream::iter(Vec::<Result<SubscribeUpdate, Status>>::new())); | ||
|
|
||
| assert!(matches!(ingester.run().await, Err(Error::StreamEnded))); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn closed_decoder_receiver_stops_cleanly() { | ||
| let (mut ingester, rx, _) = ingester(stream::iter([tx_update(1, 5)])); | ||
| drop(rx); | ||
|
|
||
| assert!(ingester.run().await.is_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.
This is (most likely) not a valid signature which is a good indicator that this should use a proper new type to encode things like the size requirements of a signature.
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.
The size requirement is already enforced, no?
Signaturehere issolana_sdk::Signature, a[u8; 64]newtype, andSignature::try_fromrejects anything that isn't 64 bytes. Thatvec![1, 2, 3]is the proto wire field, and this test exists to prove we reject it at the boundary. A crate-local wrapper would just forward to the same check, so it'd add indirection without new validation.