Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply clippy lints approx_constant, assertions_on_constants, assign_op_pattern, and bool_assert_comparison #5745

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 47 additions & 60 deletions clarity/src/vm/tests/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,20 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
let p2 = execute("'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G");
let p3 = execute("'SP3X6QWWETNBZWGBK6DRGTR1KX50S74D3433WDGJY");

let p1_std_principal_data = match p1 {
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
_ => panic!(),
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
panic!("Expected standard principal data");
};

let p1_principal = match p1 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p1_principal) = p1.clone() else {
panic!("Expected principal data");
};

let p2_principal = match p2 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p2_principal) = p2.clone() else {
panic!("Expected principal data");
};

let p3_principal = match p3 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p3_principal) = p3.clone() else {
panic!("Expected principal data");
};

let token_contract_id =
Expand Down Expand Up @@ -212,7 +208,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 3));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -224,7 +220,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 3));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

// test 2: from = to

Expand All @@ -238,7 +234,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 2));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

// test 3: sender is not tx-sender

Expand All @@ -252,7 +248,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 4));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -264,7 +260,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 4));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

// test 4: amount > balance

Expand All @@ -278,7 +274,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 1));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -290,7 +286,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
.unwrap();

assert!(is_err_code(&result, 1));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

// test 5: overflow
// NOTE: this tested behavior is no longer reachable: the total liquid ustx supply
Expand Down Expand Up @@ -525,19 +521,16 @@ fn test_simple_token_system(
let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");
let p2 = execute("'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G");

let p1_std_principal_data = match p1 {
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
_ => panic!(),
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
panic!("Expected standard pincipal data");
};

let p1_principal = match p1 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p1_principal) = p1.clone() else {
panic!("Expected principal data");
};

let p2_principal = match p2 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p2_principal) = p2.clone() else {
panic!("Expected principal data");
};

