Skip to content

Commit

Permalink
setup debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jul 24, 2024
1 parent 2fe8753 commit 884a78b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 73 deletions.
87 changes: 14 additions & 73 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions ferveo/gistfile1.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ferveo/gistfile1.txt

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions ferveo/parse.py

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions ferveo/src/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use std::{
fs::File,
io::{self, BufRead},
path::PathBuf,
};

use hex::FromHex;

#[derive(Debug)]
struct ValidatorTranscript {
validator_address: String,
validator_pk: Vec<u8>,
transcript: Vec<u8>,
}

fn parse_file(file_path: &PathBuf) -> io::Result<Vec<ValidatorTranscript>> {
let mut records = Vec::new();

let file = File::open(file_path)?;
let reader = io::BufReader::new(file);

for line in reader.lines() {
let line = line?;
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() != 3 {
eprintln!("Invalid line: {line}");
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Invalid line",
));
}

let validator_address = parts[0].to_string();
let validator_pk = Vec::from_hex(parts[1])
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
let transcript = Vec::from_hex(parts[2])
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;

if validator_address.len() != 42 {
eprintln!(
"Invalid validator_address length: {}",
validator_address.len()
);
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Invalid validator_address length",
));
}
if validator_pk.len() != 96 {
eprintln!("Invalid validator_pk length: {}", validator_pk.len());
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Invalid validator_pk length",
));
}
if transcript.len() != 3784 {
eprintln!("Invalid transcript length: {}", transcript.len());
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Invalid transcript length",
));
}

records.push(ValidatorTranscript {
validator_address,
validator_pk,
transcript,
});
}

Ok(records)
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_parse_file() {
let filename = "gistfile1.csv";
let file_path =
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(filename);
let records = parse_file(&file_path).unwrap();
assert_eq!(records.len(), 30);
}
}
2 changes: 2 additions & 0 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod pvss;
pub mod refresh;
pub mod validator;

#[cfg(test)]
mod debug;
#[cfg(test)]
mod test_common;

Expand Down

0 comments on commit 884a78b

Please sign in to comment.