Skip to content

Commit

Permalink
parse example
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Aug 13, 2024
1 parent 29b68f4 commit 2fb68e6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/dump_slots_stream_samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::env;
use std::time::SystemTime;

use base64::Engine;
use csv::ReaderBuilder;
use itertools::Itertools;
use solana_sdk::borsh0_10::try_from_slice_unchecked;
/// This file mocks the core model of the RPC server.
Expand Down Expand Up @@ -125,3 +126,28 @@ fn slots_all_confirmation_levels() -> SubscribeRequest {
..Default::default()
}
}

#[test]
fn parse_output() {
let data = "283360248,000000000,C,1723558000558";

Check warning on line 132 in examples/dump_slots_stream_samples.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/geyser-grpc-connector/geyser-grpc-connector/examples/dump_slots_stream_samples.rs
let mut rdr = ReaderBuilder::new()
.has_headers(false)
.from_reader(data. as_bytes());

let all_records = rdr.records().collect_vec();
assert_eq!(1, all_records.len());
let record = all_records[0].as_ref().unwrap();

Check warning on line 139 in examples/dump_slots_stream_samples.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/geyser-grpc-connector/geyser-grpc-connector/examples/dump_slots_stream_samples.rs

let slot: u64 = record[0].parse().unwrap();
let parent: Option<u64> = record[1].parse().ok().and_then(|v| if v == 0 { None } else { Some(v) });
let status = match record[2].to_string().as_str() {
"P" => CommitmentLevel::Processed,
"C" => CommitmentLevel::Confirmed,
"F" => CommitmentLevel::Finalized,
_ => panic!("invalid commitment level"),
};

assert_eq!(283360248, slot);
assert_eq!(None, parent);
assert_eq!(CommitmentLevel::Confirmed, status);
}

0 comments on commit 2fb68e6

Please sign in to comment.