Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit d7f352b

Browse files
authored
token[-2022]: Add proptest for unpacking (#3421)
1 parent 4aa529d commit d7f352b

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/program-2022/src/instruction.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ pub(crate) fn encode_instruction<T: Into<u8>, D: Pod>(
17871787

17881788
#[cfg(test)]
17891789
mod test {
1790-
use super::*;
1790+
use {super::*, proptest::prelude::*};
17911791

17921792
#[test]
17931793
fn test_instruction_packing() {
@@ -2284,4 +2284,14 @@ mod test {
22842284
ui_amount,
22852285
));
22862286
}
2287+
2288+
proptest! {
2289+
#![proptest_config(ProptestConfig::with_cases(1024))]
2290+
#[test]
2291+
fn test_instruction_unpack_panic(
2292+
data in prop::collection::vec(any::<u8>(), 0..255)
2293+
) {
2294+
let _no_panic = TokenInstruction::unpack(&data);
2295+
}
2296+
}
22872297
}

token/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"

token/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)