fix(network): handle end of list in tx monitor response (#305)

This commit is contained in:
teebaumcrypto 2024-06-29 20:08:16 +02:00 committed by GitHub
parent b07f88459c
commit d12fe799eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -80,14 +80,19 @@ impl<'b> Decode<'b, ()> for Message {
// find the specs
4 => Ok(Message::AwaitAcquire),
5 => Ok(Message::RequestNextTx),
6 => match d.datatype()? {
pallas_codec::minicbor::data::Type::Array
| pallas_codec::minicbor::data::Type::ArrayIndef => {
let tx = d.decode()?;
Ok(Message::ResponseNextTx(Some(tx)))
}
_ => Ok(Message::ResponseNextTx(None)),
},
6 => match d.datatype() {
Ok(datatype) => {
match datatype {
pallas_codec::minicbor::data::Type::Array
| pallas_codec::minicbor::data::Type::ArrayIndef => {
let tx = d.decode()?;
Ok(Message::ResponseNextTx(Some(tx)))
}
_ => Ok(Message::ResponseNextTx(None))
}
},
Err(_) => Ok(Message::ResponseNextTx(None))
}
7 => {
let id = d.decode()?;
Ok(Message::RequestHasTx(id))
@ -130,4 +135,15 @@ pub mod tests {
unreachable!();
}
}
#[test]
fn test_empty_next_tx_response() {
let bytes = vec![129, 6];
let msg: super::Message = pallas_codec::minicbor::decode(&bytes).unwrap();
if let super::Message::ResponseNextTx(None) = msg {
assert_eq!(0u64, 0u64);
} else {
unreachable!();
}
}
}