Skip to content

Commit

Permalink
test(arbitrary): fix low entropy buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Jan 18, 2025
1 parent 461d276 commit 252a811
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ mod tests {

#[test]
fn test_arbitrary_descriptor() {
// Number of iterations
const N: usize = 1_000;

// Create a buffer of random bytes
let mut data = vec![0u8; 1024];
// 128 bytes would be enough since it is below MAX_OP_RETURN_LEN
let mut data = vec![0u8; N * 128];
OsRng.fill_bytes(&mut data);
let mut u = Unstructured::new(&data);

// Generate several random descriptors
for _ in 0..1_000 {
for _ in 0..N {
if let Ok(desc) = Descriptor::arbitrary(&mut u) {
// Verify type tag is valid
match desc.type_tag() {
Expand All @@ -105,13 +109,17 @@ mod tests {

#[test]
fn test_arbitrary_descriptor_to_address() {
// Number of iterations
const N: usize = 1_000;

// Create a buffer of random bytes
let mut data = vec![0u8; 1024];
// 128 bytes would be enough since it is below MAX_OP_RETURN_LEN
let mut data = vec![0u8; N * 128];
OsRng.fill_bytes(&mut data);
let mut u = Unstructured::new(&data);

// Generate several random descriptors
for _ in 0..1_000 {
for _ in 0..N {
if let Ok(desc) = Descriptor::arbitrary(&mut u) {
// Verify type tag is valid
match desc.type_tag() {
Expand Down

0 comments on commit 252a811

Please sign in to comment.