Skip to content

Commit 5407708

Browse files
committed
add copyright heading to tests. fix moved tests
1 parent dc962b2 commit 5407708

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
//
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
mod representations;
1516
mod types;
1617

1718
use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG};
1819
use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey};
1920

2021
use crate::errors::CodecError;
2122
use crate::types::{PrincipalData, StandardPrincipalData, Value};
22-
use crate::{BUILD_TYPE, version_string};
23+
use crate::{version_string, BUILD_TYPE};
2324

2425
impl Value {
2526
pub fn list_from(list_data: Vec<Value>) -> Result<Value, CodecError> {

contrib/clarity-serialization/src/tests/types/representations.rs renamed to contrib/clarity-serialization/src/tests/representations.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
// Copyright (C) 2025 Stacks Open Internet Foundation
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
115
use std::io::Read;
216

317
use test_case::test_case;
418

519
use crate::errors::CodecError;
620
use crate::representations::{
7-
CONTRACT_MAX_NAME_LENGTH, CONTRACT_MIN_NAME_LENGTH, ClarityName, ContractName, MAX_STRING_LEN,
21+
ClarityName, ContractName, CONTRACT_MAX_NAME_LENGTH, CONTRACT_MIN_NAME_LENGTH, MAX_STRING_LEN,
822
};
923
use crate::stacks_common::codec::StacksMessageCodec;
1024

@@ -80,13 +94,6 @@ fn test_clarity_name_serialization(name: &str) {
8094
assert_eq!(deserialized, name);
8195
}
8296

83-
#[test]
84-
fn test_clarity_name_serialization_too_long() {
85-
// This test can't be implemented with the current API since
86-
// ClarityName::try_from would reject oversized strings
87-
// and we can't construct invalid ClarityName instances directly
88-
}
89-
9097
// the first byte is the length of the buffer.
9198
#[test_case(vec![4, 0xFF, 0xFE, 0xFD, 0xFC].as_slice(), "Failed to parse Clarity name: could not contruct from utf8"; "invalid_utf8")]
9299
#[test_case(vec![2, b'2', b'i'].as_slice(), "Failed to parse Clarity name: InvalidClarityName(\"ClarityName\", \"2i\")"; "invalid_name")] // starts with number
@@ -138,6 +145,7 @@ fn test_contract_name_valid(name: &str) {
138145
#[test_case("hello}world"; "contains_curly_close")]
139146
#[test_case("hello(world"; "contains_parenthesis_open")]
140147
#[test_case("hello)world"; "contains_parenthesis_close")]
148+
#[test_case(&"a".repeat(CONTRACT_MIN_NAME_LENGTH - 1); "too_short")]
141149
#[test_case(&"a".repeat(MAX_STRING_LEN as usize + 1); "too_long")]
142150
fn test_contract_name_invalid(name: &str) {
143151
let result = ContractName::try_from(name.to_string());
@@ -168,13 +176,19 @@ fn test_contract_name_serialization(name: &str) {
168176
assert_eq!(deserialized, name);
169177
}
170178

171-
#[test_case(&"a".repeat(CONTRACT_MIN_NAME_LENGTH - 1); "too_short")]
172179
#[test_case(&"a".repeat(CONTRACT_MAX_NAME_LENGTH + 1); "too_long")]
173-
#[test_case(&"a".repeat(MAX_STRING_LEN as usize); "max_string_len")]
174-
fn test_contract_name_serialization_too_long_or_short(_name: &str) {
175-
// This test can't be implemented with the current API since
176-
// ContractName::try_from would reject invalid strings
177-
// and we can't construct invalid ContractName instances directly
180+
fn test_contract_name_serialization_too_long_or_short(name: &str) {
181+
let name = ContractName::try_from(name.to_string()).expect("should parse");
182+
let mut buffer = Vec::with_capacity((name.len() + 1) as usize);
183+
let result = name.consensus_serialize(&mut buffer);
184+
assert!(result.is_err());
185+
assert_eq!(
186+
result.unwrap_err().to_string(),
187+
format!(
188+
"Failed to serialize contract name: too short or too long: {}",
189+
name.len()
190+
)
191+
);
178192
}
179193

180194
// the first byte is the length of the buffer.

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
mod representations;
1+
// Copyright (C) 2025 Stacks Open Internet Foundation
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
215
mod serialization;
316
mod signatures;
417

518
use stacks_common::types::StacksEpochId;
619

7-
use crate::CodecError;
820
use crate::types::{
9-
BuffData, ListTypeData, MAX_VALUE_SIZE, PrincipalData, SequenceData, TupleData, TypeSignature,
10-
Value,
21+
BuffData, ListTypeData, PrincipalData, SequenceData, TupleData, TypeSignature, Value,
22+
MAX_VALUE_SIZE,
1123
};
24+
use crate::CodecError;
1225

1326
#[test]
1427
fn test_constructors() {

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright (C) 2025 Stacks Open Internet Foundation
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
115
use std::io::Write;
216

317
use crate::errors::CodecError;
@@ -163,6 +177,7 @@ fn test_string_ascii() {
163177

164178
#[test]
165179
fn test_string_utf8() {
180+
test_deser_ser(Value::string_utf8_from_bytes(vec![61, 62, 63, 64]).unwrap());
166181
test_deser_ser(Value::string_utf8_from_bytes(vec![61, 62, 63, 240, 159, 164, 151]).unwrap());
167182
}
168183
#[test]
@@ -275,8 +290,8 @@ fn test_vectors() {
275290
Ok(StandardPrincipalData::new(
276291
0x00,
277292
[
278-
0x11, 0xde, 0xad, 0xbe, 0xef, 0x11, 0xab, 0xab, 0xff, 0xff, 0x11, 0xde, 0xad,
279-
0xbe, 0xef, 0x11, 0xab, 0xab, 0xff, 0xff,
293+
0x11, 0xde, 0xad, 0xbe, 0xef, 0x11, 0xab, 0xab, 0xff, 0xff, 0x11, 0xde,
294+
0xad, 0xbe, 0xef, 0x11, 0xab, 0xab, 0xff, 0xff,
280295
],
281296
)
282297
.unwrap()

contrib/clarity-serialization/src/tests/types/signatures.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
// Copyright (C) 2025 Stacks Open Internet Foundation
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
115
use std::collections::HashSet;
216

317
use crate::errors::CodecError;
4-
// Import all TypeSignature variants
5-
use crate::types::TypeSignature::{BoolType, IntType, ListUnionType, UIntType};
618
use crate::types::signatures::{CallableSubtype, TypeSignature};
19+
use crate::types::TypeSignature::{BoolType, IntType, ListUnionType, UIntType};
720
use crate::types::{
821
QualifiedContractIdentifier, SequenceSubtype, TraitIdentifier, TupleTypeSignature,
922
};

0 commit comments

Comments
 (0)