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

Deny clippy warnings in CI properly #2109

Merged
merged 6 commits into from
Nov 12, 2024
Merged
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
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repos:
- id: cargo-clippy-remote-executor
name: Cargo clippy for remote executor
language: "rust"
entry: cargo +1.66.1 clippy --manifest-path ./governance/remote_executor/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
entry: cargo +1.66.1 clippy --manifest-path ./governance/remote_executor/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: governance/remote_executor
# Hooks for cosmwasm contract
Expand All @@ -58,7 +58,7 @@ repos:
- id: cargo-clippy-cosmwasm
name: Cargo clippy for cosmwasm contract
language: "rust"
entry: cargo +1.82.0 clippy --manifest-path ./target_chains/cosmwasm/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
entry: cargo +1.82.0 clippy --manifest-path ./target_chains/cosmwasm/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: target_chains/cosmwasm
# Hooks for Hermes
Expand All @@ -71,7 +71,7 @@ repos:
- id: cargo-clippy-hermes
name: Cargo clippy for Hermes
language: "rust"
entry: cargo +1.82.0 clippy --manifest-path ./apps/hermes/server/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
entry: cargo +1.82.0 clippy --manifest-path ./apps/hermes/server/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: apps/hermes
# Hooks for Fortuna
Expand All @@ -84,7 +84,7 @@ repos:
- id: cargo-clippy-fortuna
name: Cargo clippy for Fortuna
language: "rust"
entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: apps/fortuna
# Hooks for message buffer contract
Expand All @@ -97,7 +97,7 @@ repos:
- id: cargo-clippy-message-buffer
name: Cargo clippy for message buffer contract
language: "rust"
entry: cargo +1.66.1 clippy --manifest-path ./pythnet/message_buffer/Cargo.toml --tests --fix --allow-dirty --allow-staged --features test-bpf -- -D warnings
entry: cargo +1.66.1 clippy --manifest-path ./pythnet/message_buffer/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: pythnet/message_buffer
# Hooks for pythnet_sdk
Expand All @@ -110,7 +110,7 @@ repos:
- id: cargo-clippy-pythnet-sdk
name: Cargo clippy for pythnet SDK
language: "rust"
entry: cargo +1.82.0 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
entry: cargo +1.82.0 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: pythnet/pythnet_sdk
# Hooks for solana receiver contract
Expand All @@ -123,7 +123,7 @@ repos:
- id: cargo-clippy-pyth-solana-receiver
name: Cargo clippy for solana target chain contract
language: "rust"
entry: cargo +1.73.0 clippy --manifest-path ./target_chains/solana/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
entry: cargo +1.73.0 clippy --manifest-path ./target_chains/solana/Cargo.toml --tests -- --deny warnings
pass_filenames: false
files: target_chains/solana
# For express relay python files
Expand Down
4 changes: 0 additions & 4 deletions apps/fortuna/src/api/revelation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ pub async fn revelation(
})
.inc();

let sequence: u64 = sequence
.try_into()
.map_err(|_| RestError::InvalidSequenceNumber)?;
Comment on lines -43 to -45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the intention here was not to check if try_into() has some errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequence is already a u64 so try_into() never fails.


