mod file_io;
fn parse_replay(lines: &'static str) -> Vec<(Vec<u8>, Vec<u8>)> {
lines
.lines()
.map(|v| {
let [tx, rx] = v
.splitn(2, ' ')
.map(|v| hex::decode(v).unwrap())
.collect::<Vec<_>>()
.try_into()
.unwrap();
(tx, rx)
})
.collect()
}
macro_rules! replay {
($name:ident, $path:literal, |$card:ident| $body:tt) => {
#[tokio::test]
async fn $name() {
const REPLAY: &str = include_str!($path);
let transcript = $crate::replay::parse_replay(REPLAY);
let transcript = transcript
.iter()
.map(|(tx, rx)| (tx.as_slice(), rx.as_slice()))
.collect::<Vec<_>>();
let backend = $crate::io::MockBackend::new(&transcript);
let $card = $crate::Card::new(&backend);
$body
}
};
}
pub(crate) use replay;