Skip to content

Commit 1e692e1

Browse files
authored
Deny clippy warnings in CI properly (#2109)
* refactor(governance): fix clippy warnings * refactor(target_chains/cosmwasm): fix clippy warnings * refactor(apps/hermes): fix clippy warnings * refactor(apps/fortuna): fix clippy warnings * refactor(pythnet): fix clippy warnings * refactor(target_chains/solana): fix clippy warnings
1 parent d3d0f9f commit 1e692e1

File tree

21 files changed

+59
-43
lines changed

21 files changed

+59
-43
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
- id: cargo-clippy-remote-executor
4646
name: Cargo clippy for remote executor
4747
language: "rust"
48-
entry: cargo +1.66.1 clippy --manifest-path ./governance/remote_executor/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
48+
entry: cargo +1.66.1 clippy --manifest-path ./governance/remote_executor/Cargo.toml --tests -- --deny warnings
4949
pass_filenames: false
5050
files: governance/remote_executor
5151
# Hooks for cosmwasm contract
@@ -58,7 +58,7 @@ repos:
5858
- id: cargo-clippy-cosmwasm
5959
name: Cargo clippy for cosmwasm contract
6060
language: "rust"
61-
entry: cargo +1.82.0 clippy --manifest-path ./target_chains/cosmwasm/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
61+
entry: cargo +1.82.0 clippy --manifest-path ./target_chains/cosmwasm/Cargo.toml --tests -- --deny warnings
6262
pass_filenames: false
6363
files: target_chains/cosmwasm
6464
# Hooks for Hermes
@@ -71,7 +71,7 @@ repos:
7171
- id: cargo-clippy-hermes
7272
name: Cargo clippy for Hermes
7373
language: "rust"
74-
entry: cargo +1.82.0 clippy --manifest-path ./apps/hermes/server/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
74+
entry: cargo +1.82.0 clippy --manifest-path ./apps/hermes/server/Cargo.toml --tests -- --deny warnings
7575
pass_filenames: false
7676
files: apps/hermes
7777
# Hooks for Fortuna
@@ -84,7 +84,7 @@ repos:
8484
- id: cargo-clippy-fortuna
8585
name: Cargo clippy for Fortuna
8686
language: "rust"
87-
entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
87+
entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests -- --deny warnings
8888
pass_filenames: false
8989
files: apps/fortuna
9090
# Hooks for message buffer contract
@@ -97,7 +97,7 @@ repos:
9797
- id: cargo-clippy-message-buffer
9898
name: Cargo clippy for message buffer contract
9999
language: "rust"
100-
entry: cargo +1.66.1 clippy --manifest-path ./pythnet/message_buffer/Cargo.toml --tests --fix --allow-dirty --allow-staged --features test-bpf -- -D warnings
100+
entry: cargo +1.66.1 clippy --manifest-path ./pythnet/message_buffer/Cargo.toml --tests -- --deny warnings
101101
pass_filenames: false
102102
files: pythnet/message_buffer
103103
# Hooks for pythnet_sdk
@@ -110,7 +110,7 @@ repos:
110110
- id: cargo-clippy-pythnet-sdk
111111
name: Cargo clippy for pythnet SDK
112112
language: "rust"
113-
entry: cargo +1.82.0 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
113+
entry: cargo +1.82.0 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests -- --deny warnings
114114
pass_filenames: false
115115
files: pythnet/pythnet_sdk
116116
# Hooks for solana receiver contract
@@ -123,7 +123,7 @@ repos:
123123
- id: cargo-clippy-pyth-solana-receiver
124124
name: Cargo clippy for solana target chain contract
125125
language: "rust"
126-
entry: cargo +1.73.0 clippy --manifest-path ./target_chains/solana/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
126+
entry: cargo +1.73.0 clippy --manifest-path ./target_chains/solana/Cargo.toml --tests -- --deny warnings
127127
pass_filenames: false
128128
files: target_chains/solana
129129
# For express relay python files

apps/fortuna/src/api/revelation.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ pub async fn revelation(
4040
})
4141
.inc();
4242

