Skip to content

Commit 7b31806

Browse files
committed
token[-2022]: Add proptest for unpacking (#3421)
1 parent fe4bbbc commit 7b31806

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ thiserror = "1.0"
2323

2424
[dev-dependencies]
2525
lazy_static = "1.4.0"
26+
proptest = "1.0"
2627
serial_test = "0.5.1"
2728
solana-program-test = "1.10.33"
2829
solana-sdk = "1.10.33"

program/src/instruction.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ pub fn is_valid_signer_index(index: usize) -> bool {
14311431

14321432
#[cfg(test)]
14331433
mod test {
1434-
use super::*;
1434+
use {super::*, proptest::prelude::*};
14351435

14361436
#[test]
14371437
fn test_instruction_packing() {
@@ -1674,14 +1674,13 @@ mod test {
16741674
assert_eq!(unpacked, check);
16751675
}
16761676

1677-
#[test]
1678-
fn test_instruction_unpack_panic() {
1679-
for i in 0..255u8 {
1680-
for j in 1..10 {
1681-
let mut data = vec![0; j];
1682-
data[0] = i;
1683-
let _no_panic = TokenInstruction::unpack(&data);
1684-
}
1677+
proptest! {
1678+
#![proptest_config(ProptestConfig::with_cases(1024))]
1679+
#[test]
1680+
fn test_instruction_unpack_panic(
1681+
data in prop::collection::vec(any::<u8>(), 0..255)
1682+
) {
1683+
let _no_panic = TokenInstruction::unpack(&data);
16851684
}
16861685
}
16871686
}

0 commit comments

Comments
 (0)