Переглянути джерело

token[-2022]: Add proptest for unpacking (#3421)

Jon Cinque 3 роки тому
батько
коміт
7b318065ca
2 змінених файлів з 9 додано та 9 видалено
  1. 1 0
      program/Cargo.toml
  2. 8 9
      program/src/instruction.rs

+ 1 - 0
program/Cargo.toml

@@ -23,6 +23,7 @@ thiserror = "1.0"
 
 [dev-dependencies]
 lazy_static = "1.4.0"
+proptest = "1.0"
 serial_test = "0.5.1"
 solana-program-test = "1.10.33"
 solana-sdk = "1.10.33"

+ 8 - 9
program/src/instruction.rs

@@ -1431,7 +1431,7 @@ pub fn is_valid_signer_index(index: usize) -> bool {
 
 #[cfg(test)]
 mod test {
-    use super::*;
+    use {super::*, proptest::prelude::*};
 
     #[test]
     fn test_instruction_packing() {
@@ -1674,14 +1674,13 @@ mod test {
         assert_eq!(unpacked, check);
     }
 
-    #[test]
-    fn test_instruction_unpack_panic() {
-        for i in 0..255u8 {
-            for j in 1..10 {
-                let mut data = vec![0; j];
-                data[0] = i;
-                let _no_panic = TokenInstruction::unpack(&data);
-            }
+    proptest! {
+        #![proptest_config(ProptestConfig::with_cases(1024))]
+        #[test]
+        fn test_instruction_unpack_panic(
+            data in prop::collection::vec(any::<u8>(), 0..255)
+        ) {
+            let _no_panic = TokenInstruction::unpack(&data);
         }
     }
 }