43-
let sequence: u64 = sequence
44-
.try_into()
45-
.map_err(|_| RestError::InvalidSequenceNumber)?;
46-
4743
let state = state
4844
.chains
4945
.get(&chain_id)

apps/fortuna/src/chain/ethereum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<T: JsonRpcClient + 'static> EntropyReader for PythRandom<Provider<T>> {
295295
Ok(Some(reader::Request {
296296
provider: r.provider,
297297
sequence_number: r.sequence_number,
298-
block_number: r.block_number.try_into()?,
298+
block_number: r.block_number,
299299
use_blockhash: r.use_blockhash,
300300
}))
301301
} else {

apps/fortuna/src/chain/reader.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub mod mock {
157157

158158
async fn get_block_number(
159159
&self,
160-
confirmed_block_status: BlockStatus,
160+
_confirmed_block_status: BlockStatus,
161161
) -> Result<BlockNumber> {
162162
Ok(*self.block_number.read().unwrap())
163163
}
@@ -172,11 +172,11 @@ pub mod mock {
172172

173173
async fn estimate_reveal_with_callback_gas(
174174
&self,
175-
sender: Address,
176-
provider: Address,
177-
sequence_number: u64,
178-
user_random_number: [u8; 32],
179-
provider_revelation: [u8; 32],
175+
_sender: Address,
176+
_provider: Address,
177+
_sequence_number: u64,
178+
_user_random_number: [u8; 32],
179+
_provider_revelation: [u8; 32],
180180
) -> Result<U256> {
181181
Ok(U256::from(5))
182182
}

apps/fortuna/src/command/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
207207

208208
async fn setup_chain_state(
209209
provider: &Address,
210-
secret: &String,
210+
secret: &str,
211211
chain_sample_interval: u64,
212212
chain_id: &ChainId,
213213
chain_config: &EthereumConfig,

apps/fortuna/src/keeper.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,10 @@ pub async fn process_event_with_backoff(
351351
})
352352
.inc();
353353
tracing::info!("Started processing event");
354-
let mut backoff = ExponentialBackoff::default();
355-
backoff.max_elapsed_time = Some(Duration::from_secs(300)); // retry for 5 minutes
354+
let backoff = ExponentialBackoff {
355+
max_elapsed_time: Some(Duration::from_secs(300)), // retry for 5 minutes
356+
..Default::default()
357+
};
356358
match backoff::future::retry_notify(
357359
backoff,
358360
|| async {
@@ -704,7 +706,7 @@ pub async fn watch_blocks(
704706
loop {
705707
match stream_option {
706708
Some(ref mut stream) => {
707-
if let None = stream.next().await {
709+
if stream.next().await.is_none() {
708710
tracing::error!("Error blocks subscription stream ended");
709711
return Err(anyhow!("Error blocks subscription stream ended"));
710712
}
@@ -984,6 +986,7 @@ pub async fn send_and_confirm(contract_call: PythContractCall) -> Result<()> {
984986
}
985987

986988
#[tracing::instrument(name = "adjust_fee", skip_all)]
989+
#[allow(clippy::too_many_arguments)]
987990
pub async fn adjust_fee_wrapper(
988991
contract: Arc<InstrumentedSignablePythContract>,
989992
provider_address: Address,
@@ -1082,6 +1085,7 @@ pub async fn update_commitments_if_necessary(
10821085
///
10831086
/// These conditions are intended to make sure that the keeper is profitable while also minimizing the number of fee
10841087
/// update transactions.
1088+
#[allow(clippy::too_many_arguments)]
10851089
pub async fn adjust_fee_if_necessary(
10861090
contract: Arc<InstrumentedSignablePythContract>,
10871091
provider_address: Address,

apps/fortuna/src/state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl PebbleHashChain {
8383
Ok(val)
8484
}
8585

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

142143
let mut last_val = chain.reveal_ith(0).unwrap();
144+
145+
#[allow(clippy::needless_range_loop)]
143146
for i in 1..length {
144147
let cur_val = chain.reveal_ith(i).unwrap();
145148
println!("{}", i);

apps/hermes/server/src/network/wormhole.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub struct GuardianSetData {
7575
///
7676
/// The following module structure must match the protobuf definitions, so that the generated code
7777
/// can correctly reference modules from each other.
78+
#[allow(clippy::enum_variant_names)]
7879
mod proto {
7980
pub mod node {
8081
pub mod v1 {

governance/remote_executor/programs/remote-executor/src/tests/executor_simulator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl ExecutorBench {
123123
pub fn add_vaa_account(
124124
&mut self,
125125
emitter: &Pubkey,
126-
instructions: &Vec<Instruction>,
126+
instructions: &[Instruction],
127127
validity: VaaAttack,
128128
) -> Pubkey {
129129
let emitter_chain: u16 = match validity {

governance/remote_executor/programs/remote-executor/src/tests/test_adversarial.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn test_adversarial() {
2828
// Setup VAAs
2929
let vaa_account_valid = bench.add_vaa_account(
3030
&emitter,
31-
&vec![transfer(
31+
&[transfer(
3232
&executor_key,
3333
&receiver,
3434
Rent::default().minimum_balance(0),
@@ -37,7 +37,7 @@ async fn test_adversarial() {
3737
);
3838
let vaa_account_wrong_data = bench.add_vaa_account(
3939
&emitter,
40-
&vec![transfer(
40+
&[transfer(
4141
&executor_key,
4242
&receiver,
4343
Rent::default().minimum_balance(0),
@@ -46,7 +46,7 @@ async fn test_adversarial() {
4646
);
4747
let vaa_account_wrong_owner = bench.add_vaa_account(
4848
&emitter,
49-
&vec![transfer(
49+
&[transfer(
5050
&executor_key,
5151
&receiver,
5252
Rent::default().minimum_balance(0),
@@ -55,7 +55,7 @@ async fn test_adversarial() {
5555
);
5656
let vaa_account_wrong_emitter_chain = bench.add_vaa_account(
5757
&emitter,
58-
&vec![transfer(
58+
&[transfer(
5959
&executor_key,
6060
&receiver,
6161
Rent::default().minimum_balance(0),
@@ -65,7 +65,7 @@ async fn test_adversarial() {
6565

6666
let vaa_account_wrong_vaa_magic = bench.add_vaa_account(
6767
&emitter,
68-
&vec![transfer(
68+
&[transfer(
6969
&executor_key,
7070
&receiver,
7171
Rent::default().minimum_balance(0),
@@ -75,7 +75,7 @@ async fn test_adversarial() {
7575

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

8080
let mut sim = bench.start().await;
8181
sim.airdrop(&executor_key, LAMPORTS_PER_SOL).await.unwrap();

governance/remote_executor/programs/remote-executor/src/tests/test_basic_instructions.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ async fn test_basic_instructions() {
5757
);
5858

5959
let vaa_account_create =
60-
bench.add_vaa_account(&emitter, &vec![instruction1, instruction2], VaaAttack::None);
61-
let vaa_account_transfer1 =
62-
bench.add_vaa_account(&emitter, &vec![instruction3], VaaAttack::None);
63-
let vaa_account_transfer2 =
64-
bench.add_vaa_account(&emitter, &vec![instruction4], VaaAttack::None);
60+
bench.add_vaa_account(&emitter, &[instruction1, instruction2], VaaAttack::None);
61+
let vaa_account_transfer1 = bench.add_vaa_account(&emitter, &[instruction3], VaaAttack::None);
62+
let vaa_account_transfer2 = bench.add_vaa_account(&emitter, &[instruction4], VaaAttack::None);
6563

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

pythnet/message_buffer/programs/message_buffer/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// We can't do much about the size of `anchor_lang::error::Error`.
2+
#![allow(clippy::result_large_err)]
3+
14
pub mod instructions;
25
mod state;
36

pythnet/message_buffer/programs/mock-cpi-caller/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// We can't do much about the size of `anchor_lang::error::Error`.
2+
#![allow(clippy::result_large_err)]
3+
14
use {anchor_lang::prelude::*, instructions::*};
25

36
pub mod instructions;

pythnet/message_buffer/programs/mock-cpi-caller/src/state/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,3 @@ pub enum PythAccountType {
1818
Test = 4,
1919
Permissions = 5,
2020
}
21-
impl PythAccountType {
22-
pub(crate) fn to_u32(&self) -> u32 {
23-
*self as u32
24-
}
25-
}

target_chains/cosmwasm/contracts/pyth/src/contract.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ mod test {
10971097
assert_eq!(ema_price.expo, feed_msg.exponent);
10981098
assert_eq!(ema_price.publish_time, feed_msg.publish_time);
10991099
}
1100-
_ => assert!(false, "invalid message type"),
1100+
_ => panic!("invalid message type"),
11011101
};
11021102
}
11031103

@@ -1228,8 +1228,8 @@ mod test {
12281228
let info = mock_info("123", &[]);
12291229
let result = update_price_feeds(deps.as_mut(), env, info, &[msg.into()]);
12301230
assert!(result.is_ok());
1231-
for i in 100..110 {
1232-
check_price_match(&deps, all_feeds[i]);
1231+
for msg in &all_feeds[100..110] {
1232+
check_price_match(&deps, msg);
12331233
}
12341234
}
12351235

target_chains/cosmwasm/sdk/rust/src/testing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use {
44
from_binary, to_binary, Binary, Coin, ContractResult, QuerierResult, SystemError,
55
SystemResult,
66
},
7-
std::{collections::HashMap, time::Duration, u128},
7+
std::{collections::HashMap, time::Duration},
88
};
99

1010
/// Mock version of Pyth for testing cosmwasm contracts.

target_chains/solana/programs/pyth-push-oracle/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// We can't do much about the size of `anchor_lang::error::Error`.
2+
#![allow(clippy::result_large_err)]
3+
14
use {
25
anchor_lang::prelude::*,
36
pyth_solana_receiver_sdk::{

target_chains/solana/programs/pyth-solana-receiver/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// We can't do much about the size of `anchor_lang::error::Error`.
2+
#![allow(clippy::result_large_err)]
3+
14
pub use pythnet_sdk::wire::v1::MerklePriceUpdate;
25
use {
36
crate::error::ReceiverError,
@@ -354,6 +357,7 @@ struct VaaComponents {
354357
emitter_chain: u16,
355358
}
356359

360+
#[allow(clippy::too_many_arguments)]
357361
fn post_price_update_from_vaa<'info>(
358362
config: &Account<'info, Config>,
359363
payer: &Signer<'info>,

target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl instruction::PostUpdate {
146146
}
147147

148148
impl instruction::PostUpdateAtomic {
149+
#[allow(clippy::too_many_arguments)]
149150
pub fn populate(
150151
payer: Pubkey,
151152
write_authority: Pubkey,

target_chains/solana/pyth_solana_receiver_sdk/src/cpi/accounts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::vec_init_then_push)]
2+
13
// This file was populated with the expanded macros of programs/pyth-solana-receiver/src/lib.rs
24

35
pub struct PostUpdateAtomic<'info> {

target_chains/solana/pyth_solana_receiver_sdk/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// We can't do much about the size of `anchor_lang::error::Error`.
2+
#![allow(clippy::result_large_err)]
3+
14
use {
25
anchor_lang::{declare_id, prelude::*},
36
borsh::{BorshDeserialize, BorshSerialize},

0 commit comments

Comments
 (0)