Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Move some `Arbitrary` impls out of `test` module into `arbitrary` module 
For example, `ergo_lib::chain::transaction::Transaction`. Currently an external user is prevented from generating `Transaction` instances with `proptest`.


Discussion / hints:
💯 agree! 

Fix patch:
diff --git a/ergo-lib/src/chain/transaction.rs b/ergo-lib/src/chain/transaction.rs
index 20ad333e1..39209b94d 100644
--- a/ergo-lib/src/chain/transaction.rs
+++ b/ergo-lib/src/chain/transaction.rs
@@ -318,13 +318,12 @@ pub enum TransactionError {
     InvalidDataInputsCount(bounded_vec::BoundedVecOutOfBounds),
 }
 
-#[cfg(test)]
-#[allow(clippy::unwrap_used, clippy::panic)]
-pub mod tests {
+/// Arbitrary impl
+#[cfg(feature = "arbitrary")]
+#[allow(clippy::unwrap_used)]
+pub mod arbitrary {
 
     use super::*;
-
-    use ergotree_ir::serialization::sigma_serialize_roundtrip;
     use proptest::prelude::*;
     use proptest::{arbitrary::Arbitrary, collection::vec};
 
@@ -344,6 +343,16 @@ pub mod tests {
         }
         type Strategy = BoxedStrategy<Self>;
     }
+}
+
+#[cfg(test)]
+#[allow(clippy::unwrap_used, clippy::panic)]
+pub mod tests {
+
+    use super::*;
+
+    use ergotree_ir::serialization::sigma_serialize_roundtrip;
+    use proptest::prelude::*;
 
     proptest! {
 
diff --git a/ergo-lib/src/chain/transaction/data_input.rs b/ergo-lib/src/chain/transaction/data_input.rs
index 2a0d5376b..f3d7672a1 100644
--- a/ergo-lib/src/chain/transaction/data_input.rs
+++ b/ergo-lib/src/chain/transaction/data_input.rs
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
 
 /// Inputs, that are used to enrich script context, but won't be spent by the transaction
 #[derive(PartialEq, Eq, Debug, Clone)]
-#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
+#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
 #[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
 pub struct DataInput {
     /// id of the box to add into context (should be in UTXO)
diff --git a/ergo-lib/src/chain/transaction/input.rs b/ergo-lib/src/chain/transaction/input.rs
index 83951df1b..c28d34b5e 100644
--- a/ergo-lib/src/chain/transaction/input.rs
+++ b/ergo-lib/src/chain/transaction/input.rs
@@ -23,7 +23,7 @@ use self::prover_result::ProverResult;
 
 /// Unsigned (without proofs) transaction input
 #[derive(PartialEq, Eq, Debug, Clone)]
-#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
+#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
 #[cfg_attr(feature = "json", derive(Deserialize))]
 pub struct UnsignedInput {
     /// id of the box to spent
@@ -69,7 +69,7 @@ impl<T: ErgoBoxId> From<T> for UnsignedInput {
 
 /// Fully signed transaction input
 #[derive(PartialEq, Eq, Debug, Clone)]
-#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
+#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
 #[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
 pub struct Input {
     /// id of the box to spent
diff --git a/ergo-lib/src/chain/transaction/input/prover_result.rs b/ergo-lib/src/chain/transaction/input/prover_result.rs
index 00e7b60cf..00e8af2ec 100644
--- a/ergo-lib/src/chain/transaction/input/prover_result.rs
+++ b/ergo-lib/src/chain/transaction/input/prover_result.rs
@@ -73,11 +73,10 @@ impl SigmaSerializable for ProverResult {
     }
 }
 
-#[cfg(test)]
-#[allow(clippy::panic)]
-mod tests {
+/// Arbitrary impls
+#[cfg(feature = "arbitrary")]
+pub mod arbitrary {
     use super::*;
-    use ergotree_ir::serialization::sigma_serialize_roundtrip;
     use proptest::prelude::*;
 
     impl Arbitrary for ProverResult {
@@ -90,6 +89,14 @@ mod tests {
                 .boxed()
         }
     }
+}
+
+#[cfg(test)]
+#[allow(clippy::panic)]
+mod tests {
+    use super::*;
+    use ergotree_ir::serialization::sigma_serialize_roundtrip;
+    use proptest::prelude::*;
 
     proptest! {
 
diff --git a/ergo-lib/src/chain/transaction/reduced.rs b/ergo-lib/src/chain/transaction/reduced.rs
index 57f427dd8..fd5267058 100644
--- a/ergo-lib/src/chain/transaction/reduced.rs
+++ b/ergo-lib/src/chain/transaction/reduced.rs
@@ -144,12 +144,11 @@ impl SigmaSerializable for ReducedTransaction {
     }
 }
 
-#[cfg(test)]
-#[allow(clippy::panic)]
-mod tests {
+/// Arbitrary impl
+#[cfg(feature = "arbitrary")]
+pub mod arbitrary {
     use super::*;
 
-    use ergotree_ir::serialization::sigma_serialize_roundtrip;
     use proptest::prelude::*;
 
     impl Arbitrary for ReducedTransaction {
@@ -176,6 +175,15 @@ mod tests {
         }
         type Strategy = BoxedStrategy<Self>;
     }
+}
+
+#[cfg(test)]
+#[allow(clippy::panic)]
+mod tests {
+    use super::*;
+
+    use ergotree_ir::serialization::sigma_serialize_roundtrip;
+    use proptest::prelude::*;
 
     proptest! {
 
diff --git a/ergo-lib/src/chain/transaction/unsigned.rs b/ergo-lib/src/chain/transaction/unsigned.rs
index ac8ee4152..2eca6439e 100644
--- a/ergo-lib/src/chain/transaction/unsigned.rs
+++ b/ergo-lib/src/chain/transaction/unsigned.rs
@@ -120,9 +120,10 @@ impl UnsignedTransaction {
     }
 }
 
-#[cfg(test)]
-#[allow(clippy::unwrap_used, clippy::panic)]
-pub mod tests {
+/// Arbitrary impl
+#[cfg(feature = "arbitrary")]
+#[allow(clippy::unwrap_used)]
+pub mod arbitrary {
     use super::*;
 
     use proptest::prelude::*;
@@ -144,6 +145,14 @@ pub mod tests {
         }
         type Strategy = BoxedStrategy<Self>;
     }
+}
+
+#[cfg(test)]
+#[allow(clippy::unwrap_used, clippy::panic)]
+pub mod tests {
+    use super::*;
+
+    use proptest::prelude::*;
 
     proptest! {
 
diff --git a/ergotree-ir/src/mir/apply.rs b/ergotree-ir/src/mir/apply.rs
index ffb8b5224..60ec67788 100644
--- a/ergotree-ir/src/mir/apply.rs
+++ b/ergotree-ir/src/mir/apply.rs
@@ -71,13 +71,11 @@ impl SigmaSerializable for Apply {
     }
 }
 
-#[cfg(test)]
-#[allow(clippy::panic)]
+/// Arbitrary impl
+#[cfg(feature = "arbitrary")]
 #[allow(clippy::unwrap_used)]
-mod tests {
-
+pub mod arbitrary {
     use crate::mir::func_value::*;
-    use crate::serialization::sigma_serialize_roundtrip;
 
     use super::*;
 
@@ -107,6 +105,18 @@ mod tests {
                 .boxed()
         }
     }
+}
+
+#[cfg(test)]
+#[allow(clippy::panic)]
+#[allow(clippy::unwrap_used)]
+mod tests {
+
+    use crate::serialization::sigma_serialize_roundtrip;
+
+    use super::*;
+
+    use proptest::prelude::*;
 
     proptest! {
 


Test patch: