Skip to content

Commit 41c74fa

Browse files
authored
Merge pull request #5624 from stacks-network/fix/clippy-ci-stacks-lib-unnecessary-cast
Remove unnecessary casts throughout stackslib
2 parents 8e2c660 + 273d3b4 commit 41c74fa

Some content is hidden

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

54 files changed

+336
-373
lines changed

stackslib/src/burnchains/bitcoin/blocks.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ mod tests {
656656
data_amt: 0,
657657
txid: to_txid(&hex_bytes("185c112401590b11acdfea6bb26d2a8e37cb31f24a0c89dbb8cc14b3d6271fb1").unwrap()),
658658
vtxindex,
659-
opcode: '+' as u8,
659+
opcode: b'+',
660660
data: hex_bytes("fae543ff5672fb607fe15e16b1c3ef38737c631c7c5d911c6617993c21fba731363f1cfe").unwrap(),
661661
inputs: vec![
662662
BitcoinTxInputStructured {
@@ -703,7 +703,7 @@ mod tests {
703703
data_amt: 0,
704704
txid: to_txid(&hex_bytes("eb2e84a45cf411e528185a98cd5fb45ed349843a83d39fd4dff2de47adad8c8f").unwrap()),
705705
vtxindex,
706-
opcode: '~' as u8,
706+
opcode: b'~',
707707
data: hex_bytes("7061747269636b7374616e6c6579322e6964").unwrap(),
708708
inputs: vec![
709709
BitcoinTxInputStructured {
@@ -746,7 +746,7 @@ mod tests {
746746
data_amt: 0,
747747
txid: to_txid(&hex_bytes("b908952b30ccfdfa59985dc1ffdd2a22ef054d20fa253510d2af7797dddee459").unwrap()),
748748
vtxindex,
749-
opcode: ':' as u8,
749+
opcode: b':',
750750
data: hex_bytes("666f6f2e74657374").unwrap(),
751751
inputs: vec![
752752
BitcoinTxInputStructured {
@@ -777,7 +777,7 @@ mod tests {
777777
data_amt: 0,
778778
txid: to_txid(&hex_bytes("16751ca54407b922e3072830cf4be58c5562a6dc350f6703192b673c4cc86182").unwrap()),
779779
vtxindex,
780-
opcode: '?' as u8,
780+
opcode: b'?',
781781
data: hex_bytes("9fab7f294936ddb6524a48feff691ecbd0ca9e8f107d845c417a5438d1cb441e827c5126").unwrap(),
782782
inputs: vec![
783783
BitcoinTxInputStructured {
@@ -827,7 +827,7 @@ mod tests {
827827
data_amt: 0,
828828
txid: to_txid(&hex_bytes("185c112401590b11acdfea6bb26d2a8e37cb31f24a0c89dbb8cc14b3d6271fb1").unwrap()),
829829
vtxindex,
830-
opcode: '+' as u8,
830+
opcode: b'+',
831831
data: hex_bytes("fae543ff5672fb607fe15e16b1c3ef38737c631c7c5d911c6617993c21fba731363f1cfe").unwrap(),
832832
inputs: vec![
833833
BitcoinTxInputRaw {
@@ -865,7 +865,7 @@ mod tests {
865865
data_amt: 0,
866866
txid: to_txid(&hex_bytes("eb2e84a45cf411e528185a98cd5fb45ed349843a83d39fd4dff2de47adad8c8f").unwrap()),
867867
vtxindex,
868-
opcode: '~' as u8,
868+
opcode: b'~',
869869
data: hex_bytes("7061747269636b7374616e6c6579322e6964").unwrap(),
870870
inputs: vec![
871871
BitcoinTxInputRaw {
@@ -898,7 +898,7 @@ mod tests {
898898
data_amt: 0,
899899
txid: to_txid(&hex_bytes("b908952b30ccfdfa59985dc1ffdd2a22ef054d20fa253510d2af7797dddee459").unwrap()),
900900
vtxindex,
901-
opcode: ':' as u8,
901+
opcode: b':',
902902
data: hex_bytes("666f6f2e74657374").unwrap(),
903903
inputs: vec![
904904
BitcoinTxInputRaw {
@@ -929,7 +929,7 @@ mod tests {
929929
data_amt: 0,
930930
txid: to_txid(&hex_bytes("16751ca54407b922e3072830cf4be58c5562a6dc350f6703192b673c4cc86182").unwrap()),
931931
vtxindex,
932-
opcode: '?' as u8,
932+
opcode: b'?',
933933
data: hex_bytes("9fab7f294936ddb6524a48feff691ecbd0ca9e8f107d845c417a5438d1cb441e827c5126").unwrap(),
934934
inputs: vec![
935935
BitcoinTxInputRaw {
@@ -962,7 +962,7 @@ mod tests {
962962
data_amt: 0,
963963
txid: to_txid(&hex_bytes("8b8a12909d48fd86c06e92270133d320498fb36caa0fdcb3292a8bba99669ebd").unwrap()),
964964
vtxindex,
965-
opcode: '&' as u8,
965+
opcode: b'&',
966966
data: hex_bytes("0000cd73fa046543210000000000aa000174657374").unwrap(),
967967
inputs: vec![
968968
BitcoinTxInputRaw {
@@ -1039,7 +1039,7 @@ mod tests {
10391039
// NAME_REGISTRATION with segwit p2wpkh-p2sh input
10401040
txid: to_txid(&hex_bytes("b908952b30ccfdfa59985dc1ffdd2a22ef054d20fa253510d2af7797dddee459").unwrap()),
10411041
vtxindex: 1,
1042-
opcode: ':' as u8,
1042+
opcode: b':',
10431043
data: hex_bytes("666f6f2e74657374").unwrap(),
10441044
inputs: vec![
10451045
BitcoinTxInputStructured {
@@ -1082,7 +1082,7 @@ mod tests {
10821082
// TOKEN_TRANSFER
10831083
txid: to_txid(&hex_bytes("13f2c54dbbe3d4d6ed6c9fd1a68fe3c4238ec5de50316d102a106553b57b8728").unwrap()),
10841084
vtxindex: 2,
1085-
opcode: '$' as u8,
1085+
opcode: b'$',
10861086
data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(),
10871087
inputs: vec![
10881088
BitcoinTxInputStructured {
@@ -1110,7 +1110,7 @@ mod tests {
11101110
// TOKEN_TRANSFER
11111111
txid: to_txid(&hex_bytes("7c7c60ae8617daeb351da01d0f683633e6778eb39b69e6e652b24ca0ce230291").unwrap()),
11121112
vtxindex: 4,
1113-
opcode: '$' as u8,
1113+
opcode: b'$',
11141114
data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(),
11151115
inputs: vec![
11161116
BitcoinTxInputStructured {
@@ -1138,7 +1138,7 @@ mod tests {
11381138
// TOKEN_TRANSFER
11391139
txid: to_txid(&hex_bytes("ae1cf8b812cf28ea96c7343dc7ee9ff2d8dfb2f441ab11c886dfcd56a0a1a2b4").unwrap()),
11401140
vtxindex: 7,
1141-
opcode: '$' as u8,
1141+
opcode: b'$',
11421142
data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(),
11431143
inputs: vec![
11441144
BitcoinTxInputStructured {
@@ -1166,7 +1166,7 @@ mod tests {
11661166
// TOKEN_TRANSFER
11671167
txid: to_txid(&hex_bytes("12fed1db482a35dba87535a13089692cea35a71bfb159b21d0a04be41219b2bd").unwrap()),
11681168
vtxindex: 10,
1169-
opcode: '$' as u8,
1169+
opcode: b'$',
11701170
data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(),
11711171
inputs: vec![
11721172
BitcoinTxInputStructured {
@@ -1194,7 +1194,7 @@ mod tests {
11941194
// TOKEN_TRANSFER
11951195
txid: to_txid(&hex_bytes("78035609a8733f214555cfec29e3eee1d24014863dc9f9d98092f6fbc5df63e8").unwrap()),
11961196
vtxindex: 13,
1197-
opcode: '$' as u8,
1197+
opcode: b'$',
11981198
data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(),
11991199
inputs: vec![
12001200
BitcoinTxInputStructured {

stackslib/src/burnchains/tests/affirmation.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,11 @@ pub fn make_reward_cycle_with_vote(
389389
);
390390

391391
if let Some(ref parent_commit) = parent_commits[i].as_ref() {
392+
assert!(parent_commit.block_height != block_commit.block_height);
392393
assert!(
393-
parent_commit.block_height as u64 != block_commit.block_height as u64
394-
);
395-
assert!(
396-
parent_commit.block_height as u64
397-
== block_commit.parent_block_ptr as u64
398-
);
399-
assert!(
400-
parent_commit.vtxindex as u64 == block_commit.parent_vtxindex as u64
394+
parent_commit.block_height == u64::from(block_commit.parent_block_ptr)
401395
);
396+
assert!(parent_commit.vtxindex == u32::from(block_commit.parent_vtxindex));
402397
}
403398

404399
parent_commits[i] = Some(block_commit.clone());

stackslib/src/burnchains/tests/burnchain.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,8 @@ fn test_process_block_ops() {
464464
123,
465465
));
466466

467-
let initial_snapshot = BlockSnapshot::initial(
468-
first_block_height,
469-
&first_burn_hash,
470-
first_block_height as u64,
471-
);
467+
let initial_snapshot =
468+
BlockSnapshot::initial(first_block_height, &first_burn_hash, first_block_height);
472469

473470
// process up to 124
474471
{
@@ -733,11 +730,8 @@ fn test_burn_snapshot_sequence() {
733730

734731
// insert all operations
735732
let mut db = SortitionDB::connect_test(first_block_height, &first_burn_hash).unwrap();
736-
let mut prev_snapshot = BlockSnapshot::initial(
737-
first_block_height,
738-
&first_burn_hash,
739-
first_block_height as u64,
740-
);
733+
let mut prev_snapshot =
734+
BlockSnapshot::initial(first_block_height, &first_burn_hash, first_block_height);
741735
let mut all_stacks_block_hashes = vec![];
742736

743737
for i in 0..32 {

stackslib/src/burnchains/tests/db.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,14 @@ fn test_get_commit_at() {
602602
for i in 0..5 {
603603
let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]);
604604
let block_header = BurnchainBlockHeader {
605-
block_height: (first_height + i) as u64,
605+
block_height: first_height + i,
606606
block_hash: hdr,
607607
parent_block_hash: parent_block_header
608608
.as_ref()
609609
.map(|blk| blk.block_hash.clone())
610610
.unwrap_or(first_block_header.block_hash.clone()),
611611
num_txs: 1,
612-
timestamp: i as u64,
612+
timestamp: i,
613613
};
614614

615615
headers.push(block_header.clone());
@@ -656,13 +656,13 @@ fn test_get_commit_at() {
656656
assert_eq!(cmt, cmts[4]);
657657

658658
// fork off the last stored commit block
659-
let fork_hdr = BurnchainHeaderHash([90 as u8; 32]);
659+
let fork_hdr = BurnchainHeaderHash([90; 32]);
660660
let fork_block_header = BurnchainBlockHeader {
661661
block_height: 5,
662662
block_hash: fork_hdr,
663-
parent_block_hash: BurnchainHeaderHash([4 as u8; 32]),
663+
parent_block_hash: BurnchainHeaderHash([4; 32]),
664664
num_txs: 1,
665-
timestamp: 4 as u64,
665+
timestamp: 4,
666666
};
667667

668668
let mut fork_cmt = cmts[4].clone();
@@ -716,14 +716,14 @@ fn test_get_set_check_anchor_block() {
716716
for i in 0..5 {
717717
let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]);
718718
let block_header = BurnchainBlockHeader {
719-
block_height: (first_height + i) as u64,
719+
block_height: first_height + i,
720720
block_hash: hdr,
721721
parent_block_hash: parent_block_header
722722
.as_ref()
723723
.map(|blk| blk.block_hash.clone())
724724
.unwrap_or(first_block_header.block_hash.clone()),
725725
num_txs: 1,
726-
timestamp: i as u64,
726+
timestamp: i,
727727
};
728728

729729
headers.push(block_header.clone());
@@ -802,14 +802,14 @@ fn test_update_block_descendancy() {
802802
for i in 0..5 {
803803
let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]);
804804
let block_header = BurnchainBlockHeader {
805-
block_height: (first_height + i) as u64,
805+
block_height: first_height + i,
806806
block_hash: hdr,
807807
parent_block_hash: parent_block_header
808808
.as_ref()
809809
.map(|blk| blk.block_hash.clone())
810810
.unwrap_or(first_block_header.block_hash.clone()),
811811
num_txs: 3,
812-
timestamp: i as u64,
812+
timestamp: i,
813813
};
814814

815815
headers.push(block_header.clone());
@@ -926,14 +926,14 @@ fn test_update_block_descendancy_with_fork() {
926926
for i in 0..5 {
927927
let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]);
928928
let block_header = BurnchainBlockHeader {
929-
block_height: (first_height + i) as u64,
929+
block_height: first_height + i,
930930
block_hash: hdr,
931931
parent_block_hash: parent_block_header
932932
.as_ref()
933933
.map(|blk| blk.block_hash.clone())
934934
.unwrap_or(first_block_header.block_hash.clone()),
935935
num_txs: 3,
936-
timestamp: i as u64,
936+
timestamp: i,
937937
};
938938

939939
headers.push(block_header.clone());
@@ -943,14 +943,14 @@ fn test_update_block_descendancy_with_fork() {
943943
for i in 0..5 {
944944
let hdr = BurnchainHeaderHash([(i + 128 + 1) as u8; 32]);
945945
let block_header = BurnchainBlockHeader {
946-
block_height: (first_height + i) as u64,
946+
block_height: first_height + i,
947947
block_hash: hdr,
948948
parent_block_hash: parent_block_header
949949
.as_ref()
950950
.map(|blk| blk.block_hash.clone())
951951
.unwrap_or(first_block_header.block_hash.clone()),
952952
num_txs: 3,
953-
timestamp: i as u64,
953+
timestamp: i,
954954
};
955955

956956
fork_headers.push(block_header.clone());

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use crate::util_lib::db::{
8888
u64_to_sql, DBConn, DBTx, Error as db_error, FromColumn, FromRow, IndexDBConn, IndexDBTx,
8989
};
9090

91-
const BLOCK_HEIGHT_MAX: u64 = ((1 as u64) << 63) - 1;
91+
const BLOCK_HEIGHT_MAX: u64 = (1 << 63) - 1;
9292

9393
pub const REWARD_WINDOW_START: u64 = 144 * 15;
9494
pub const REWARD_WINDOW_END: u64 = 144 * 90 + REWARD_WINDOW_START;
@@ -7422,7 +7422,7 @@ pub mod tests {
74227422
for i in 0..255 {
74237423
let sortition_id = SortitionId([
74247424
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7425-
0, 0, 0, 0, 0, i as u8,
7425+
0, 0, 0, 0, 0, i,
74267426
]);
74277427
let parent_sortition_id = if i == 0 {
74287428
last_snapshot.sortition_id.clone()
@@ -7459,7 +7459,7 @@ pub mod tests {
74597459
0,
74607460
0,
74617461
0,
7462-
i - 1 as u8,
7462+
i - 1,
74637463
])
74647464
};
74657465

@@ -7471,7 +7471,7 @@ pub mod tests {
74717471
burn_header_timestamp: get_epoch_time_secs(),
74727472
burn_header_hash: BurnchainHeaderHash::from_bytes(&[
74737473
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7474-
0, 0, 0, 0, 0, 0, i as u8,
7474+
0, 0, 0, 0, 0, 0, i,
74757475
])
74767476
.unwrap(),
74777477
sortition_id,
@@ -7508,7 +7508,7 @@ pub mod tests {
75087508
0,
75097509
0,
75107510
0,
7511-
(if i == 0 { 0xff } else { i - 1 }) as u8,
7511+
(if i == 0 { 0xff } else { i - 1 }),
75127512
])
75137513
.unwrap(),
75147514
consensus_hash: ConsensusHash::from_bytes(&[
@@ -7531,12 +7531,12 @@ pub mod tests {
75317531
0,
75327532
0,
75337533
0,
7534-
(i + 1) as u8,
7534+
i + 1,
75357535
])
75367536
.unwrap(),
75377537
ops_hash: OpsHash::from_bytes(&[
75387538
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7539-
0, 0, 0, 0, 0, 0, i as u8,
7539+
0, 0, 0, 0, 0, 0, i,
75407540
])
75417541
.unwrap(),
75427542
total_burn: i as u64,
@@ -7717,7 +7717,7 @@ pub mod tests {
77177717
let snapshot_row = BlockSnapshot {
77187718
accumulated_coinbase_ustx: 0,
77197719
pox_valid: true,
7720-
block_height: i as u64 + 1,
7720+
block_height: i + 1,
77217721
burn_header_timestamp: get_epoch_time_secs(),
77227722
burn_header_hash: BurnchainHeaderHash::from_bytes(&[
77237723
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -7789,7 +7789,7 @@ pub mod tests {
77897789
0, 0, 0, 0, 0, 0, i as u8,
77907790
])
77917791
.unwrap(),
7792-
total_burn: i as u64,
7792+
total_burn: i,
77937793
sortition: true,
77947794
sortition_hash: SortitionHash::initial(),
77957795
winning_block_txid: Txid::from_hex(
@@ -7801,7 +7801,7 @@ pub mod tests {
78017801
)
78027802
.unwrap(),
78037803
index_root: TrieHash::from_empty_data(),
7804-
num_sortitions: i as u64 + 1,
7804+
num_sortitions: i + 1,
78057805
stacks_block_accepted: false,
78067806
stacks_block_height: 0,
78077807
arrival_index: 0,
@@ -7824,7 +7824,7 @@ pub mod tests {
78247824
last_snapshot = snapshot_row;
78257825
last_snapshot.index_root = index_root;
78267826
// should succeed within the tx
7827-
let ch = tx.get_consensus_at(i as u64 + 1).unwrap().unwrap();
7827+
let ch = tx.get_consensus_at(i + 1).unwrap().unwrap();
78287828
assert_eq!(ch, last_snapshot.consensus_hash);
78297829

78307830
tx.commit().unwrap();

0 commit comments

Comments
 (0)