let state = state
.chains
.get(&chain_id)
Expand Down
2 changes: 1 addition & 1 deletion apps/fortuna/src/chain/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<T: JsonRpcClient + 'static> EntropyReader for PythRandom<Provider<T>> {
Ok(Some(reader::Request {
provider: r.provider,
sequence_number: r.sequence_number,
block_number: r.block_number.try_into()?,
block_number: r.block_number,
use_blockhash: r.use_blockhash,
}))
} else {
Expand Down
12 changes: 6 additions & 6 deletions apps/fortuna/src/chain/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub mod mock {

async fn get_block_number(
&self,
confirmed_block_status: BlockStatus,
_confirmed_block_status: BlockStatus,
) -> Result<BlockNumber> {
Ok(*self.block_number.read().unwrap())
}
Expand All @@ -172,11 +172,11 @@ pub mod mock {

async fn estimate_reveal_with_callback_gas(
&self,
sender: Address,
provider: Address,
sequence_number: u64,
user_random_number: [u8; 32],
provider_revelation: [u8; 32],
_sender: Address,
_provider: Address,
_sequence_number: u64,
_user_random_number: [u8; 32],
_provider_revelation: [u8; 32],
) -> Result<U256> {
Ok(U256::from(5))
}
Expand Down
2 changes: 1 addition & 1 deletion apps/fortuna/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {

async fn setup_chain_state(
provider: &Address,
secret: &String,
secret: &str,
chain_sample_interval: u64,
chain_id: &ChainId,
chain_config: &EthereumConfig,
Expand Down
10 changes: 7 additions & 3 deletions apps/fortuna/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,10 @@ pub async fn process_event_with_backoff(
})
.inc();
tracing::info!("Started processing event");
let mut backoff = ExponentialBackoff::default();
backoff.max_elapsed_time = Some(Duration::from_secs(300)); // retry for 5 minutes
let backoff = ExponentialBackoff {
max_elapsed_time: Some(Duration::from_secs(300)), // retry for 5 minutes
..Default::default()
};
match backoff::future::retry_notify(
backoff,
|| async {
Expand Down Expand Up @@ -704,7 +706,7 @@ pub async fn watch_blocks(
loop {
match stream_option {
Some(ref mut stream) => {
if let None = stream.next().await {
if stream.next().await.is_none() {
tracing::error!("Error blocks subscription stream ended");
return Err(anyhow!("Error blocks subscription stream ended"));
}
Expand Down Expand Up @@ -984,6 +986,7 @@ pub async fn send_and_confirm(contract_call: PythContractCall) -> Result<()> {
}

#[tracing::instrument(name = "adjust_fee", skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn adjust_fee_wrapper(
contract: Arc<InstrumentedSignablePythContract>,
provider_address: Address,
Expand Down Expand Up @@ -1082,6 +1085,7 @@ pub async fn update_commitments_if_necessary(
///
/// These conditions are intended to make sure that the keeper is profitable while also minimizing the number of fee
/// update transactions.
#[allow(clippy::too_many_arguments)]
pub async fn adjust_fee_if_necessary(
contract: Arc<InstrumentedSignablePythContract>,
provider_address: Address,
Expand Down
3 changes: 3 additions & 0 deletions apps/fortuna/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl PebbleHashChain {
Ok(val)
}

#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.length
}
Expand Down Expand Up @@ -140,6 +141,8 @@ mod test {
let chain = PebbleHashChain::new(secret, length, sample_interval);

let mut last_val = chain.reveal_ith(0).unwrap();

#[allow(clippy::needless_range_loop)]
for i in 1..length {
let cur_val = chain.reveal_ith(i).unwrap();
println!("{}", i);
Expand Down
1 change: 1 addition & 0 deletions apps/hermes/server/src/network/wormhole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct GuardianSetData {
///
/// The following module structure must match the protobuf definitions, so that the generated code
/// can correctly reference modules from each other.
#[allow(clippy::enum_variant_names)]
mod proto {
pub mod node {
pub mod v1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl ExecutorBench {
pub fn add_vaa_account(
&mut self,
emitter: &Pubkey,
instructions: &Vec<Instruction>,
instructions: &[Instruction],
validity: VaaAttack,
) -> Pubkey {
let emitter_chain: u16 = match validity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn test_adversarial() {
// Setup VAAs
let vaa_account_valid = bench.add_vaa_account(
&emitter,
&vec![transfer(
&[transfer(
&executor_key,
&receiver,
Rent::default().minimum_balance(0),
Expand All @@ -37,7 +37,7 @@ async fn test_adversarial() {
);
let vaa_account_wrong_data = bench.add_vaa_account(
&emitter,
&vec![transfer(
&[transfer(
&executor_key,
&receiver,
Rent::default().minimum_balance(0),
Expand All @@ -46,7 +46,7 @@ async fn test_adversarial() {
);
let vaa_account_wrong_owner = bench.add_vaa_account(
&emitter,
&vec![transfer(
&[transfer(
&executor_key,
&receiver,
Rent::default().minimum_balance(0),
Expand All @@ -55,7 +55,7 @@ async fn test_adversarial() {
);
let vaa_account_wrong_emitter_chain = bench.add_vaa_account(
&emitter,
&vec![transfer(
&[transfer(
&executor_key,
&receiver,
Rent::default().minimum_balance(0),
Expand All @@ -65,7 +65,7 @@ async fn test_adversarial() {

let vaa_account_wrong_vaa_magic = bench.add_vaa_account(
&emitter,
&vec![transfer(
&[transfer(
&executor_key,
&receiver,
Rent::default().minimum_balance(0),
Expand All @@ -75,7 +75,7 @@ async fn test_adversarial() {

// The goal of this account is creating a claim_record that the attacker is going to try to use to impersonate
// the right claim_record
let vaa_account_valid_2 = bench.add_vaa_account(&emitter_2, &vec![], VaaAttack::None);
let vaa_account_valid_2 = bench.add_vaa_account(&emitter_2, &[], VaaAttack::None);

let mut sim = bench.start().await;
sim.airdrop(&executor_key, LAMPORTS_PER_SOL).await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ async fn test_basic_instructions() {
);

let vaa_account_create =
bench.add_vaa_account(&emitter, &vec![instruction1, instruction2], VaaAttack::None);
let vaa_account_transfer1 =
bench.add_vaa_account(&emitter, &vec![instruction3], VaaAttack::None);
let vaa_account_transfer2 =
bench.add_vaa_account(&emitter, &vec![instruction4], VaaAttack::None);
bench.add_vaa_account(&emitter, &[instruction1, instruction2], VaaAttack::None);
let vaa_account_transfer1 = bench.add_vaa_account(&emitter, &[instruction3], VaaAttack::None);
let vaa_account_transfer2 = bench.add_vaa_account(&emitter, &[instruction4], VaaAttack::None);

let mut sim = bench.start().await;

Expand Down
3 changes: 3 additions & 0 deletions pythnet/message_buffer/programs/message_buffer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// We can't do much about the size of `anchor_lang::error::Error`.
#![allow(clippy::result_large_err)]

pub mod instructions;
mod state;

Expand Down
3 changes: 3 additions & 0 deletions pythnet/message_buffer/programs/mock-cpi-caller/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// We can't do much about the size of `anchor_lang::error::Error`.
#![allow(clippy::result_large_err)]

use {anchor_lang::prelude::*, instructions::*};

pub mod instructions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ pub enum PythAccountType {
Test = 4,
Permissions = 5,
}
impl PythAccountType {
pub(crate) fn to_u32(&self) -> u32 {
*self as u32
}
}
6 changes: 3 additions & 3 deletions target_chains/cosmwasm/contracts/pyth/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ mod test {
assert_eq!(ema_price.expo, feed_msg.exponent);
assert_eq!(ema_price.publish_time, feed_msg.publish_time);
}
_ => assert!(false, "invalid message type"),
_ => panic!("invalid message type"),
};
}

Expand Down Expand Up @@ -1228,8 +1228,8 @@ mod test {
let info = mock_info("123", &[]);
let result = update_price_feeds(deps.as_mut(), env, info, &[msg.into()]);
assert!(result.is_ok());
for i in 100..110 {
check_price_match(&deps, all_feeds[i]);
for msg in &all_feeds[100..110] {
check_price_match(&deps, msg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion target_chains/cosmwasm/sdk/rust/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
from_binary, to_binary, Binary, Coin, ContractResult, QuerierResult, SystemError,
SystemResult,
},
std::{collections::HashMap, time::Duration, u128},
std::{collections::HashMap, time::Duration},
};

/// Mock version of Pyth for testing cosmwasm contracts.
Expand Down
3 changes: 3 additions & 0 deletions target_chains/solana/programs/pyth-push-oracle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// We can't do much about the size of `anchor_lang::error::Error`.
#![allow(clippy::result_large_err)]

use {
anchor_lang::prelude::*,
pyth_solana_receiver_sdk::{
Expand Down
4 changes: 4 additions & 0 deletions target_chains/solana/programs/pyth-solana-receiver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// We can't do much about the size of `anchor_lang::error::Error`.
#![allow(clippy::result_large_err)]

pub use pythnet_sdk::wire::v1::MerklePriceUpdate;
use {
crate::error::ReceiverError,
Expand Down Expand Up @@ -354,6 +357,7 @@ struct VaaComponents {
emitter_chain: u16,
}

#[allow(clippy::too_many_arguments)]
fn post_price_update_from_vaa<'info>(
config: &Account<'info, Config>,
payer: &Signer<'info>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl instruction::PostUpdate {
}

impl instruction::PostUpdateAtomic {
#[allow(clippy::too_many_arguments)]
pub fn populate(
payer: Pubkey,
write_authority: Pubkey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::vec_init_then_push)]
Copy link
Collaborator

@ali-bahjati ali-bahjati Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't we move this in? (i mean just fix it perhaps)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module contains auto generated code so I feel like it's more convenient to keep this outside so it's easier to update the code if needed.


// This file was populated with the expanded macros of programs/pyth-solana-receiver/src/lib.rs

pub struct PostUpdateAtomic<'info> {
Expand Down
3 changes: 3 additions & 0 deletions target_chains/solana/pyth_solana_receiver_sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// We can't do much about the size of `anchor_lang::error::Error`.
#![allow(clippy::result_large_err)]

use {
anchor_lang::{declare_id, prelude::*},
borsh::{BorshDeserialize, BorshSerialize},
Expand Down
Loading