let token_contract_id =
Expand Down Expand Up @@ -569,7 +562,7 @@ fn test_simple_token_system(
.unwrap();
assert!(!is_committed(&result));

assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand Down Expand Up @@ -597,7 +590,7 @@ fn test_simple_token_system(
.unwrap();

assert!(is_err_code(&result, 1));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -609,7 +602,7 @@ fn test_simple_token_system(
.unwrap();

assert!(is_err_code(&result, 2));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let err = execute_transaction(
&mut owned_env,
Expand All @@ -635,7 +628,7 @@ fn test_simple_token_system(
.unwrap();

assert_eq!(result, Value::UInt(1000));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -647,7 +640,7 @@ fn test_simple_token_system(
.unwrap();

assert_eq!(result, Value::UInt(9200));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand Down Expand Up @@ -814,7 +807,7 @@ fn test_simple_token_system(
.unwrap();

assert!(!is_committed(&result));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());
}

#[apply(test_epochs)]
Expand All @@ -836,14 +829,12 @@ fn test_total_supply(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnviro

let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");

let p1_std_principal_data = match p1 {
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
_ => panic!(),
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
panic!("Expected standard principal data");
};

let p1_principal = match p1 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p1_principal) = p1.clone() else {
panic!("Expected principal data");
};

let token_contract_id =
Expand Down Expand Up @@ -939,9 +930,8 @@ fn test_overlapping_nfts(

let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");

let p1_std_principal_data = match p1 {
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
_ => panic!(),
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1 else {
panic!("Expected standard principal data");
};

let tokens_contract_id =
Expand Down Expand Up @@ -991,19 +981,16 @@ fn test_simple_naming_system(
let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");
let p2 = execute("'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G");

let p1_std_principal_data = match p1 {
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
_ => panic!(),
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
panic!("Expected standard principal data");
};

let p1_principal = match p1 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p1_principal) = p1.clone() else {
panic!("Expected principal data");
};

let p2_principal = match p2 {
Value::Principal(ref data) => data.clone(),
_ => panic!(),
let Value::Principal(p2_principal) = p2.clone() else {
panic!("Expected principal data");
};

let placeholder_context =
Expand Down Expand Up @@ -1126,7 +1113,7 @@ fn test_simple_naming_system(
)
.unwrap();
assert!(is_err_code(&result, 0));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand Down Expand Up @@ -1157,7 +1144,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_err_code(&result, 1));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -1169,7 +1156,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_committed(&result));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

// let's transfer name

Expand All @@ -1183,7 +1170,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_err_code(&result, 3));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -1195,7 +1182,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_err_code(&result, 1));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand All @@ -1207,7 +1194,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_err_code(&result, 2));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

let (result, asset_map, _events) = execute_transaction(
&mut owned_env,
Expand Down Expand Up @@ -1314,7 +1301,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_committed(&result));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

// p2 burning 8 (which belongs to p1) should succeed even though sender != tx_sender.
let (result, asset_map, _events) = execute_transaction(
Expand Down Expand Up @@ -1375,7 +1362,7 @@ fn test_simple_naming_system(
.unwrap();

assert!(is_committed(&result));
assert_eq!(asset_map.to_table().len(), 0);
assert!(asset_map.to_table().is_empty());

{
let mut env = owned_env.get_exec_environment(None, None, &placeholder_context);
Expand Down
18 changes: 8 additions & 10 deletions libsigner/src/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ fn test_decode_http_request_err() {
for (data, expected_err_type) in tests.iter() {
let err = decode_http_request(data.as_bytes()).unwrap_err();
match (err, expected_err_type) {
(EventError::Deserialize(..), EventError::Deserialize(..)) => {}
(EventError::MalformedRequest(..), EventError::MalformedRequest(..)) => {}
(EventError::Deserialize(..), EventError::Deserialize(..))
| (EventError::MalformedRequest(..), EventError::MalformedRequest(..)) => {}
(x, y) => {
error!("expected error mismatch: {:?} != {:?}", &y, &x);
panic!();
panic!("expected error mismatch: {x:?} != {y:?}");
}
}
}
Expand Down Expand Up @@ -138,11 +137,10 @@ fn test_decode_http_response_err() {
let err_type = decode_http_response(data.as_bytes()).unwrap_err();
match (err_type, expected_err_type) {
(RPCError::HttpError(x), RPCError::HttpError(y)) => assert_eq!(x, *y),
(RPCError::Deserialize(_), RPCError::Deserialize(_)) => {}
(RPCError::MalformedResponse(_), RPCError::MalformedResponse(_)) => {}
(RPCError::Deserialize(_), RPCError::Deserialize(_))
| (RPCError::MalformedResponse(_), RPCError::MalformedResponse(_)) => {}
(x, y) => {
error!("expected error mismatch: {:?} != {:?}", &y, &x);
panic!();
panic!("expected error mismatch: {y:?} != {x:?}");
}
}
}
Expand Down Expand Up @@ -338,7 +336,7 @@ fn test_run_http_request_no_body() {
)
.unwrap();

assert_eq!(result_chunked.len(), 0);
assert_eq!(result_plain.len(), 0);
assert!(result_chunked.is_empty());
assert!(result_plain.is_empty());
}
}
12 changes: 6 additions & 6 deletions stacks-common/src/deps_common/httparse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ mod tests {
assert_eq!(req.method.unwrap(), "GET");
assert_eq!(req.path.unwrap(), "/");
assert_eq!(req.version.unwrap(), 1);
assert_eq!(req.headers.len(), 0);
assert!(req.headers.is_empty());
}
}

Expand All @@ -950,7 +950,7 @@ mod tests {
assert_eq!(req.method.unwrap(), "GET");
assert_eq!(req.path.unwrap(), "/thing?data=a");
assert_eq!(req.version.unwrap(), 1);
assert_eq!(req.headers.len(), 0);
assert!(req.headers.is_empty());
}
}

Expand All @@ -961,7 +961,7 @@ mod tests {
assert_eq!(req.method.unwrap(), "GET");
assert_eq!(req.path.unwrap(), "/thing?data=a^");
assert_eq!(req.version.unwrap(), 1);
assert_eq!(req.headers.len(), 0);
assert!(req.headers.is_empty());
}
}

Expand Down Expand Up @@ -1084,7 +1084,7 @@ mod tests {
assert_eq!(req.method.unwrap(), "GET");
assert_eq!(req.path.unwrap(), "/");
assert_eq!(req.version.unwrap(), 1);
assert_eq!(req.headers.len(), 0);
assert!(req.headers.is_empty());
}
}

Expand All @@ -1095,7 +1095,7 @@ mod tests {
assert_eq!(req.method.unwrap(), "GET");
assert_eq!(req.path.unwrap(), "/");
assert_eq!(req.version.unwrap(), 1);
assert_eq!(req.headers.len(), 0);
assert!(req.headers.is_empty());
}
}

Expand All @@ -1106,7 +1106,7 @@ mod tests {
assert_eq!(req.method.unwrap(), "GET");
assert_eq!(req.path.unwrap(), "/\\?wayne\\=5");
assert_eq!(req.version.unwrap(), 1);
assert_eq!(req.headers.len(), 0);
assert!(req.headers.is_empty());
}
}

Expand Down
Loading