Skip to content

Commit

Permalink
chore(repo): fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ubordignon committed Oct 8, 2024
1 parent 98c3d11 commit 4be2637
Show file tree
Hide file tree
Showing 31 changed files with 138 additions and 139 deletions.
2 changes: 1 addition & 1 deletion common/bitcoin/src/validate_btc_difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod tests {
#[test]
fn should_err_if_difficulty_is_below_threshold() {
let block_header = get_sample_btc_block_and_id().unwrap().block.header;
let threshold = u64::max_value();
let threshold = u64::MAX;
assert!(check_difficulty_is_above_threshold(threshold, &block_header, BtcNetwork::Bitcoin).is_err());
}

Expand Down
4 changes: 2 additions & 2 deletions common/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mod tests {

#[test]
fn should_convert_u64_to_bytes() {
let u_64 = u64::max_value();
let u_64 = u64::MAX;
let expected_result = [255, 255, 255, 255, 255, 255, 255, 255];
let result = convert_u64_to_bytes(u_64);
assert_eq!(result, expected_result);
Expand All @@ -183,7 +183,7 @@ mod tests {
#[test]
fn should_convert_bytes_to_u64() {
let bytes = vec![255, 255, 255, 255, 255, 255, 255, 255];
let expected_result = u64::max_value();
let expected_result = u64::MAX;
let result = convert_bytes_to_u64(&bytes).unwrap();
assert_eq!(result, expected_result);
}
Expand Down
2 changes: 0 additions & 2 deletions common/debug_signers/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(test)]

use common_eth::{convert_hex_to_eth_address, EthPrivateKey};
use ethereum_types::{Address as EthAddress, H256};

Expand Down
3 changes: 2 additions & 1 deletion common/eos/src/eos_enclave_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use common::{
use common_safe_addresses::SAFE_EOS_ADDRESS_STR;
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "spring_1-0"))]
use crate::Incremerkles;
use crate::{
eos_database_utils::EosDbUtils,
eos_global_sequences::ProcessedGlobalSequences,
eos_types::EosKnownSchedulesJsons,
protocol_features::EnabledFeatures,
Incremerkles,
};

#[derive(Serialize, Deserialize)]
Expand Down
3 changes: 1 addition & 2 deletions common/eos/src/eos_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ macro_rules! impl_hash {
where
H: Hasher,
{
state.write(&self.0);
state.finish();
self.0.hash(state);
}
}

Expand Down
21 changes: 14 additions & 7 deletions common/eos/src/eos_incremerkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use derive_more::{Constructor, Deref, DerefMut};
use eos_chain::Checksum256;
use serde::{Deserialize, Serialize};

use crate::{EosDbUtils, EosState};
use crate::EosDbUtils;
#[cfg(not(feature = "spring_1-0"))]
use crate::EosState;

// NOTE: The light client for EOS doesn't keep blocks - they are too frequent and too numerous
// for efficient use in TEEs.
Expand All @@ -29,6 +31,7 @@ use crate::{EosDbUtils, EosState};
// keep up to some X incremerkles around. This means we have a choice of incremerkle from which we can
// verifiy a new submission.

#[cfg(not(feature = "spring_1-0"))]
const MAX_NUM_INCREMERKLES: usize = 10;

#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize, Constructor, Deref, DerefMut)]
Expand Down Expand Up @@ -93,6 +96,7 @@ impl Incremerkles {

// TODO Make more efficient my taking &mut self, however that makes using the above
// state-version of this more difficult to manage for the caller.
#[cfg(not(feature = "spring_1-0"))]
fn add_block_ids<D: DatabaseInterface>(
&self,
eos_db_utils: &EosDbUtils<D>,
Expand Down Expand Up @@ -134,6 +138,7 @@ impl Incremerkles {
Ok(mutable_self)
}

#[cfg(not(feature = "spring_1-0"))]
fn add(&mut self, incremerkle: Incremerkle) {
if incremerkle.block_num() > self.latest_block_num() || self.is_empty() {
info!("adding new incremerkle to list");
Expand Down Expand Up @@ -388,10 +393,9 @@ mod tests {
#![allow(clippy::needless_range_loop)]
use std::str::FromStr;

use common::{
test_utils::get_test_database,
types::{Byte, Bytes},
};
#[cfg(not(feature = "spring_1-0"))]
use common::test_utils::get_test_database;
use common::types::{Byte, Bytes};
use eos_chain::{AccountName, Action, ActionName, PermissionLevel, PermissionName, SerializeData};

use super::*;
Expand Down Expand Up @@ -440,8 +444,8 @@ mod tests {
}
for i in 0..(leaves.len() / 2) {
leaves[i] = MerkleProof::hash_canonical_pair(Incremerkle::make_canonical_pair(
&convert_hex_to_checksum256(&hex::encode(&leaves[2 * i])).unwrap(),
&convert_hex_to_checksum256(&hex::encode(&leaves[(2 * i) + 1])).unwrap(),
&convert_hex_to_checksum256(hex::encode(&leaves[2 * i])).unwrap(),
&convert_hex_to_checksum256(hex::encode(&leaves[(2 * i) + 1])).unwrap(),
))
.unwrap()
.as_bytes()
Expand Down Expand Up @@ -685,6 +689,7 @@ mod tests {
.for_each(|(result, expected_result)| assert_eq!(result, expected_result))
}

#[cfg(not(feature = "spring_1-0"))]
#[test]
fn should_only_allow_max_num_incremerkles() {
let mut incremerkles = Incremerkles::default();
Expand All @@ -699,6 +704,7 @@ mod tests {
}
}

#[cfg(not(feature = "spring_1-0"))]
#[test]
fn should_put_and_get_incremerkles_in_db() {
let mut incremerkles = Incremerkles::default();
Expand All @@ -713,6 +719,7 @@ mod tests {
assert_eq!(incremerkles.block_nums(), incremerkles_from_db.block_nums());
}

#[cfg(not(feature = "spring_1-0"))]
#[test]
fn should_only_add_subsequent_incremerkles() {
let mut incremerkles = Incremerkles::default();
Expand Down
5 changes: 2 additions & 3 deletions common/eos/src/eos_merkle_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ mod tests {
#[test]
fn should_verify_merkle_proofs() {
let num_proofs = 4;
vec![0, num_proofs - 1]
[0, num_proofs - 1]
.iter()
.enumerate()
.map(|(_, i)| get_sample_eos_submission_material_n(i + 1))
.map(|i| get_sample_eos_submission_material_n(i + 1))
.map(|submission_material| submission_material.action_proofs[0].action_proof.clone().into())
.for_each(|proof: MerkleProof| assert!(proof.verify().unwrap()));
}
Expand Down
3 changes: 2 additions & 1 deletion common/eos/src/eos_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use common::{
};

pub use crate::bitcoin_crate_alias::blockdata::transaction::Transaction as BtcTransaction;
#[cfg(not(feature = "spring_1-0"))]
use crate::eos_incremerkle::Incremerkles;
use crate::{
eos_action_proofs::EosActionProofs,
eos_block_header::EosBlockHeaderV2,
eos_database_utils::EosDbUtils,
eos_global_sequences::{GlobalSequences, ProcessedGlobalSequences},
eos_incremerkle::Incremerkles,
eos_producer_schedule::EosProducerScheduleV2,
eos_submission_material::EosSubmissionMaterial,
eos_types::Checksum256s,
Expand Down
2 changes: 1 addition & 1 deletion common/eos/src/get_action_digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod tests {
data: hex::decode("c0a6c36c3adc90bb8d6e0d0000000000085042544300000022314e393348584a687848754732444e59356b786a51373147347463726b5278354341")
.unwrap(),
};
let results = vec![
let results = [
hex::encode(get_action_digest(&action, true).unwrap()), // Assum the action HAS return value...
hex::encode(get_action_digest(&action, false).unwrap()), // Assume the action has NO return value...
];
Expand Down
4 changes: 2 additions & 2 deletions common/eos/src/protocol_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ mod tests {
#[test]
fn should_multi_add_available_features() {
let existing_feature_hash = hex::decode(WTMSIG_BLOCK_SIGNATURE_FEATURE_HASH).unwrap();
let existing_feature_hashes = vec![existing_feature_hash.clone(), existing_feature_hash];
let existing_feature_hashes = [existing_feature_hash.clone(), existing_feature_hash];
existing_feature_hashes
.iter()
.for_each(|hash| assert!(AVAILABLE_FEATURES.contains(hash)));
Expand All @@ -245,7 +245,7 @@ mod tests {
fn should_fail_when_multi_addiing_non_available_features() {
let unavailable_feature_hash = vec![0u8; 32];
let existing_feature_hash = hex::decode(WTMSIG_BLOCK_SIGNATURE_FEATURE_HASH).unwrap();
let feature_hashes = vec![existing_feature_hash, unavailable_feature_hash.clone()];
let feature_hashes = [existing_feature_hash, unavailable_feature_hash.clone()];
assert!(feature_hashes
.iter()
.map(|hash| AVAILABLE_FEATURES.contains(hash))
Expand Down
3 changes: 2 additions & 1 deletion common/eos/src/validate_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use common::{
use eos_chain::{AccountName as EosAccountName, PublicKey as EosProducerKey};
use secp256k1::Message;

#[cfg(not(feature = "spring_1-0"))]
use crate::protocol_features::WTMSIG_BLOCK_SIGNATURE_FEATURE_HASH;
use crate::{
bitcoin_crate_alias::hashes::{sha256, Hash},
eos_block_header::{EosBlockHeaderV1, EosBlockHeaderV2},
eos_constants::EOS_DEFAULT_PUB_KEY_STRING,
eos_crypto::{eos_public_key::EosPublicKey, eos_signature::EosSignature},
eos_producer_key::EosProducerKeyV1,
eos_producer_schedule::{EosProducerScheduleV1, EosProducerScheduleV2},
protocol_features::WTMSIG_BLOCK_SIGNATURE_FEATURE_HASH,
EosState,
};

Expand Down
1 change: 0 additions & 1 deletion common/ethereum/src/eth_contracts/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(test)]
use std::{fs::read_to_string, path::Path, str::FromStr};

use common::{dictionaries::eth_evm::EthEvmTokenDictionary, types::Result};
Expand Down
26 changes: 8 additions & 18 deletions common/ethereum/src/eth_submission_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,10 @@ mod tests {
.unwrap();
let num_receipts_after = result.receipts.len();
assert!(num_receipts_before > num_receipts_after);
result
.receipts
.0
.iter()
.map(|receipt| {
assert!(receipt.logs.contain_topic(&topics[0]));
receipt
})
.for_each(|receipt| assert!(receipt.logs.contain_address(&address)));
result.receipts.0.iter().for_each(|receipt| {
assert!(receipt.logs.contain_topic(&topics[0]));
assert!(receipt.logs.contain_address(&address))
});
}

#[test]
Expand All @@ -585,15 +580,10 @@ mod tests {
let num_receipts_after = result.receipts.len();
assert!(num_receipts_before > num_receipts_after);
assert_eq!(num_receipts_after, expected_num_receipts_after);
result
.receipts
.0
.iter()
.map(|receipt| {
assert!(receipt.logs.contain_topic(&topics[0]));
receipt
})
.for_each(|receipt| assert!(receipt.logs.contain_address(&address)));
result.receipts.0.iter().for_each(|receipt| {
assert!(receipt.logs.contain_topic(&topics[0]));
assert!(receipt.logs.contain_address(&address))
});
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ fn reprocess_int_block<D: DatabaseInterface>(db: &D, block_json: &str, signature
///
/// ### NOTE:
///
/// - This function will increment the core's INT nonce, meaning the outputted reports will have a
/// gap in their report IDs!
/// - This function will increment the core's INT nonce, meaning the outputted reports will have a gap in their report
/// IDs!
///
/// ### BEWARE:
/// If you don't broadcast the transaction outputted from this function, ALL future BTC transactions will
Expand Down
1 change: 0 additions & 1 deletion v2_bridges/eos_on_int/src/eos/get_eos_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ use std::str::FromStr;
#[cfg(test)]
use common::errors::AppError;
#[cfg(test)]
#[cfg(test)]
impl FromStr for EosOutput {
type Err = AppError;

Expand Down
19 changes: 11 additions & 8 deletions v2_bridges/eos_on_int/src/eos/submit_eos_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use common::{traits::DatabaseInterface, types::Result, CoreType};
#[cfg(not(feature = "spring_1-0"))]
use common_eos::Incremerkles;
use common_eos::{
end_eos_db_transaction_and_return_state,
get_active_schedule_from_db_and_add_to_state,
Expand All @@ -17,7 +19,6 @@ use common_eos::{
validate_block_header_signature,
validate_producer_slot_of_block_in_state,
EosState,
Incremerkles,
};

use crate::eos::{
Expand Down Expand Up @@ -115,7 +116,7 @@ mod tests {

use common::test_utils::get_test_database;
use common_chain_ids::EthChainId;
use common_eos::{initialize_eos_core_inner, EosPrivateKey, EosSubmissionMaterial, ProcessedGlobalSequences};
use common_eos::{initialize_eos_core_inner, EosPrivateKey, ProcessedGlobalSequences};
use common_eth::{
initialize_eth_core_with_router_contract_and_return_state,
EthDbUtils,
Expand All @@ -136,12 +137,6 @@ mod tests {
get_sample_int_address,
get_sample_int_private_key,
get_sample_router_address,
multi_incremerkle_submission::{
get_incremekle_update_block,
get_init_block,
get_sample_dictionary as get_sample_dictionary_for_incremerkle_test,
get_submission_block,
},
},
};

Expand Down Expand Up @@ -267,7 +262,15 @@ mod tests {

#[cfg(not(feature = "spring_1-0"))]
mod legacy_blocks {
use common_eos::EosSubmissionMaterial;

use super::*;
use crate::test_utils::multi_incremerkle_submission::{
get_incremekle_update_block,
get_init_block,
get_sample_dictionary as get_sample_dictionary_for_incremerkle_test,
get_submission_block,
};

#[test]
fn should_submit_eos_block() {
Expand Down
4 changes: 3 additions & 1 deletion v2_bridges/eos_on_int/src/get_latest_block_numbers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use common::{core_type::CoreType, traits::DatabaseInterface, types::Result};
use common_eos::{EosDbUtils, Incremerkles};
use common_eos::EosDbUtils;
#[cfg(not(feature = "spring_1-0"))]
use common_eos::Incremerkles;
use common_eth::{EthDbUtils, EthDbUtilsExt};
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ fn reprocess_eth_block<D: DatabaseInterface>(
/// submission pipeline, signing any signatures for pegouts it may find in the block
///
/// ### NOTES:
/// - This function will increment the core's ETH nonce, meaning the outputted reports will have a
/// gap in their report IDs!
/// - This function will increment the core's ETH nonce, meaning the outputted reports will have a gap in their report
/// IDs!
///
/// - This version of the ETH block reprocessor __will__ deduct fees from any transaction info(s) it
/// parses from the submitted block, but it will __not__ accrue those fees on to the total in the
/// dictionary. This is to avoid accounting for fees twice.
/// - This version of the ETH block reprocessor __will__ deduct fees from any transaction info(s) it parses from the
/// submitted block, but it will __not__ accrue those fees on to the total in the dictionary. This is to avoid
/// accounting for fees twice.
///
/// ### BEWARE:
/// If you don't broadcast the transaction outputted from this function, ALL future ETH transactions will
Expand All @@ -185,9 +185,9 @@ pub fn debug_reprocess_eth_block<D: DatabaseInterface>(db: &D, block_json: &str,
///
/// - This function will NOT increment the core's ETH nonce if one is passed in!
///
/// - This version of the ETH block reprocessor __will__ deduct fees from any transaction info(s) it
/// parses from the submitted block, but it will __not__ accrue those fees on to the total in the
/// dictionary. This is to avoid accounting for fees twice.
/// - This version of the ETH block reprocessor __will__ deduct fees from any transaction info(s) it parses from the
/// submitted block, but it will __not__ accrue those fees on to the total in the dictionary. This is to avoid
/// accounting for fees twice.
///
/// ### BEWARE:
///
Expand All @@ -209,14 +209,13 @@ pub fn debug_reprocess_eth_block_with_nonce<D: DatabaseInterface>(
///
/// ### NOTES:
///
/// - This function will increment the core's ETH nonce, meaning the outputted reports will have a
/// gap in their report IDs!
/// - This function will increment the core's ETH nonce, meaning the outputted reports will have a gap in their report
/// IDs!
///
/// - This version of the ETH block reprocessor __will__ deduct fees from any transaction info(s) it
/// parses from the submitted block, and __will__ accrue those fees on to the total in the
/// dictionary. Only use this is you know what you're doing and why, and make sure you're avoiding
/// accruing the fees twice if the block has already been processed through the non-debug ETH
/// block submission pipeline.
/// - This version of the ETH block reprocessor __will__ deduct fees from any transaction info(s) it parses from the
/// submitted block, and __will__ accrue those fees on to the total in the dictionary. Only use this is you know what
/// you're doing and why, and make sure you're avoiding accruing the fees twice if the block has already been
/// processed through the non-debug ETH block submission pipeline.
///
/// ### BEWARE:
/// If you don't broadcast the transaction outputted from this function, ALL future ETH transactions will
Expand Down
Loading

0 comments on commit 4be2637

Please sign in to comment.