From 14157325d6a6741d4ea1bec7c13c80b6ba34c359 Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Fri, 24 Jan 2025 21:00:09 -0500 Subject: [PATCH] fix: `cargo clippy-stacks` errors --- clarity/src/libclarity.rs | 3 +-- clarity/src/vm/contexts.rs | 4 ++-- clarity/src/vm/test_util/mod.rs | 2 +- clarity/src/vm/tests/simple_apply_eval.rs | 10 ++++------ clarity/src/vm/types/mod.rs | 5 ++--- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/clarity/src/libclarity.rs b/clarity/src/libclarity.rs index 9f1a0a06ba..7ce2a4f903 100644 --- a/clarity/src/libclarity.rs +++ b/clarity/src/libclarity.rs @@ -60,8 +60,7 @@ pub mod boot_util { pub fn boot_code_id(name: &str, mainnet: bool) -> QualifiedContractIdentifier { let addr = boot_code_addr(mainnet); QualifiedContractIdentifier::new( - addr.try_into() - .expect("FATAL: boot contract addr is not a legal principal"), + addr.into(), ContractName::try_from(name.to_string()) .expect("FATAL: boot contract name is not a legal ContractName"), ) diff --git a/clarity/src/vm/contexts.rs b/clarity/src/vm/contexts.rs index c716538f6d..a9779e96e6 100644 --- a/clarity/src/vm/contexts.rs +++ b/clarity/src/vm/contexts.rs @@ -2140,8 +2140,8 @@ mod test { // not simply rollback the tx and squelch the error as includable. let e = env .stx_transfer( - &PrincipalData::try_from(u1).unwrap(), - &PrincipalData::try_from(u2).unwrap(), + &PrincipalData::from(u1), + &PrincipalData::from(u2), 1000, &BuffData::empty(), ) diff --git a/clarity/src/vm/test_util/mod.rs b/clarity/src/vm/test_util/mod.rs index 07e557119c..37a40182eb 100644 --- a/clarity/src/vm/test_util/mod.rs +++ b/clarity/src/vm/test_util/mod.rs @@ -108,7 +108,7 @@ impl From<&StacksPrivateKey> for StandardPrincipalData { &vec![StacksPublicKey::from_private(o)], ) .unwrap(); - StandardPrincipalData::try_from(stacks_addr).unwrap() + StandardPrincipalData::from(stacks_addr) } } diff --git a/clarity/src/vm/tests/simple_apply_eval.rs b/clarity/src/vm/tests/simple_apply_eval.rs index 861cf60224..ceeb7f9ddb 100644 --- a/clarity/src/vm/tests/simple_apply_eval.rs +++ b/clarity/src/vm/tests/simple_apply_eval.rs @@ -430,7 +430,7 @@ fn test_secp256k1() { ) .unwrap(); eprintln!("addr from privk {:?}", &addr); - let principal = addr.try_into().unwrap(); + let principal = addr.into(); if let PrincipalData::Standard(data) = principal { eprintln!("test_secp256k1 principal {:?}", data.to_address()); } @@ -446,7 +446,7 @@ fn test_secp256k1() { ) .unwrap(); eprintln!("addr from hex {:?}", addr); - let principal: PrincipalData = addr.try_into().unwrap(); + let principal: PrincipalData = addr.into(); if let PrincipalData::Standard(data) = principal.clone() { eprintln!("test_secp256k1 principal {:?}", data.to_address()); } @@ -491,8 +491,7 @@ fn test_principal_of_fix() { .unwrap()], ) .unwrap() - .try_into() - .unwrap(); + .into(); let testnet_principal: PrincipalData = StacksAddress::from_public_keys( C32_ADDRESS_VERSION_TESTNET_SINGLESIG, &AddressHashMode::SerializeP2PKH, @@ -503,8 +502,7 @@ fn test_principal_of_fix() { .unwrap()], ) .unwrap() - .try_into() - .unwrap(); + .into(); // Clarity2, mainnet, should have a mainnet principal. assert_eq!( diff --git a/clarity/src/vm/types/mod.rs b/clarity/src/vm/types/mod.rs index 804d5f2eb1..d34a9cdf70 100644 --- a/clarity/src/vm/types/mod.rs +++ b/clarity/src/vm/types/mod.rs @@ -1531,9 +1531,8 @@ impl From for StacksAddress { fn from(o: StandardPrincipalData) -> StacksAddress { // should be infallible because it's impossible to construct a StandardPrincipalData with // an unsupported version byte - StacksAddress::new(o.version(), hash::Hash160(o.1)).unwrap_or_else(|_| { - panic!("FATAL: could not convert a StandardPrincipalData to StacksAddress") - }) + StacksAddress::new(o.version(), hash::Hash160(o.1)) + .expect("FATAL: could not convert a StandardPrincipalData to StacksAddress") } }