Skip to content

Commit 649a33e

Browse files
committed
move testing utilities to their own modules
1 parent a7b9193 commit 649a33e

File tree

4 files changed

+17
-47
lines changed

4 files changed

+17
-47
lines changed

contrib/clarity-serialization/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,13 @@ pub enum CodecError {
117117
#[error("An unexpected internal error occurred: {0}")]
118118
Expect(String),
119119
}
120+
121+
// Implement PartialEq for testing and simple equality checks by comparing the
122+
// string representations of each error. This avoids requiring all wrapped
123+
// fields (like `std::io::Error`) to implement PartialEq.
124+
#[cfg(any(test, feature = "testing"))]
125+
impl PartialEq for CodecError {
126+
fn eq(&self, other: &Self) -> bool {
127+
self.to_string() == other.to_string()
128+
}
129+
}

contrib/clarity-serialization/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub use errors::CodecError;
3232
pub use representations::{ClarityName, ContractName};
3333
pub use types::Value;
3434

35-
#[cfg(any(test, feature = "testing"))]
35+
#[cfg(test)]
3636
pub mod tests;
3737

3838
// set via _compile-time_ envars

contrib/clarity-serialization/src/tests/mod.rs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,7 @@
1515
mod representations;
1616
mod types;
1717

18-
use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG};
19-
use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey};
20-
21-
use crate::errors::CodecError;
22-
use crate::types::{PrincipalData, StandardPrincipalData, Value};
23-
use crate::{version_string, BUILD_TYPE};
24-
25-
impl Value {
26-
pub fn list_from(list_data: Vec<Value>) -> Result<Value, CodecError> {
27-
Value::cons_list_unsanitized(list_data)
28-
}
29-
}
30-
31-
// Implement PartialEq for testing and simple equality checks by comparing the
32-
// string representations of each error. This avoids requiring all wrapped
33-
// fields (like `std::io::Error`) to implement PartialEq.
34-
impl PartialEq for CodecError {
35-
fn eq(&self, other: &Self) -> bool {
36-
self.to_string() == other.to_string()
37-
}
38-
}
39-
40-
impl From<&StacksPrivateKey> for StandardPrincipalData {
41-
fn from(o: &StacksPrivateKey) -> StandardPrincipalData {
42-
let stacks_addr = StacksAddress::from_public_keys(
43-
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
44-
&AddressHashMode::SerializeP2PKH,
45-
1,
46-
&vec![StacksPublicKey::from_private(o)],
47-
)
48-
.unwrap();
49-
StandardPrincipalData::from(stacks_addr)
50-
}
51-
}
52-
53-
impl From<&StacksPrivateKey> for PrincipalData {
54-
fn from(o: &StacksPrivateKey) -> PrincipalData {
55-
PrincipalData::Standard(StandardPrincipalData::from(o))
56-
}
57-
}
58-
59-
impl From<&StacksPrivateKey> for Value {
60-
fn from(o: &StacksPrivateKey) -> Value {
61-
Value::from(StandardPrincipalData::from(o))
62-
}
63-
}
18+
use crate::{BUILD_TYPE, version_string};
6419

6520
#[test]
6621
fn test_version_string_basic_no_env() {

contrib/clarity-serialization/src/types/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,11 @@ impl Value {
860860
})))
861861
}
862862

863+
#[cfg(any(test, feature = "testing"))]
864+
pub fn list_from(list_data: Vec<Value>) -> Result<Value, CodecError> {
865+
Value::cons_list_unsanitized(list_data)
866+
}
867+
863868
pub fn cons_list(list_data: Vec<Value>, epoch: &StacksEpochId) -> Result<Value, CodecError> {
864869
// Constructors for TypeSignature ensure that the size of the Value cannot
865870
// be greater than MAX_VALUE_SIZE (they error on such constructions)

0 commit comments

Comments
 (0)