Skip to content

Commit 62b22fd

Browse files
committed
Merge branch develop into chore/clippy-single-match-and-redundant-pattern-matching and fix conflicts
2 parents c9cbd23 + 36d49b0 commit 62b22fd

File tree

100 files changed

+743
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+743
-883
lines changed

Cargo.lock

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

clarity/src/libclarity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ pub mod boot_util {
6060
pub fn boot_code_id(name: &str, mainnet: bool) -> QualifiedContractIdentifier {
6161
let addr = boot_code_addr(mainnet);
6262
QualifiedContractIdentifier::new(
63-
addr.try_into()
64-
.expect("FATAL: boot contract addr is not a legal principal"),
63+
addr.into(),
6564
ContractName::try_from(name.to_string())
6665
.expect("FATAL: boot contract name is not a legal ContractName"),
6766
)

clarity/src/vm/contexts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,8 +2140,8 @@ mod test {
21402140
// not simply rollback the tx and squelch the error as includable.
21412141
let e = env
21422142
.stx_transfer(
2143-
&PrincipalData::try_from(u1).unwrap(),
2144-
&PrincipalData::try_from(u2).unwrap(),
2143+
&PrincipalData::from(u1),
2144+
&PrincipalData::from(u2),
21452145
1000,
21462146
&BuffData::empty(),
21472147
)

clarity/src/vm/test_util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl From<&StacksPrivateKey> for StandardPrincipalData {
108108
&vec![StacksPublicKey::from_private(o)],
109109
)
110110
.unwrap();
111-
StandardPrincipalData::try_from(stacks_addr).unwrap()
111+
StandardPrincipalData::from(stacks_addr)
112112
}
113113
}
114114

clarity/src/vm/tests/simple_apply_eval.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fn test_secp256k1() {
430430
)
431431
.unwrap();
432432
eprintln!("addr from privk {:?}", &addr);
433-
let principal = addr.try_into().unwrap();
433+
let principal = addr.into();
434434
if let PrincipalData::Standard(data) = principal {
435435
eprintln!("test_secp256k1 principal {:?}", data.to_address());
436436
}
@@ -446,7 +446,7 @@ fn test_secp256k1() {
446446
)
447447
.unwrap();
448448
eprintln!("addr from hex {:?}", addr);
449-
let principal: PrincipalData = addr.try_into().unwrap();
449+
let principal: PrincipalData = addr.into();
450450
if let PrincipalData::Standard(data) = principal.clone() {
451451
eprintln!("test_secp256k1 principal {:?}", data.to_address());
452452
}
@@ -491,8 +491,7 @@ fn test_principal_of_fix() {
491491
.unwrap()],
492492
)
493493
.unwrap()
494-
.try_into()
495-
.unwrap();
494+
.into();
496495
let testnet_principal: PrincipalData = StacksAddress::from_public_keys(
497496
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
498497
&AddressHashMode::SerializeP2PKH,
@@ -503,8 +502,7 @@ fn test_principal_of_fix() {
503502
.unwrap()],
504503
)
505504
.unwrap()
506-
.try_into()
507-
.unwrap();
505+
.into();
508506

509507
// Clarity2, mainnet, should have a mainnet principal.
510508
assert_eq!(

clarity/src/vm/types/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,9 +1531,8 @@ impl From<StandardPrincipalData> for StacksAddress {
15311531
fn from(o: StandardPrincipalData) -> StacksAddress {
15321532
// should be infallible because it's impossible to construct a StandardPrincipalData with
15331533
// an unsupported version byte
1534-
StacksAddress::new(o.version(), hash::Hash160(o.1)).unwrap_or_else(|_| {
1535-
panic!("FATAL: could not convert a StandardPrincipalData to StacksAddress")
1536-
})
1534+
StacksAddress::new(o.version(), hash::Hash160(o.1))
1535+
.expect("FATAL: could not convert a StandardPrincipalData to StacksAddress")
15371536
}
15381537
}
15391538

libsigner/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn test_simple_signer() {
128128
reward_cycle: 1,
129129
};
130130
for i in 0..max_events {
131-
let privk = Secp256k1PrivateKey::new();
131+
let privk = Secp256k1PrivateKey::random();
132132
let message = SignerMessage::BlockProposal(block_proposal.clone());
133133
let message_bytes = message.serialize_to_vec();
134134
let mut chunk = StackerDBChunkData::new(i as u32, 1, message_bytes);

libsigner/src/v0/messages.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ mod test {
11921192
let rejection = BlockRejection::new(
11931193
Sha512Trunc256Sum([0u8; 32]),
11941194
RejectCode::ValidationFailed(ValidateRejectCode::InvalidBlock),
1195-
&StacksPrivateKey::new(),
1195+
&StacksPrivateKey::random(),
11961196
thread_rng().gen_bool(0.5),
11971197
thread_rng().next_u64(),
11981198
);
@@ -1204,7 +1204,7 @@ mod test {
12041204
let rejection = BlockRejection::new(
12051205
Sha512Trunc256Sum([1u8; 32]),
12061206
RejectCode::ConnectivityIssues,
1207-
&StacksPrivateKey::new(),
1207+
&StacksPrivateKey::random(),
12081208
thread_rng().gen_bool(0.5),
12091209
thread_rng().next_u64(),
12101210
);
@@ -1231,7 +1231,7 @@ mod test {
12311231
let response = BlockResponse::Rejected(BlockRejection::new(
12321232
Sha512Trunc256Sum([1u8; 32]),
12331233
RejectCode::ValidationFailed(ValidateRejectCode::InvalidBlock),
1234-
&StacksPrivateKey::new(),
1234+
&StacksPrivateKey::random(),
12351235
thread_rng().gen_bool(0.5),
12361236
thread_rng().next_u64(),
12371237
));
@@ -1318,10 +1318,10 @@ mod test {
13181318

13191319
#[test]
13201320
fn verify_sign_mock_proposal() {
1321-
let private_key = StacksPrivateKey::new();
1321+
let private_key = StacksPrivateKey::random();
13221322
let public_key = StacksPublicKey::from_private(&private_key);
13231323

1324-
let bad_private_key = StacksPrivateKey::new();
1324+
let bad_private_key = StacksPrivateKey::random();
13251325
let bad_public_key = StacksPublicKey::from_private(&bad_private_key);
13261326

13271327
let mut mock_proposal = random_mock_proposal();
@@ -1353,7 +1353,7 @@ mod test {
13531353
#[test]
13541354
fn serde_mock_proposal() {
13551355
let mut mock_signature = random_mock_proposal();
1356-
mock_signature.sign(&StacksPrivateKey::new()).unwrap();
1356+
mock_signature.sign(&StacksPrivateKey::random()).unwrap();
13571357
let serialized_signature = mock_signature.serialize_to_vec();
13581358
let deserialized_signature = read_next::<MockProposal, _>(&mut &serialized_signature[..])
13591359
.expect("Failed to deserialize MockSignature");
@@ -1368,7 +1368,7 @@ mod test {
13681368
metadata: SignerMessageMetadata::default(),
13691369
};
13701370
mock_signature
1371-
.sign(&StacksPrivateKey::new())
1371+
.sign(&StacksPrivateKey::random())
13721372
.expect("Failed to sign MockSignature");
13731373
let serialized_signature = mock_signature.serialize_to_vec();
13741374
let deserialized_signature = read_next::<MockSignature, _>(&mut &serialized_signature[..])
@@ -1379,8 +1379,10 @@ mod test {
13791379
#[test]
13801380
fn serde_mock_block() {
13811381
let mock_proposal = random_mock_proposal();
1382-
let mock_signature_1 = MockSignature::new(mock_proposal.clone(), &StacksPrivateKey::new());
1383-
let mock_signature_2 = MockSignature::new(mock_proposal.clone(), &StacksPrivateKey::new());
1382+
let mock_signature_1 =
1383+
MockSignature::new(mock_proposal.clone(), &StacksPrivateKey::random());
1384+
let mock_signature_2 =
1385+
MockSignature::new(mock_proposal.clone(), &StacksPrivateKey::random());
13841386
let mock_block = MockBlock {
13851387
mock_proposal,
13861388
mock_signatures: vec![mock_signature_1, mock_signature_2],

libstackerdb/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::*;
2424

2525
#[test]
2626
fn test_stackerdb_slot_metadata_sign_verify() {
27-
let pk = StacksPrivateKey::new();
27+
let pk = StacksPrivateKey::random();
2828
let addr = StacksAddress::from_public_keys(
2929
C32_ADDRESS_VERSION_MAINNET_SINGLESIG,
3030
&AddressHashMode::SerializeP2PKH,

stacks-common/src/util/secp256k1.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Default for Secp256k1PublicKey {
123123
impl Secp256k1PublicKey {
124124
#[cfg(any(test, feature = "testing"))]
125125
pub fn new() -> Secp256k1PublicKey {
126-
Secp256k1PublicKey::from_private(&Secp256k1PrivateKey::new())
126+
Secp256k1PublicKey::from_private(&Secp256k1PrivateKey::random())
127127
}
128128

129129
pub fn from_hex(hex_string: &str) -> Result<Secp256k1PublicKey, &'static str> {
@@ -249,14 +249,8 @@ impl PublicKey for Secp256k1PublicKey {
249249
}
250250
}
251251

252-
impl Default for Secp256k1PrivateKey {
253-
fn default() -> Self {
254-
Self::new()
255-
}
256-
}
257-
258252
impl Secp256k1PrivateKey {
259-
pub fn new() -> Secp256k1PrivateKey {
253+
pub fn random() -> Secp256k1PrivateKey {
260254
let mut rng = rand::thread_rng();
261255
loop {
262256
// keep trying to generate valid bytes
@@ -460,7 +454,7 @@ mod tests {
460454

461455
#[test]
462456
fn test_parse_serialize_compressed() {
463-
let mut t1 = Secp256k1PrivateKey::new();
457+
let mut t1 = Secp256k1PrivateKey::random();
464458
t1.set_compress_public(true);
465459
let h_comp = t1.to_hex();
466460
t1.set_compress_public(false);
@@ -654,7 +648,7 @@ mod tests {
654648
let mut rng = rand::thread_rng();
655649

656650
for i in 0..100 {
657-
let privk = Secp256k1PrivateKey::new();
651+
let privk = Secp256k1PrivateKey::random();
658652
let pubk = Secp256k1PublicKey::from_private(&privk);
659653

660654
let mut msg = [0u8; 32];

0 commit comments

Comments
 (0)