mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
Fix #612
This commit is contained in:
parent
2e57168a97
commit
23b433fe6c
2 changed files with 13 additions and 7 deletions
|
@ -302,7 +302,8 @@ impl Extra {
|
||||||
// `fill_buf` returns the current buffer, filled if empty, only empty if the reader is
|
// `fill_buf` returns the current buffer, filled if empty, only empty if the reader is
|
||||||
// exhausted
|
// exhausted
|
||||||
while !r.fill_buf()?.is_empty() {
|
while !r.fill_buf()?.is_empty() {
|
||||||
res.0.push(ExtraField::read(r)?);
|
let Ok(field) = ExtraField::read(r) else { break };
|
||||||
|
res.0.push(field);
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
// Tests derived from
|
// Tests derived from
|
||||||
// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/
|
// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/
|
||||||
// tests/unit_tests/test_tx_utils.cpp
|
// tests/unit_tests/test_tx_utils.cpp
|
||||||
// which is licensed
|
// which is licensed as follows:
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2014-2022, The Monero Project
|
Copyright (c) 2014-2022, The Monero Project
|
||||||
|
@ -105,13 +105,15 @@ fn padding_only_max_size() {
|
||||||
#[test]
|
#[test]
|
||||||
fn padding_only_exceed_max_size() {
|
fn padding_only_exceed_max_size() {
|
||||||
let buf: Vec<u8> = vec![0; MAX_TX_EXTRA_PADDING_COUNT + 1];
|
let buf: Vec<u8> = vec![0; MAX_TX_EXTRA_PADDING_COUNT + 1];
|
||||||
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
|
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
|
||||||
|
assert!(extra.0.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_padding_only() {
|
fn invalid_padding_only() {
|
||||||
let buf: Vec<u8> = vec![0, 42];
|
let buf: Vec<u8> = vec![0, 42];
|
||||||
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
|
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
|
||||||
|
assert!(extra.0.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -135,7 +137,8 @@ fn extra_nonce_only_wrong_size() {
|
||||||
let mut buf: Vec<u8> = vec![0; 20];
|
let mut buf: Vec<u8> = vec![0; 20];
|
||||||
buf[0] = 2;
|
buf[0] = 2;
|
||||||
buf[1] = 255;
|
buf[1] = 255;
|
||||||
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
|
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
|
||||||
|
assert!(extra.0.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -155,7 +158,8 @@ fn pub_key_and_padding() {
|
||||||
fn pub_key_and_invalid_padding() {
|
fn pub_key_and_invalid_padding() {
|
||||||
let mut buf: Vec<u8> = PUB_KEY_BYTES.to_vec();
|
let mut buf: Vec<u8> = PUB_KEY_BYTES.to_vec();
|
||||||
buf.extend([0, 1]);
|
buf.extend([0, 1]);
|
||||||
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
|
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
|
||||||
|
assert_eq!(extra.0, vec![ExtraField::PublicKey(pub_key())]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -181,7 +185,8 @@ fn extra_mysterious_minergate_only_wrong_size() {
|
||||||
let mut buf: Vec<u8> = vec![0; 20];
|
let mut buf: Vec<u8> = vec![0; 20];
|
||||||
buf[0] = 222;
|
buf[0] = 222;
|
||||||
buf[1] = 255;
|
buf[1] = 255;
|
||||||
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
|
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
|
||||||
|
assert!(extra.0.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue